Rebol 和 /local 对象

发布于 2024-08-15 06:44:11 字数 1052 浏览 4 评论 0原文

如果 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: ""
]
>>

那是名字和姓氏是“”而不是“John”“Doe”

The new function below doesn't work if Obj is local. If I remove it from /local it works. So what to do to make it work with a local Obj thanks ? Sure not hard for you.

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"]

Would give

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

That is FirstName and LastName are "" instead of "John" "Doe"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们只是彼此的过ke 2024-08-22 06:44:11

这有效...

    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"

]

This works ...

    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"

]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文