{"action":"created","issue":{"url":"https://api.github.com/repos/red/red/issues/3064","repository_url":"https://api.github.com/repos/red/red","labels_url":"https://api.github.com/repos/red/red/issues/3064/labels{/name}","comments_url":"https://api.github.com/repos/red/red/issues/3064/comments","events_url":"https://api.github.com/repos/red/red/issues/3064/events","html_url":"https://github.com/red/red/pull/3064","id":261879577,"node_id":"MDExOlB1bGxSZXF1ZXN0MTQ0MDQ4ODg5","number":3064,"title":"Implementation of a dynamic prototype-based programming in Red","user":{"login":"ejtizado","id":25245900,"node_id":"MDQ6VXNlcjI1MjQ1OTAw","avatar_url":"https://avatars3.githubusercontent.com/u/25245900?v=4","gravatar_id":"","url":"https://api.github.com/users/ejtizado","html_url":"https://github.com/ejtizado","followers_url":"https://api.github.com/users/ejtizado/followers","following_url":"https://api.github.com/users/ejtizado/following{/other_user}","gists_url":"https://api.github.com/users/ejtizado/gists{/gist_id}","starred_url":"https://api.github.com/users/ejtizado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ejtizado/subscriptions","organizations_url":"https://api.github.com/users/ejtizado/orgs","repos_url":"https://api.github.com/users/ejtizado/repos","events_url":"https://api.github.com/users/ejtizado/events{/privacy}","received_events_url":"https://api.github.com/users/ejtizado/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-30T23:25:14Z","updated_at":"2018-07-20T03:01:51Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/red/red/pulls/3064","html_url":"https://github.com/red/red/pull/3064","diff_url":"https://github.com/red/red/pull/3064.diff","patch_url":"https://github.com/red/red/pull/3064.patch"},"body":"Red implement a prototype-based programming (*value-share*), i.e., the clones will be created from a prototype, but after creation they stand on their own feet (*creation-time sharing*). \r\n\r\nSee the [paper][1] of this link.\r\n\r\n[1]: [http://www.idt.mdh.se/kurser/cd5130/msl/2003lp4/reports/prototypebased.pf]\r\n\r\nThis addon of Red tries to implement a dynamic prototype-based programming (*property-share*), transparent to users and usual rules of Red.\r\n\r\nThis implementation following the concepts of the Self implementation of the object oriented programming language. Then, it uses *objects* and *slots* concept, i.e., it does not distinct variables from methods to be more flexible. Thus it also follow the philosophy of Red.\r\n\r\nHowever, to explain the implementation, the difference between variables (properties) and methods (functions) is necessary.\r\n\r\n## Properties (variables)\r\n\r\n### Delegation (1): to share the value of a property\r\n\r\nThe delegation is clean and follow the rules of Red. The only difference is the slot `_proto` (or any other name decided by the main contributors of Red as `_is`) to clone an object when we declare as prototype-based object from any other `object!` (with or whithout prototype). \r\n\r\n\ta: make object! [x: 1 y: 2 z: 3]\t  ; any object can be a prototype\r\n\t\r\n\t; clone (child) creation\r\n\tb: make object! [_proto: a x: 10]  \r\n\t\r\n\tb/x ; => 10\r\n\tb/y ; => 2\r\n\t\r\n\ta/y: 20\r\n\tb/y ; => 20\r\n\r\nIt is not necessary the slot `_proto` to clone a _siblind_ prototype following the rules of Red, but copy all other variables of the siblind object, if this conduct is not desirable then the user can use the usual creation of a prototype-based object.\r\n\r\n\ta: make object! [x: 1 y: 2 z: 3]\t  ; any object could be a prototype\r\n\tb: make object! [_proto: a x: 10]  \r\n\t\r\n\t; clone (siblind) creation\r\n\tc: make b [z: 30]  \r\n\t\r\n\tc/x ; => 10  ; copy of b\r\n\tc/y ; => 2   ; from a\r\n\tb/x: 20\r\n\tc/x ; => 10\r\n\t\r\n\t; or\r\n\tc: make object! [_proto: a x: 300] ; override x from b\r\n\t\r\n\tc/x ; => 300  ; from c\r\n\tc/y ; => 2    ; from a\r\n\t\r\n#### CPU cost\t\r\n\r\nThe cpu cost of this implementation to other users of `object!` is zero. However, a bad programming conduct could lead to crash the system\r\n\r\n\r\n\tb: make object! [_proto: 5 x: 10]\r\n\t\r\n\tb/x ; => 10\r\n\tb/y\r\n\t*** Runtime Error 1: access violation\r\n\t*** at: 000370EAh\r\n\r\nTo avoid it, is necessary check `_proto` as a valid `object!`. There are two possibilities:\r\n\r\n1. _Zero cost for object users and high cost for prototype users._\r\n\tIt is possible checking the validity of `_proto` in the delegation process, but the pay for the prototype users is in all delegations (variable access) of a prototype-based object.\r\n\t\r\n2. _Cost sharing for all users._\r\n\tThe checking of validity of `_proto` is placed in the creation of `object!`. \r\n\t\r\n\tI implement this option because the cost for all users is low only when `make` the object. After that, no aditional cost for any users at this moment.\r\n\r\n### Delegation (2): new value of a property\r\n\r\nLogically, any object can change the values of their properties but the question is if an object can modify the value of a prototype property or if can add new properties. This feature could be resolve with three mechanisms, from low to high cpu cost:\r\n\r\n1. _Objects can modify the slot values of the prototypes but no add new properties._\r\n\r\n\tIt is the more easy to implement without any aditional cost to the users. However, I think, this is a very risky option.  \r\n\r\n2. _Objects can not add or modify properties of theirs prototypes._\r\n\r\n\tThis could be the default mechanism when the objects are static after creation. An object only can modify their properties. This idea is nowdays in the background of Red because a `extend` function is not posible to add properties to the objects.\t\r\n\r\n3. _Objects can override properties of the prototypes, creating property if it is necessary._\r\n\tAn object can add properties presents in their prototypes but can no add new properties (when `extend` will be implemented in Red, they will can althought the implementation is easy!).\r\n\t\r\nI implement this last option because is safe, flexible and the cpu cost is the same as the previous option.\r\n\r\n\ta: make object! [x: 1 y: 2 z: 3]\r\n\tb: make object! [_proto: a x: 10]  \r\n\t\r\n\tb/y: 20  ; b now is object! [_proto: a x: 10 y: 20]\r\n\r\n\tb/w: 30\r\n\t*** Script Error: cannot access w in path b/w:\r\n\t*** Where: set-path\r\n\t*** Stack:\r\n\t\r\n\r\n### Remove properties\r\n\r\nIn this moment Red does not implement a function to remove slots of an object. Then, it is not implemented but when it will be implemented to `object!`, it could be used in prototype-based programming with any change.\r\n\r\n> The mechanism of *property-share* uses about 20 lines of code and with very low cpu cost to the object users without prototype-based programming.\r\n\r\n## Methods (functions)\r\n\r\n**To be implemented**"},"comment":{"url":"https://api.github.com/repos/red/red/issues/comments/406475163","html_url":"https://github.com/red/red/pull/3064#issuecomment-406475163","issue_url":"https://api.github.com/repos/red/red/issues/3064","id":406475163,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjQ3NTE2Mw==","user":{"login":"greggirwin","id":460079,"node_id":"MDQ6VXNlcjQ2MDA3OQ==","avatar_url":"https://avatars2.githubusercontent.com/u/460079?v=4","gravatar_id":"","url":"https://api.github.com/users/greggirwin","html_url":"https://github.com/greggirwin","followers_url":"https://api.github.com/users/greggirwin/followers","following_url":"https://api.github.com/users/greggirwin/following{/other_user}","gists_url":"https://api.github.com/users/greggirwin/gists{/gist_id}","starred_url":"https://api.github.com/users/greggirwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greggirwin/subscriptions","organizations_url":"https://api.github.com/users/greggirwin/orgs","repos_url":"https://api.github.com/users/greggirwin/repos","events_url":"https://api.github.com/users/greggirwin/events{/privacy}","received_events_url":"https://api.github.com/users/greggirwin/received_events","type":"User","site_admin":false},"created_at":"2018-07-20T03:01:51Z","updated_at":"2018-07-20T03:01:51Z","author_association":"CONTRIBUTOR","body":"@ejtizado, this is really cool work. Unfortunately, it may not be a good fit for Core Red at this time, and now has conflicts which would need resolving. I'd like to close this, but don't want to lose the link to your work, until we have modules and a better way to consider it in the future. "}}
{"actor":{"display_login":"greggirwin"}}