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

[context] How to compose in a local context

 [1/5] from: atruter:labyrinth:au at: 22-Apr-2004 0:07


Given the following:
>> b: 'a
== a
>> do has [a][set 'a 0]
== 0
>> a
** Script Error: a has no value ** Near: a
>> do has [a][do compose/deep [set [(b)] 0]]
== 0
>> a
== 0 How can I prevent 'compose from binding to the global context? Regards, Ashley

 [2/5] from: g:santilli:tiscalinet:it at: 21-Apr-2004 16:35


Hi Ashley, On Wednesday, April 21, 2004, 4:07:28 PM, you wrote:
>>> b: 'a
AT> == a
>>> do has [a][set 'a 0]
AT> == 0
>>> a
AT> ** Script Error: a has no value AT> ** Near: a
>>> do has [a][do compose/deep [set [(b)] 0]]
AT> == 0
>>> a
AT> == 0 AT> How can I prevent 'compose from binding to the global context? The binding of the body of a function is done at function creation time. Also, COMPOSE just replaces the paren with its value after evaluation, so in this case it just places the word A in place of the paren there; that word! value happens to be bound to the global context. So you can either set B to a word that is already bound to the context you want, like in:
>> do has [a][b: 'a do compose/deep [set [(b)] 0]]
or you can bind the entire block returned by COMPOSE to your local context:
>> do has [a][do bind compose/deep [set [(b)] 0] 'a]
Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [3/5] from: lmecir:mbox:vol:cz at: 21-Apr-2004 18:26


Hi Ashley, ....
>How can I prevent 'compose from binding to the global context? >
you can't, because Compose doesn't do any binding. Here is one way, where Has is allowed to do the binding, but I don't know whether this is the one you need: b: 'a do has [a] compose/deep [do [set [(b)] 0]] -L

 [4/5] from: Gary:Jones:usap:gov at: 22-Apr-2004 9:38


From: Ashley Tr=FCter Given the following:
>> b: 'a
== a
>> do has [a][set 'a 0]
== 0
>> a
** Script Error: a has no value ** Near: a
>> do has [a][do compose/deep [set [(b)] 0]]
== 0
>> a
== 0 How can I prevent 'compose from binding to the global context? **** Hi, Ashley, I'm not an expert on binding, but as you seem to be aware, it appears as though the order of evaluation has 'a being set to 0 in the global context by way of the 'do command *inside* the block. An alternative approach is to "compose" the full line: b: 'a do compose/deep [has [a][set (to-lit-word b) 0]] The actual lines I used in order to be sure that I had it right was: b: 'a do compose/deep [ c: has [a][ set (to-lit-word b) 0 print (b) ] ] such that:
>> do compose/deep [
[ c: has [a][ [ set (to-lit-word b) 0 [ print (b) [ ] [ ]
>> c
0
>> a
** Script Error: a has no value ** Near: a
>> b
== a
>>
Finally, if you want to get the function ready but not run it, then: b: 'a reduce compose/deep [ c: has [a][ set (to-lit-word b) 0 print (b) ] ] Hope that helps. --Scott Jones

 [5/5] from: atruter:labyrinth:au at: 22-Apr-2004 12:33


Thanks to all who responded, I finally ended up using bits of each posted solution to derive the following: b: 'a do has [a] compose [set (to-lit-word b) 0] So simple in hind-sight! ;) Regards, Ashley