Created
August 4, 2018 18:28
-
-
Save x8x/e0af4637838f020e0673f854a9f6e261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. |
For reference, this doesn't work in Rebol:
f: func [/local a][a: context [b: context [c: 'ok]] print do bind reduce [load {a/b/c}] :f] f
** Script Error: bind expected known-word argument of type: any-word object port
** Where: f
** Near: print do bind reduce [load "a/b/c"]
@x8x I can't answer all the questions, as I don't know the implementation internals of Red, but I think you are correct on first point.
About the third point, I think it is because the a
resulting from loading the string is bound to default global context. I may hypothesize that a
-s in function's body are bound to local context at definition time, but loading happens in runtime, and a
resulting from loading in runtime is not bound to functions context.
BTW, in my first snippet bind
isn't needed actually, because a
is bound in this case:
f: func [/local a][a: context [b: context [c: 'ok]] print do [a/b/c]] f
; or
f: func [/local a][a: context [b: context [c: 'ok]] print reduce 'a/b/c] f
; or
f: func [/local a][a: context [b: context [c: 'ok]] print a/b/c] f
ok
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@toomasv Oh well! That works! Thank you! Guess you win the bounty! Please send me your address on Gitter, so I can transfer the REDs!
..btw, always impressed by your Red productivity!! 👍
Now for some details about how/why that works:
:f
, when defining functionf
, the body block is just that, ablock!
not executed yet, hence no complain about:f
not being defined yet. While when callingf
,:f
gets its value from the global space, where functionf
is defined. Correct?bind [] 'a
? Binding to aword!
should execute theblock!
in the context where thatword!
is defined, which in this case would be thef
function body.do load
, inside the function body, execute in the global space and I need to bind it in the first place?Still curious about Rebol/Red different behaviours, is that wanted, enhancement, regression?