set-word! in block

Started by limux on 2-Dec-2010/9:02:40-8:00
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
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:
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!
select blk3 to-get 'foo == "foo" I wonder why blk3/(to-get-word 'foo) does not work as blk2/(to-set-word 'foo).
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: http://www.rebol.com/r3/alpha-intro.html
R3 is becoming better and better. blk4: [:foo: "foo"] in R2 is ok, and in R3 is bad.
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"
Thanks for your so detailed explaining.//REGARDS.

Reply