Rebol和/ local Object

时间:2009-12-16 20:49:04

标签: rebol

如果Obj是本地的,则下面的新功能不起作用。如果我从/ local删除它可以工作。那么该怎么做才能让它与当地的Obj一起工作呢?对你来说当然不难。

Person: make object! [

Person: func[FirstName LastName][
     Self/FirstName: FirstName
     Self/LastName: LastName
     Print Self/FirstName
     Print Self/LastName
]
FirstName: ""
LastName: ""

]



new: func[Class [Object!] Param-Block [block!] /local Obj][
    Constructor: to-word pick pick Class 1 2
    Obj: Make Class []
    params: copy ""
    foreach param Param-Block [
      if string? param [
        param: rejoin [{"} param {"}]
      ]
      append params param
      append params " "
    ]
    do rejoin [{do get in Obj Constructor} { } params]
    Obj
]
;FOR TEST
John: new Person["John" "Doe"]

会给予

>> probe John
make object! [
    Person: func [FirstName LastName][
        Self/FirstName: FirstName
        Self/LastName: LastName
        Print Self/FirstName
        Print Self/LastName
    ]
    FirstName: ""
    LastName: ""
]
>>

这是FirstName和LastName是“”而不是“John”“Doe”

1 个答案:

答案 0 :(得分:3)

这有效......

    rebol []

    Person: make object! [
        Person: func [ names] [
            Self/FirstName: names/1
            Self/LastName: names/2
        ]
        FirstName: copy ""
        LastName: copy ""
    ]

    new: func [class [object!] param-block [block!]
        /local obj constructor 
    ] [
        constructor: second first class
        obj: make class []
        do get in obj constructor copy param-block
        obj
    ]

    test: new person [ "John" "Doe" ]
    probe test

    make object! [
        Person: func [names][
            Self/FirstName: names/1
            Self/LastName: names/2
        ]
        FirstName: "John"
        LastName: "Doe"
    ]

    test2: new person [ "Dick" "Nixon" ]
    probe test2

    make object! [
        Person: func [names][
            Self/FirstName: names/1
            Self/LastName: names/2
        ]
        FirstName: "Dick"
        LastName: "Nixon"

]