为什么不能在Rebol中覆盖内置函数?

4 rebol rebol2

我创造了这个

cloneset: :set
set: func[word [word!] value][
if/else (type? get word) = list! [
    print "list is immutable"
][

    cloneset word value
    protect word
]
]
protect 'cloneset
protect 'set
Run Code Online (Sandbox Code Playgroud)

使用新的set函数定义val函数时出现此错误:

val: func[word [word!] value][
    set word value
    protect word
    value
]

>> val: func[word [word!] value][
[        set word value
[        protect word
[        value
[    ]
** Script Error: set has no refinement called any
** Where: throw-on-error
** Near: if error? set/any 'blk try
Run Code Online (Sandbox Code Playgroud)

我不明白为什么?

Gre*_*ley 6

当您重新定义定义的单词时system/words,您应该完全重新定义它.该set字有两个改进:/pad/any你重新定义还应该包括:

cloneset: :set
set: func [
    word [word! block!]
    value
    /any
    /pad
][
    either all [word? word list? get word] [
        throw make error! "List is immutable!"
    ][
        comment {
           At this point you'll have to forward the arguments and refinements
           of your SET method to CLONESET. This will be made much easier in R3
           with the new APPLY function.
        }
    ]
]
Run Code Online (Sandbox Code Playgroud)

(我根本没有测试过上面的代码.它应该被视为伪代码.)

  • 在多个帖子上投票给你,但由于我没有注册,因此无法给出好的答案. (2认同)