{"action":"closed","issue":{"url":"https://api.github.com/repos/crack-lang/crack/issues/8","repository_url":"https://api.github.com/repos/crack-lang/crack","labels_url":"https://api.github.com/repos/crack-lang/crack/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/crack-lang/crack/issues/8/comments","events_url":"https://api.github.com/repos/crack-lang/crack/issues/8/events","html_url":"https://github.com/crack-lang/crack/issues/8","id":339803412,"node_id":"MDU6SXNzdWUzMzk4MDM0MTI=","number":8,"title":"add weak references in the syntax to allow mutual references","user":{"login":"senselogic","id":24891838,"node_id":"MDQ6VXNlcjI0ODkxODM4","avatar_url":"https://avatars0.githubusercontent.com/u/24891838?v=4","gravatar_id":"","url":"https://api.github.com/users/senselogic","html_url":"https://github.com/senselogic","followers_url":"https://api.github.com/users/senselogic/followers","following_url":"https://api.github.com/users/senselogic/following{/other_user}","gists_url":"https://api.github.com/users/senselogic/gists{/gist_id}","starred_url":"https://api.github.com/users/senselogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/senselogic/subscriptions","organizations_url":"https://api.github.com/users/senselogic/orgs","repos_url":"https://api.github.com/users/senselogic/repos","events_url":"https://api.github.com/users/senselogic/events{/privacy}","received_events_url":"https://api.github.com/users/senselogic/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-07-10T11:33:51Z","updated_at":"2018-07-26T16:59:47Z","closed_at":"2018-07-26T16:59:47Z","author_association":"NONE","body":"I suggest that you add a way to declare both weak references and pointers, in complement to the default strong references.\r\n\r\nWhen an object looses its last strong reference (= null strong reference count), it is immediately destroyed (= its destructor is called).\r\n\r\nBut the object memory block is released only when it looses its last weak reference (= null weak reference count). \r\n\r\nMeanwhile the weak references will behave as if they were null when using them, as the object they are pointing to has been destroyed.\r\n\r\nThe object memory block is deallocated only when the last weak reference is also lost.\r\n\r\nThere is a sample implementation here :\r\n\r\nhttps://github.com/senselogic/BASE/tree/master/CODE/COUNTED\r\n\r\nWeak references are very useful for instance to easily declare double-linked tree structures, where the parent node holds an array of strong references to the child nodes (for downward traversal), and each child node also keeps a weak reference to its parent (for upward traversal).\r\n\r\nAbout the syntax, I suggest adding a postfix character (!) to the type :\r\n\r\nclass NODE\r\n{\r\n    NODE! ParentNode;    // weak reference to the parent node\r\n    array[NODE] ChildNodeArray;    // array of strong references to the child nodes\r\n    ...\r\n}\r\n\r\nAnd inside the tree traversal code, I suggest we also have to possibility to also use raw pointer types (@) to just hold the address of a node in highly optimized code, at the expense of some safety.\r\n\r\nNODE doSomething()\r\n{\r\n    NODE@ node, childnode;\r\n    for(...) {\r\n        if (...) node = childnode;\r\n        else node = childnode.ParentNode;\r\n    }\r\n    return node;\r\n}\r\n"}}
{"actor":{"display_login":"mindhog"}}