{"action":"created","issue":{"url":"https://api.github.com/repos/gambit/gambit/issues/242","repository_url":"https://api.github.com/repos/gambit/gambit","labels_url":"https://api.github.com/repos/gambit/gambit/issues/242/labels{/name}","comments_url":"https://api.github.com/repos/gambit/gambit/issues/242/comments","events_url":"https://api.github.com/repos/gambit/gambit/issues/242/events","html_url":"https://github.com/gambit/gambit/issues/242","id":223989456,"number":242,"title":"Universal backend: Implement wills and weak references","user":{"login":"feeley","id":555673,"avatar_url":"https://avatars1.githubusercontent.com/u/555673?v=3","gravatar_id":"","url":"https://api.github.com/users/feeley","html_url":"https://github.com/feeley","followers_url":"https://api.github.com/users/feeley/followers","following_url":"https://api.github.com/users/feeley/following{/other_user}","gists_url":"https://api.github.com/users/feeley/gists{/gist_id}","starred_url":"https://api.github.com/users/feeley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feeley/subscriptions","organizations_url":"https://api.github.com/users/feeley/orgs","repos_url":"https://api.github.com/users/feeley/repos","events_url":"https://api.github.com/users/feeley/events{/privacy}","received_events_url":"https://api.github.com/users/feeley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-04-25T00:48:45Z","updated_at":"2017-06-29T16:51:58Z","closed_at":null,"body":"Estimated time: 40 hours\r\n\r\nThe will objects and hash tables can contain weak references.  Is it possible to implement this in the target languages with the existing garbage collectors?"},"comment":{"url":"https://api.github.com/repos/gambit/gambit/issues/comments/312026736","html_url":"https://github.com/gambit/gambit/issues/242#issuecomment-312026736","issue_url":"https://api.github.com/repos/gambit/gambit/issues/242","id":312026736,"user":{"login":"316k","id":4315554,"avatar_url":"https://avatars2.githubusercontent.com/u/4315554?v=3","gravatar_id":"","url":"https://api.github.com/users/316k","html_url":"https://github.com/316k","followers_url":"https://api.github.com/users/316k/followers","following_url":"https://api.github.com/users/316k/following{/other_user}","gists_url":"https://api.github.com/users/316k/gists{/gist_id}","starred_url":"https://api.github.com/users/316k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/316k/subscriptions","organizations_url":"https://api.github.com/users/316k/orgs","repos_url":"https://api.github.com/users/316k/repos","events_url":"https://api.github.com/users/316k/events{/privacy}","received_events_url":"https://api.github.com/users/316k/received_events","type":"User","site_admin":false},"created_at":"2017-06-29T16:51:58Z","updated_at":"2017-06-29T16:51:58Z","body":"Hmm... I'm not sure this is possible. Unless triggered manually, the will action must be performed *just before the object is garbage collected*, while it's still alive. I think this is roughly equivalent to using the finalize() method in Java, plus using a few `WeakReference` so that the will object won't prevent the object from being collected when it should.\r\n\r\nIt could look something like this :\r\n\r\n```java\r\nimport java.util.Arrays;\r\nimport java.util.HashMap;\r\nimport java.lang.System;\r\n\r\nimport java.util.Stack;\r\nimport java.lang.ref.WeakReference;\r\n\r\nclass RTS {\r\n\r\n  static abstract class ScmObj {\r\n      Stack<WeakReference<Will>> wills = null;\r\n      \r\n      protected void finalize() {\r\n          if(this.wills != null)\r\n              while(!this.wills.isEmpty()) {\r\n                  WeakReference<Will> w = this.wills.pop();\r\n\r\n                  if(w.get() != null) {\r\n                      // **?**\r\n                  }\r\n              }\r\n          }\r\n      }\r\n\r\n\r\n      public void addWill(Will w) {\r\n          if(this.wills == null)\r\n              this.wills = new Stack<WeakReference<Will>>();\r\n\r\n          this.wills.push(new WeakReference<Will>(w));\r\n      }\r\n  }\r\n\r\n  static class Will extends ScmObj {\r\n\r\n    public WeakReference<ScmObj> testator;\r\n    public ScmObj action;\r\n\r\n    Will(ScmObj _testator, ScmObj _action) {\r\n      testator = new WeakReference<ScmObj>(_testator);\r\n      action = _action;\r\n    }\r\n\r\n    public ScmObj getTestator() {\r\n      return this.testator.get();\r\n    }\r\n  }\r\n```\r\n\r\nBut I wouldn't know how to replace the `**?**` with something that would execute the Will action in the scheme runtime."}}
{"actor":{"display_login":"316k"}}