develooper Front page | perl.perl6.users | Postings from January 2016

'!' versus 'not' in boolean expression

Thread Next
Tom Browder
January 18, 2016 18:56
'!' versus 'not' in boolean expression
Message ID:
In creating some new Perl 6 programs I've run across several instances
I'm confused about, to wit:

Example 1

> my %h; say 'false' if !%h<a>:exists;
Unexpected named parameter 'exists' passed

Example 2

> my %h; say 'false' if not %h<a>:exists;

It looks like '!' doesn't work as I thought it was supposed to.  But,
I just discovered that when I use parens, it works.

Example 3

> my %h; say 'false' if !(%h<a>:exists);

I presume the parens would cure the similar things I've noticed with
other classes.

When I look at the docs on Operators I see this:

prefix !

multi sub prefix:<!>(Mu) returns Bool:D

Negated boolean context operator.

Coerces the argument to Bool by calling the Bool method on it, and
returns the negation of the result. Note that this collapses

prefix not

multi sub prefix:<not>(Mu $x) returns Bool:D

Evaluates its argument in boolean context (and thus collapses
Junctions), and negates the result.

Those two definitions look very similar to my eyes, but I think the
subtle difference is intentional.But they are not identical.

Is there some rule of thumb here that a Perl 6 wannabe can grasp in
Perl 5 terms (e.g., prefer 'not' over '!')?  Or am I going to have to
go deep early into the object class structure?

Many thanks.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About