You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this is a big enough trap, but it just got me, so…
I had code like this:
my%h= <a 1 b 2>;
say‘hello’if%h<a>:exists;
say‘world’if%h<x>:exists;
Output:
hello
Then I decided to check for more than one element, and using slices is what came to my mind immediately:
my%h= <a 1 b 2>;
say‘hello’if%h<a b>:exists;
say‘world’if%h<x y>:exists;
Output:
hello
world
Not exactly what I hoped for!
Thinking about it, it makes sense. Still, perhaps it is worth to mention something like this as one of the traps (are there any other traps similar to this one?).
The text was updated successfully, but these errors were encountered:
Yes, depending on what you want exactly, you should use anyorall.
The fact that it returns the element itself (and not a list with one element) is a possible source for other traps. It makes sense because this is what you mean in most cases, but when you start generalizing you stumble upon completely different behavior.
Not sure if this is a big enough trap, but it just got me, so…
I had code like this:
Output:
Then I decided to check for more than one element, and using slices is what came to my mind immediately:
Output:
Not exactly what I hoped for!
Thinking about it, it makes sense. Still, perhaps it is worth to mention something like this as one of the traps (are there any other traps similar to this one?).
The text was updated successfully, but these errors were encountered: