Permalink
Browse files

Add missing Any.exists-key accelerator

  • Loading branch information...
1 parent e6af5b8 commit 2c9ae3eb6897ca56cbea1bb5db446236043a47f8 @sorear committed May 28, 2011
Showing with 13 additions and 3 deletions.
  1. +0 −3 lib/CORE.setting
  2. +13 −0 lib/Kernel.cs
View
@@ -870,9 +870,6 @@ my class Hash {
}
augment class Any {
- method exists-key($) {
- defined(self) ?? die("Cannot use hash access on an object of type $.typename") !! False
- }
method delete-key($) {
defined(self) ?? die("Cannot use hash access on an object of type $.typename") !! Any
}
View
@@ -1623,6 +1623,18 @@ class IxCallMethod : IndexHandler {
}
}
+ class IxAnyExistsKey : IndexHandler {
+ public override Variable Get(Variable obj, Variable key) {
+ if (key.islist) {
+ return Slice(obj, key);
+ }
+
+ P6any os = obj.Fetch();
+ if (!os.IsDefined())
+ return Kernel.FalseV;
+ throw new NieczaException("Cannot use hash access on an object of type " + os.mo.name);
+ }
+ }
class IxAnyAtKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
if (key.islist) {
@@ -3060,6 +3072,7 @@ class LastFrameNode {
HashMO.Invalidate();
AnyMO = new STable("Any");
+ WrapHandler1(AnyMO, "exists-key", new IxAnyExistsKey());
WrapHandler1(AnyMO, "at-key", new IxAnyAtKey());
WrapHandler1(AnyMO, "at-pos", new IxAnyAtPos());
Handler_Vonly(AnyMO, "list", new CtxAnyList(), null);

0 comments on commit 2c9ae3e

Please sign in to comment.