I often find myself experimenting in the REPL and I will say something like:
subset Bar of Int where * %% 57;
Then I play around with checks on the Bar-ness for things for a bit.
Everything is happy, until I realize that I want to change the definition of Bar.
If I just redefine Bar, I get a Redeclaration of symbol exception.
I tried using MONKEY-TYPING and augment like this:
use MONKEY-TYPING;
augment subset Bar of Int where * %% 37;
Run Code Online (Sandbox Code Playgroud)
But that netted me the same error.
Why do I want this? So I can iterate on my subset (or class, or other symbol) definitions, while reusing the tests I've already typed that are in my history.
我认为 REPL 的部分魔力是通过EVAL将每个新输入放入新的嵌套词法范围中来实现的。因此,如果您使用mythen 声明事物,则可以使用稍后输入的声明来隐藏它们:
my subset Bar of Int where * %% 57;
sub take-Bar(Bar $n) { say "$n is Bar" }
take-Bar 57;
my subset Bar of Int where * %% 42;
sub take-Bar(Bar $n) { say "$n is Bar" }
take-Bar 42;
Run Code Online (Sandbox Code Playgroud)
如果省略my,则将使用forsubset和class声明,因为实际上是+ 将符号添加到封闭包中...;事实证明,如果您从包中删除该符号,您可以稍后再次隐藏它:ourourmy
subset Bar of Int where * %% 57;
GLOBAL::<Bar>:delete;
subset Bar of Int where * %% 42;
42 ~~ Bar;
Run Code Online (Sandbox Code Playgroud)
注意:这些结果仅来自我在 REPL 中的实验。我不确定是否还有其他未知的副作用。