Permalink
Browse files

Make :exists and :delete up to spec

The :exists and :delete adverbial pairs on hash accesses were always
interpreted as "true".  Which makes constructs as :!exists or :delete($really)
not work.
  • Loading branch information...
1 parent 2a04f23 commit 5e360a6fa2367e99cbf29492512966c49e4aefc6 @lizmat lizmat committed May 19, 2013
Showing with 15 additions and 7 deletions.
  1. +15 −7 src/core/Any.pm
View
@@ -306,17 +306,19 @@ my class Any {
multi method postcircumfix:<{ }>(:$BIND!) {
X::Bind::ZenSlice.new(type => self.WHAT).throw
}
+
+ # %h<key>
multi method postcircumfix:<{ }>(\SELF: $key) is rw {
SELF.at_key($key)
}
multi method postcircumfix:<{ }>(\SELF: $key, Mu :$BIND! is parcel) is rw {
SELF.bind_key($key, $BIND)
}
- multi method postcircumfix:<{ }>(\SELF: $key, :$delete!) is rw {
+ multi method postcircumfix:<{ }>(\SELF: $key, :$delete! where so $delete) is rw {
SELF.delete($key)
}
multi method postcircumfix:<{ }>(\SELF: $key, :$exists!) is rw {
- SELF.exists($key)
+ !( SELF.exists($key) ?^ $exists )
}
multi method postcircumfix:<{ }>(\SELF: $key, :$p!) is rw {
RWPAIR($key, SELF.at_key($key))
@@ -327,6 +329,8 @@ my class Any {
multi method postcircumfix:<{ }>(\SELF: $key, :$kv!) is rw {
($key, SELF.at_key($key))
}
+
+ # %h<a b c>
multi method postcircumfix:<{ }>(\SELF: Positional \key) is rw {
nqp::iscont(key)
?? SELF.at_key(key)
@@ -335,14 +339,16 @@ my class Any {
multi method postcircumfix:<{ }>(Positional $key, :$BIND!) is rw {
X::Bind::Slice.new(type => self.WHAT).throw
}
- multi method postcircumfix:<{ }>(\SELF: Positional \key, :$delete!) is rw {
+ multi method postcircumfix:<{ }>(
+ \SELF: Positional \key, :$delete! where so $delete ) is rw {
nqp::iscont(key)
?? SELF.delete(key)
!! key.map({ SELF.delete($_) }).eager.Parcel
}
- multi method postcircumfix:<{ }>(\SELF: Positional \key, :$exists!) is rw {
+ multi method postcircumfix:<{ }>(
+ \SELF: Positional \key, :$exists!) is rw {
nqp::iscont(key)
- ?? SELF.exists(key)
+ ?? !( SELF.exists(key) ?^ $exists )
!! die("Cannot use exists adverb with a slice")
}
multi method postcircumfix:<{ }>(\SELF: Positional \key, :$p!) is rw {
@@ -365,17 +371,19 @@ my class Any {
?? SELF.at_key(key)
!! key.map({ SELF.exists($_) ?? SELF.at_key($_) !! () }).eager.Parcel
}
+
+ # %h{*}
multi method postcircumfix:<{ }>(\SELF: Whatever) is rw {
SELF{SELF.keys}
}
multi method postcircumfix:<{ }>(Whatever, :$BIND!) is rw {
X::Bind::Slice.new(type => self.WHAT).throw
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$delete!) is rw {
- SELF{SELF.keys}:delete
+ SELF{SELF.keys}:$delete
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$exists!) is rw {
- SELF{SELF.keys}:delete
+ SELF{SELF.keys}:$exists
}
multi method postcircumfix:<{ }>(\SELF: Whatever, :$p!) is rw {
SELF{SELF.keys}:p

0 comments on commit 5e360a6

Please sign in to comment.