Hi Rebols,

Brian wrote:

> Here's some REBOL pseudo-code of this (for block! spec):
> make-object: func [spec [block!] /local c o] [
>      c: copy [self]
>      foreach x spec [
>          all [
>              set-word? x
>              none? find c (x: to-word x)
>              insert tail c x
>          ]
>      ]
>      o: make-context c  ; Here's the "pseudo-" part
>      o/self: o
>      spec: bind/copy spec in o 'self
>      do spec
>      o/self  ; NOT o, for some reason
> ]

Because the way Make Object! works limits the manipulation with
'self during the object creation, here is a code, that overcomes
the limitation:

Rebol [
    Title: "MakeObject"
    Date: 20/7/2000
    File: %mkobject.r
    Author: "Ladislav Mecir"
    Email: [EMAIL PROTECTED]
    Purpose: {
        Equivalent of Make Object!,
        but unlike it Self can be manipulated
    }
    Category: [General]
]

make-object: func [
    {make object}
    blk [block!] "object spec"
    /local result getres
] [
    getres: func [value] [result: :value]
    blk: head insert insert copy blk :getres [:self]
    make object! blk
    result
]

{
    Example:

    o: make-object [a: 1 self: 2]
    o/self
}


Reply via email to