当我尝试使用反射从另一个对象创建 rebol 对象时,为什么会出现错误

发布于 2024-08-08 17:50:03 字数 497 浏览 1 评论 0原文

>> example: make object! [
[        var1: 10
[        var2: var1 + 10
[        var3: now/time
[        set-time: does [var3: now/time]
[        calculate: func [value] [
[                var1: value
[                var2: value + 10
[            ]
[    ]
>>
>> example2: make object! third example
** Script Error: none is missing its value argument
** Near: calculate: func [value][
    var1: value
    var2: value + 10
]
>>

如何防止对第三个例子的评估?

>> example: make object! [
[        var1: 10
[        var2: var1 + 10
[        var3: now/time
[        set-time: does [var3: now/time]
[        calculate: func [value] [
[                var1: value
[                var2: value + 10
[            ]
[    ]
>>
>> example2: make object! third example
** Script Error: none is missing its value argument
** Near: calculate: func [value][
    var1: value
    var2: value + 10
]
>>

How to prevent evaluation of third example ?

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

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

发布评论

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

评论(2

∞琼窗梦回ˉ 2024-08-15 17:50:03

最好的方法可能是使用construct/with——它基于现有对象创建一个对象。

要基于 example 对象加上一个额外字段来创建一个对象:

example2: construct/with [extra-field: 999] example

或者仅使用相同的字段来创建一个对象

example2: construct/with [] example

Best way is probably to use construct/with -- it creates an object based on an existing one.

To make an object based on the example object plus an extra field:

example2: construct/with [extra-field: 999] example

or to make one with just the same fields

example2: construct/with [] example
烏雲後面有陽光 2024-08-15 17:50:03

您还可以利用 Rebol 的对象原型:

example2: make example []

或者使用附加字段

example3: make example [      
  var4: now/date
  set-date: does [var4: now/date]
]

或替换字段

example4: make example [
  calculate: func [value] [
    var1: value
    var2: value + 20
  ]
]

You could also take advantage of Rebol's object prototyping:

example2: make example []

or with additional fields

example3: make example [      
  var4: now/date
  set-date: does [var4: now/date]
]

or replacing fields

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