Home   Archive   Permalink

set-word! in block

There are two blocks:
blk1: [ foo "foo"]
blk2: [ foo: "foo"]
What is the essential difference between them, How can I access the foo in the second block?
I know foo is a word type in blk1 and foo: in blk2 is a set-word! type.
blk1/foo ==> "foo"
blk2/foo ==> invalid path value

posted by:   limux       2-Dec-2010/9:02:40-8:00

One difference is what happens when you execute the two blocks:
reduce blk1
** Script Error: foo has no value ;; falls over on 'foo
reduce blk2
== ["foo"]
foo    ;; assigns "foo" to 'foo
== "foo"
How to access foo: in the second block? Here's one way....
find blk2 to-set-word 'foo
== [foo: "foo"] ;; positions blk2 at foo:
select blk2 to-set-word 'foo
== "foo"     ;; returns the entry after foo:

posted by:   sunanda       2-Dec-2010/12:01:39-8:00

Thank you very much for your help!
I find that we can use blk2/(to-set-word 'foo to get it's value and use blk2/(to-set-word 'foo): somevalue to set it's.
I do another test of block blk3: [:foo "foo"].
And I find I can not access the :foo by blk3/(to-get-word 'foo), Where is the right way? THKS!

posted by:   limux       2-Dec-2010/20:49:25-8:00

select blk3 to-get 'foo
== "foo"
I wonder why blk3/(to-get-word 'foo) does not work as blk2/(to-set-word 'foo).

posted by:   limux       2-Dec-2010/20:56:46-8:00

It works in REBOL 3, but not in REBOL 2.
Perhaps R3 fixes a bug that has not been fixed in R2; or maybe R3 just has better semantics for this sort of thing.
R3 alpha downloads start here:

posted by:   Sunanda       3-Dec-2010/2:09:15-8:00

R3 is becoming better and better.
blk4: [:foo: "foo"] in R2 is ok, and in R3 is bad.

posted by:   limux       3-Dec-2010/3:27:18-8:00

R3 has tightened up a lot of the rules for what makes a valid word. Also, the load parser behaves differently when it encounters ambiguous syntax. These changes affect what you can do with a ":"
Example: in R2 :aa: is treated as :aa ...
blk: [:aa: "aa"]
== [:aa "aa"]
...while R3 throws a syntax error
As an example of the tightening of the rules for what makes a valid word:
R2: >> type? #xxx:xxx
R2: == issue!
R3: ** Syntax error: invalid "issue" -- "#xxx:xxx"

posted by:   Sunanda       3-Dec-2010/3:59:13-8:00

Thanks for your so detailed explaining.

posted by:   limux       3-Dec-2010/4:47:40-8:00