gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:26:10 25 4
gpt4 key购买 nike

我创造了这个

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

使用新的 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

我不明白为什么?

最佳答案

当您重新定义在 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.
}
]
]

(以上代码我完全没有测试过,应该算是伪代码。)

关于rebol - 为什么不能在 Rebol 中覆盖内置函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1150492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com