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

Words escaping from context! help needed!

 [1/11] from: kgozlin:neokartgis:pl at: 11-Feb-2005 9:58


Hi list! I think I need some "binding" :-) this script does not work as I want. look : unset 'a ; just for testing unset 'b ; object: make object! [ variables: [ a b] ; this block may change during object lifetime ; so should be always referenced data: [1 2] ; data to set, may change too ; it has to be that way ; below is what i want repair executor: func [ program] [ use variables [ ; <-- i want to variables to be defined only here --> set variables data ; setting variables do program ; executing ] ] ] testing :
>> object/executor [ print a + b]
3
>>
looks fine, but :
>> print [a b]
1 2
>>
ups! variables are in global context please help how to keep them in USE block thanks in advance Karol

 [2/11] from: volker::nitsch::gmail::com at: 11-Feb-2005 13:07


On Fri, 11 Feb 2005 09:58:20 +0100, Karol Go=C5=BAli=C5=84ski <[kgozlin--neokartgis--com--pl]> wrote:
> Hi list! > I think I need some "binding" :-)
<<quoted lines omitted: 5>>
> variables: [ a b] ; this block may change during object > lifetime
;"make object!" detects only set-word in top-level. Rest keeps old ;binding.. ;You need a: b: none
> ; so should be always referenced > data: [1 2] ; data to set, may change too
<<quoted lines omitted: 23>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler

 [3/11] from: antonr:lexicon at: 11-Feb-2005 23:52


The problem is that the words in variables is not bound to your object. When objects are made, the spec block is first scanned for set-words. In your example, there are three set-words in the spec block, [variables: data: executor:] These are now the only words which can exist directly in the object, and they are bound to the object. Objects can't be arbitrarily expanded or shrunk; you can't add or remove words. (This is a pity, but I believe it speeds things up the way it is.) Anyway, as sad as that sounds, there is a way of wrapping things up safely in a context. Here is a possible solution: my-ctx: context [ make-object-spec: func ["Prepare an object spec block from words and data." words [block!] data [block!] /local result ][ result: copy [] repeat n length? words [append result reduce [to-set-word words/:n data/:n]] result ] executor: func [variables data program /local object][ object: context make-object-spec variables data do bind/copy program in object 'self ] ] ; Test my-ctx/executor [a b] [1 2] [print a + b] ;>> a ;** Script Error: a has no value ;** Near: a I should also like to know the reason why you wanted this. Regards, Anton.

 [4/11] from: kgozlin:neokartgis:pl at: 11-Feb-2005 13:58


I set them to none, but it does not help, see unset 'a unset 'b object: make object! [ variables: [ a b] data: [1 2] executor: func [ program] [ use variables [ a: b: none set variables data do program ] ] ]
>> >> object/executor [ print a + b]
3
>> print [a b]
1 2
>>
still 'a and 'b are in global context but I want also do such things : object/valiables: [ x y] object/data: [3 4] object/executor [ print x * y] 12 so I can not rely on constatnt variables function foreach does similar thing but i have no idea how thanks for reply Karol

 [5/11] from: gabriele::colellachiara::com at: 11-Feb-2005 14:50


Hi Karol, On Friday, February 11, 2005, 9:58:20 AM, you wrote: KG> executor: func [ program] [ KG> use variables [ ; <-- i want to variables to be defined KG> only here --> KG> set variables data ; setting variables KG> do program ; executing KG> ] KG> ] KG> ] A simple solution to your problem is: executor: func [program] [ use variables compose [ set [(variables)] data (program) ] ] Regards, Gabriele. -- Gabriele Santilli <g.santilli-tiscalinet.it> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [6/11] from: volker::nitsch::gmail::com at: 11-Feb-2005 18:02


On Fri, 11 Feb 2005 13:58:14 +0100, Karol Go=C5=BAli=C5=84ski <[kgozlin--neokartgis--com--pl]> wrote:
> I set them to none, but it does not help, see > unset 'a
<<quoted lines omitted: 10>>
> ] > ]
when i wrote: "make object!" detects only set-word in top-level" i meant the top-level block. "make object!" does not look inside inner blocks. so this: make object![ inner-block: [ a: b: none ] ] would not work. and you do similar with executor. but this: make object![ a: b: none ] works. "make object!" sees the set-words and makes them local for everything inside the block. so the 'a 'executor will be bound to the object and no longer be global. its also not required to set them to none, only that they appear as set-words in the top-level block. so 'executor is local too, because the appears "executor:".
> >> > >> object/executor [ print a + b]
<<quoted lines omitted: 16>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler

 [7/11] from: ammon:johnson:gma:il at: 11-Feb-2005 12:08


Gabrielle is right, COMPOSE will do what you want but it gets slightly more complex if it want to really work dynamically... example: make object! [ variables: [a b] data: [1 2] executor: func [program] [ use variables compose/deep [ set [(variables)] data do bind load [(program)] (to lit-word! first variables) ] ] ] example/executor [print a + b] This is a subject (context and binding) I've been meaning to write an article on but there just aren't enough hours in a day... HTH ~~Ammon ;~> On Fri, 11 Feb 2005 18:02:05 +0100, Volker Nitsch <[volker--nitsch--gmail--com]> wrote:
> On Fri, 11 Feb 2005 13:58:14 +0100, Karol Go=C5=BAli=C5=84ski > <[kgozlin--neokartgis--com--pl]> wrote:
<<quoted lines omitted: 65>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- Enjoy!! ~~~ Ammon ~~~ ~ Sui Generis ~ ~~~~ ;~> ~~~~

 [8/11] from: gabriele::colellachiara::com at: 12-Feb-2005 16:34


Hi Ammon, On Friday, February 11, 2005, 8:08:40 PM, you wrote: AJ> example: make object! [ AJ> variables: [a b] AJ> data: [1 2] AJ> executor: func [program] [ AJ> use variables compose/deep [ AJ> set [(variables)] data AJ> do bind load [(program)] (to lit-word! first variables) AJ> ] AJ> ] AJ> ] AJ> example/executor [print a + b] Lack of /DEEP was my fault, but you don't need the BIND (nor does the LOAD have any sense there) if you use COMPOSE. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [9/11] from: ammon:johnson:gma:il at: 12-Feb-2005 13:56


Hmm... You are right. I thought that I tried that but I guess I didn't... Enjoy!! ~~Ammon ;~> On Sat, 12 Feb 2005 16:34:50 +0100, Gabriele Santilli <[gabriele--colellachiara--com]> wrote:
> Hi Ammon, > On Friday, February 11, 2005, 8:08:40 PM, you wrote:
<<quoted lines omitted: 19>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- Enjoy!! ~~~ Ammon ~~~ ~ Sui Generis ~ ~~~~ ;~> ~~~~

 [10/11] from: kgozlin::neokartgis::com::pl at: 14-Feb-2005 11:35


I have no idea how, but it works! It must be that famous Rebol simplicity ;-) Anyway, thanks a lot, you are great! Karol

 [11/11] from: kgozlin:neokartgis:pl at: 9-Feb-2005 15:50


Hi list! I think I need some "binding" :-) this script does not work as I want. look : unset 'a ; just for testing unset 'b ; object: make object! [ variables: [ a b] ; this block may change during object lifetime ; so should be always referenced data: [1 2] ; data to set, may change too ; it has to be that way ; below is what i want repair executor: func [ program] [ use variables [ ; <-- i want to variables to be defined only here --> set variables data ; setting variables do program ; executing ] ] ] testing :
>> object/executor [ print a + b]
3
>>
looks fine, but :
>> print [a b]
1 2
>>
ups! variables are in global context please help how to keep then in USE block

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted