Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

USE and SET

 [1/4] from: henrik::webz::dk at: 27-Jul-2006 5:37


Why does this work like so: >> d: [a b c] ; dynamic block of words == [a b c] >> a ** Script Error: a has no value ** Near: a OK, so far. >> use d [set d [1 2 3]] == [1 2 3] >> a == 1 ; a is global Not good. I want a, b and c to be local to that USE block. Unsetting a, b and c again: >> unset d >> a ** Script Error: a has no value ** Near: a Using copy/deep is no good: >> use d [set copy/deep d [1 2 3]] == [1 2 3] >> a == 1 >> unset d Still no good: >> use copy/deep d [set copy/deep d [1 2 3]] == [1 2 3] >> a == 1 However if I refer to the block directly: >> use d [set [a b c] [1 2 3]] >> a ** Script Error: a has no value ** Near: a It works as intended, but I want the block of words being set to be dynamic. How? -- Regards, Henrik Mikael Kristensen

 [2/4] from: cyphre:seznam:cz at: 27-Jul-2006 12:16


Hi Henrik, Your attempts failed becuse you are setting words which are bound to global context. AFAIK USE is making a copy of the WORDS argument so the D block is still bound to global. Here is a solution:
>> d: [a b c]
== [a b c]
>> use d [set dd: bind copy d 'a [1 2 3] print [a b c]]
1 2 3
>> reduce d
** Script Error: a has no value ** Near: a b c
>> reduce dd
== [1 2 3]
>> a
** Script Error: a has no value ** Near: a
>> b
** Script Error: b has no value ** Near: b
>> c
** Script Error: c has no value ** Near: c
>>
The only problem is you have to specify some word of the hidden context of USE. So if you want really 'dynamic' example.
>> d: [a b c]
== [a b c]
>> use join d 'self [set dd: bind copy d 'self [1 2 3] print [a b c]]
1 2 3
>> a
** Script Error: a has no value ** Near: a
>> b
** Script Error: b has no value ** Near: b
>> c
** Script Error: c has no value ** Near: c
>> reduce d
** Script Error: a has no value ** Near: a b c
>> reduce dd
== [1 2 3]
>>
As you can see I added the SELF word so I'm sure this word is always present in the context of USE regardles the DYNAMIC block content. But you can choose any other word as well. regards, Cyphre

 [3/4] from: gabriele::colellachiara::com at: 27-Jul-2006 12:35


Hi Cyphre, On Thursday, July 27, 2006, 12:16:18 PM, you wrote:
>>> use join d 'self [set dd: bind copy d 'self [1 2 3] print [a b c]]
Or: use d compose/only [set (d) [1 2 3] ...] (you may want to copy it as well, etc.) Regards, Gabriele. -- Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/ Colella Chiara software division --- http://www.colellachiara.com/

 [4/4] from: lmecir::mbox::vol::cz at: 28-Jul-2006 7:28


an alternative I would like to mention: do you know this one? d: [a b c] d: use d reduce [d] set d [1 2 3] -L