Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add missing Any.exists-key accelerator

  • Loading branch information...
commit 2c9ae3eb6897ca56cbea1bb5db446236043a47f8 1 parent e6af5b8
@sorear authored
Showing with 13 additions and 3 deletions.
  1. +0 −3  lib/CORE.setting
  2. +13 −0 lib/Kernel.cs
View
3  lib/CORE.setting
@@ -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
13 lib/Kernel.cs
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.