Skip to content

Instantly share code, notes, and snippets.

@RomanHargrave
Created March 20, 2021 20:10
Show Gist options
  • Save RomanHargrave/caea726269872be1100c225850829243 to your computer and use it in GitHub Desktop.
Save RomanHargrave/caea726269872be1100c225850829243 to your computer and use it in GitHub Desktop.
proto method declare(@, @, :$tag = Nil, |) { ... }
multi method declare([], [$name], :$tag = Nil) {
say " → leaf $name";
%.children{$name} //= Node[ClassTag].new(
:parent(self),
:tag($tag // ClassTag.new),
:$name
)
}
# This ^
# Appears to shadow this v
multi method declare([], [$name, *@class], :$tag = Nil) {
given %.children{$name} //= Node[ClassTag].new: :parent(self), :$name {
say " → declare({@class.gist}) [ClassTag]";
.declare(@class, :$tag);
}
}
# Also, @class here doesn't match array params unless it's marked as greedy (*)
multi method declare([$name, *@package], *@class, :$tag = Nil) {
given %.children{$name} //= Node[PackageTag].new: :parent(self), :$name {
say " → declare({@package.gist}, {@class.gist})";
.declare(@package, |@class, :$tag);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment