The Red programming language is moving slowly to version 1.0 and today is at 0.5.4
I thought that it might be useful to look at a do block with the prin function when entered at the Red console.
My example is as follows:
do [
t1: "test1"
prin t1
t1: "test2"
prin t1
]
The console output will be
test1test2
and NOT
test2test2
Why?
I think that this is only really clear if you see the example code as
do [
t1: "test1"
prin :t1
t1: "test2"
prin :t1
]
The difference above is that each prin function explicitly is being passed the value of t1.
This is what happens in the short-hand or syntactic sugar version of the example as I first presented it.
If a new user of Red imagined that prin was being passed the ADDRESS of t1 or the ADDRESS of its value, one might expect the meta-level do block to output
test2test2.
This is obvious to old-hands from Rebol, but it may not be obvious to users who are new to expression-based languages.
I thought that it might be useful to look at a do block with the prin function when entered at the Red console.
My example is as follows:
do [
t1: "test1"
prin t1
t1: "test2"
prin t1
]
The console output will be
test1test2
and NOT
test2test2
Why?
I think that this is only really clear if you see the example code as
do [
t1: "test1"
prin :t1
t1: "test2"
prin :t1
]
The difference above is that each prin function explicitly is being passed the value of t1.
This is what happens in the short-hand or syntactic sugar version of the example as I first presented it.
If a new user of Red imagined that prin was being passed the ADDRESS of t1 or the ADDRESS of its value, one might expect the meta-level do block to output
test2test2.
This is obvious to old-hands from Rebol, but it may not be obvious to users who are new to expression-based languages.
No comments:
Post a Comment