为什么“clear”和“clear”之间的用法存在差异?并“取消设置”;与 Rebol 列表?

发布于 2024-09-11 08:56:37 字数 214 浏览 4 评论 0原文

给定一个列表:

a: [1 2 3 4 5]

为什么用 clear a 来清除列表,用 unset 'a 来取消设置它?我希望 clearunset 始终采用 a'a 作为参数。

Given a list:

a: [1 2 3 4 5]

Why is it clear a to clear the list and unset 'a to unset it? I would have expected both clear and unset to consistently take either a or 'a as their arguments.

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

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

发布评论

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

评论(2

谁的年少不轻狂 2024-09-18 08:56:38

Clear 从单词 a 引用的块中删除条目:

a: [1 2 3 4 5]
length? a
== 5
clear a
length? a
== 0

Unset 删除单词 a 本身:

a: [1 2 3 4 5]
length? a
== 5
unset 'a
length? a
** Script Error: a has no value
** Near: length? a

Clear removes entries from the block referenced by the word a:

a: [1 2 3 4 5]
length? a
== 5
clear a
length? a
== 0

Unset removes the word a itself:

a: [1 2 3 4 5]
length? a
== 5
unset 'a
length? a
** Script Error: a has no value
** Near: length? a
遇到 2024-09-18 08:56:38

UNSET 是一个采用 WORD 类型值的操作! CLEAR 是一个采用 SERIES 类型值的操作!请注意,多个单词可以指向同一个系列!值...

>> a: [m a t t]
== [m a t t]

>> b: a
== [m a t t]

>> clear a
== []

>> b
== []

自从传递一个WORD!目前,将其转换为一系列操作没有任何意义,从技术上讲,CLEAR 可以选择在您向其传递一个 WORD 时进行识别!值,并在这种情况下执行一些特殊操作(例如,查找与该单词关联的值(如果有)并删除其值)。但是“如果没有其他含义,则隐式间接一个单词”并不是一个特别好的不变量,并且您不会在 FIRST 或 FIND 等操作中找到它。

相反的情况......隐式取消设置 QUOTE 其参数。 ..在技术上是可能的。但如果确实如此,当 WORD! 出现时,您将如何处理这种情况!取消设置存储在另一个WORD中?

>> c: [m a t t]
== [m a t t]

>> d: 'c
== c

>> unset d

>> c
** Script error: c has no value

>> d
== c

>> unset 'd

>> d
** Script error: d has no value

UNSET is an operation that takes a value of type WORD! and CLEAR is an operation that takes a value of type SERIES! Note that multiple words can point to the same SERIES! value...

>> a: [m a t t]
== [m a t t]

>> b: a
== [m a t t]

>> clear a
== []

>> b
== []

Since passing a WORD! into a series operation has no meaning at present, it's technically possible that CLEAR could elect to recognize when you passed it a WORD! value, and do something special in that case (for instance, look up the value associated with that word--if any--and erase its values). But "implicitly indirect a word if there is no other meaning" isn't a particularly nice invariant, and you won't find it in operations like FIRST or FIND etc.

The reverse case... to have unset QUOTE its argument implicitly... would be technically possible. But if it did, how would you handle the case when the WORD! to unset was stored in another WORD?

>> c: [m a t t]
== [m a t t]

>> d: 'c
== c

>> unset d

>> c
** Script error: c has no value

>> d
== c

>> unset 'd

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