Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable Hash[TVal,TKey].new to work (for lizmat++).
This patch updates Hash.new so that it correctly understands
how to create typed hashes from a parameterized Hash type object.
In particular, `Hash[Str,Int].new` will create a hash constrained
to Int keys and Str values.

This patch at least partially addresses
Raku/old-design-docs#43 .

Note that this doesn't resolve the output of `.perl` on
typed hashes; that's a different problem (having to do with
the definition of `Hash.perl` and/or `TypedHash.perl`).
And `.perl` is due for some redesign as well, see
Raku/old-design-docs#6 .
  • Loading branch information
pmichaud committed Jun 13, 2013
1 parent c947f78 commit 90f3bee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core/Hash.pm
Expand Up @@ -3,7 +3,11 @@ my class X::Hash::Store::OddNumber { ... }
my class Hash {
# Has attributes and parent EnumMap declared in BOOTSTRAP

method new(*@args) { @args.hash }
method new(*@args) {
my %h := nqp::create(self);
%h.STORE(@args) if @args;
%h;
}

multi method at_key(Hash:D: $key is copy) is rw {
my Mu $storage := nqp::defined(nqp::getattr(self, EnumMap, '$!storage')) ??
Expand Down

0 comments on commit 90f3bee

Please sign in to comment.