具有类型约束的无符号 "variables" 是否可以重新绑定?
Should sigilless "variables" with type constraints be re-bindable?
[EDIT:关闭支持 https://Whosebug。com/questions/69231506/what-are-the-rules-for-re-binding,我在更清楚地理解了我在这个问题中想问的内容后制定的.]
我对 的理解是,没有印记的声明符号 永远不会 被反弹。引用该答案:
Yes, [the current behavior is] certainly by design, and - like most things in [Raku] design - it's this way for more than one reason.… It was decided to make the sigilless symbol form a "static single assignment" syntax…. There were various reasons for this, including… enhancing program readability by having a form that lets the reader know that the symbol will never be rebound to a new value
(强调已添加。)
鉴于此,我很惊讶地看到下面的代码:
my Int \b = 8;
say "{b*b}"; # OUTPUT: «64»
b := 4;
say "{b*b}"; # OUTPUT: «16»
也就是说,当 b
声明时没有 sigil 但 有 类型约束时,它可以被反弹 - 不像它没有那样类型约束。这种行为是错误还是正确的?
如果是,它如何符合上面链接的答案中提到的设计注意事项?
(另请参阅 GitHub 上的 this Raku/doc issue thread,了解有关此行为的讨论以及它是否是故意的。)
这是一个错误。
[任何语言都不应该 有时 禁止无符号变量重新绑定,具体取决于声明中是否指定了类型或类型。
[EDIT:关闭支持 https://Whosebug。com/questions/69231506/what-are-the-rules-for-re-binding,我在更清楚地理解了我在这个问题中想问的内容后制定的.]
我对
Yes, [the current behavior is] certainly by design, and - like most things in [Raku] design - it's this way for more than one reason.… It was decided to make the sigilless symbol form a "static single assignment" syntax…. There were various reasons for this, including… enhancing program readability by having a form that lets the reader know that the symbol will never be rebound to a new value
(强调已添加。)
鉴于此,我很惊讶地看到下面的代码:
my Int \b = 8;
say "{b*b}"; # OUTPUT: «64»
b := 4;
say "{b*b}"; # OUTPUT: «16»
也就是说,当 b
声明时没有 sigil 但 有 类型约束时,它可以被反弹 - 不像它没有那样类型约束。这种行为是错误还是正确的?
如果是,它如何符合上面链接的答案中提到的设计注意事项?
(另请参阅 GitHub 上的 this Raku/doc issue thread,了解有关此行为的讨论以及它是否是故意的。)
这是一个错误。
[任何语言都不应该 有时 禁止无符号变量重新绑定,具体取决于声明中是否指定了类型或类型。