Hi Ladislav,

>     make-proto: function [
>         {MAKE PROTO simulation}
>         proto [object!]
>         spec [block!]
>     ] [set-words object sw word value spc body] [
>         set-words: copy []
>         ; get local words from proto
>         foreach word next first proto [
>             append set-words to set-word! word
>         ]
>         ; append all set-words from SPEC
>         parse spec [
>             any [
>                 copy sw set-word! (append set-words sw) |
>                 skip
>             ]
>         ]
>         ; create a blank object with the desired local words
>         object: blank-object set-words
>         ; set 'self in object to refer to the object
>         object/self: object
>         ; copy the contents of the proto
>         repeat i (length? first proto) - 1 [
>             word: pick next first proto i
>             any-type? set/any 'value pick next second proto i
>             any [
>                 all [string? get/any 'value set in object word copy value]
>                 all [block? get/any 'value set in object word bind/copy
> value in object word]
>                 all [
>                     function? get/any 'value
>                     spc: load mold third :value
>                     body: bind/copy second :value in object word
>                     set in object word func spc body
>                 ]
>                 any-type? set/any in object word get/any 'value
>             ]
>         ]
>         ; bind the SPEC to the object
>         bind spec in object 'self
>         ; evaluate it
>         spec-eval spec
>         ; return the value of 'self as the result
>         return get/any in object 'self
>     ]

Some observations:

1) set-words should be unique, this is not a problem with your blank-object,
but is a problem with your lfunc.

2) Because of return bug, it is better

      get/any in object 'self

instead of

      return get/any in object 'self

3) I did not test your code, but it seems to me that it bind the body function
to the new context. This is only half correct: binding is done in Rebol before
adding the new set-words of spec to the new object:

d: "global"
a: context [b: does [print d]]
a/b; == global
a2: make a [d: "local to a2"]
a2/b; == global

As you can see, the d word in the func body is not binded to the a2 context.
But:

a: context [b: does [print d] d: "local to a"]
a/b; == local to a
a2: make a [d: "local to a2"]
a2/b; == local to a2

I think that your code gives always the result of second example (but i did
not tested it).

4) instead of parsing all the block, because the only oddity of make object is
copy and binding the function bodies, one could use bind and copy deep and
then finding and changing only the function values, but i did not try.

5) why this any-type? ?

 any-type? set/any 'value pick next second proto i

---
Ciao
Romano Paolo Tenca


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to