在 Raku 集合中查找列表键

Looking up list keys in a Raku set

在 Raku 中,我可以创建一组列表:

> my $set = SetHash.new((1, 2), (3, 4, 5))
SetHash((1 2) (3 4 5))
> $set.keys.map(&WHAT)
((List) (List))

但我似乎无法检查列表键是否存在:

> $set{(1,2)}
(False False)

...因为下标中的列表被解释为切片,而不是单个键。

有什么办法可以查到这样的key吗?

设置 ValueTypes 的工作。尽管 List 可能看起来像 ValueType,但不幸的是它不是(因为虽然 List 中的元素数量是固定的,但它可能包含可变元素,因此 并不总是 常量).

这就是我在几年前实施 Tuple 模块的原因。这允许您:

use Tuple;
my $set := SetHash.new: tuple(1,2), tuple(1,2,3);
say $set{tuple(1,2)};  # True

当然,有点冗长。您可以通过重新定义 tuple 子来缩短冗长:

use Tuple;
my &t := &tuple;
my $set := SetHash.new: t(1,2), t(1,2,3);
say $set{t(1,2)};  # True