metaeducation / ren-c

Library for embedding a Rebol interpreter into C codebases
GNU Lesser General Public License v3.0
126 stars 27 forks source link

Begin phase out of old METHOD, use METH temporarily #1110

Closed hostilefork closed 3 years ago

hostilefork commented 3 years ago

The historical distinction between FUNC and FUNCTION--as well as between METH and METHOD--was that the full word forms would look for SET-WORD!s in the body and implicitly make those locals in the frame (as if they had been defined as locals in the spec).

That mechanic turned out to have a lot of problems. SET-WORD!s can mean many things--especially when dialected. Having all the fields of a MAKE OBJECT! in a function body suddenly be added to the frames would bloat them considerably. It also tied the hands of dialects to have to force the use of SET-WORD!s in places they might not have wanted to...or make them avoid uses in places they would want them.

https://forum.rebol.info/t/rethinking-auto-gathered-set-word-locals/1150/

Virtual binding allows another mechanic, to add bindings into the evaluation as it runs. While not everything is worked out just yet, the best way to get it tested in real scenarios is to start using it. It may perform poorly for a while...if it is a problem, then mitigate it in critical functions by manually declaring your <local>s in the spec.

This takes the first step of eliminating the gathering METHOD. Since it is used less than FUNCTION, it should be less painful to change the callsites to use LET and METH instead.

Note that LET works with words or set-words. The plain word form will evaluate to the word with the new binding

word: let x
x: 10
get word  ; will be 10

The set word form will evaluate to the product

ten: let x: 10
ten + x  ; will be 20

There is also support for LET of BLOCK!s and SET-BLOCK!s, with special consideration for interaction with multiple return values

IF THIS STEP GOES SUCCESSFULLY, A SIMILAR STEP WILL BE TAKEN WITH FUNC AND FUNCTION.

Eventually, the goal is to make FUNC and FUNCTION synonyms, and maybe to make METH and METHOD synonyms too, though perhaps that isn't needed.