Create an object/Native demonstration: Difference between revisions

Line 292:
eval {...} called at test.pl line 66</lang>
=={{header|Perl 6}}==
{{works with|rakudo|20132015.10-02-2229}}
Here we use delegation to handle all the normal hash methods that we don't need to override to define our new class.
<lang perl6>class FixedHash {
has $.hash handles *;
method new(*@args) { self.bless: *, hash => Hash.new: @args }
method at_keyAT-KEY(FixedHash:D: $key is copy) is rw {
$!hash.existsEXISTS-KEY($key) ?? $!hash.at_keyAT-KEY($key) !! NilFailure.new(q{can't store value for unknown key});
}
method deleteDELETE-KEY($key) { $!hash.{$key} = Nil }
}
 
Line 311:
say $fh<a b>; # 1 42
say $fh<c>; # Nil
$fh<c> = 43; # error</lang>
</lang>
{{out}}
<pre>(1 2)
(1 Nil(Any))
(1 42)
can't store value for unknown key
Nil
in block <unit> at native-demonstration.p6:17
Cannot assign to a non-container
 
in block at freezehash:21</pre>
Actually thrown at:
in block <unit> at freezehashnative-demonstration.p6:2117</pre>
 
=={{header|Python}}==
Anonymous user