English 中文(简体)
Rebol and /local Object
原标题:
  • 时间:2009-12-16 20:49:03
  •  标签:
  • rebol

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"

最佳回答

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"

]
问题回答

暂无回答




相关问题
Rebol Email Pop Server error

I have tested pop successufully with some POP servers with Rebol but it doesn t work with my hosting server dreamhost (which works with Outlook I have tested http://wiki.dreamhost.com/Outlook_Express )...

Rebol and /local Object

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:...

In Rebol How to get the Object Path Name (String)?

Let s say I have list: [system/history system/prompt] I want to convert to list-string: ["system/history" "system/prompt"] This may be an obvious answer but I can t see any :) Thanks.

What new Widgets in Rebol 3 Vid? [closed]

Rebol 2 VID was hugely missing Dropdownlist and Treeview, I have made a search on Rebol 3 on Google but couldn t find anything except a discussion. So what will Rebol 3 VID really include as new ...

热门标签