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.

> 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

-- 
To unsubscribe from the list, just send an email to rebol-request
at rebol.com with unsubscribe as the subject.

Reply via email to