develooper Front page | perl.perl6.language | Postings from June 2006

~~ with *

Thread Next
Daniel Hulme
June 6, 2006 09:13
~~ with *
Message ID:
I only vaguely recall the discussions a while back about what
smart-matching against Booleans should do. IIRC, there are two
positions, and a good argument for either side:

C<$foo ~~ True> means C<?$foo>; C<$foo ~~ False> means C<! ?$foo>
C<$foo ~~ True> means C<True>; C<$foo ~~ False> means C<False>

The first of these adds expressiveness to given/when, and behaves the
intuitive way when both the RHS of a match is a Boolean-valued variable
(I would intuitively expect C<$bool1 ~~ $bool2> to do Boolean equality).
The second means that the default case of a while can be syntactic sugar
for C<when (true)>, and I see that we went for the latter on those

However, if we make the Whatever star on the RHS always match, we can
make C<default> equivalent to C<when (*)>, reminiscently of a shell
script, and we can also make C<$bool1 ~~ $bool2> do the obvious thing.
I don't immediately see any big wins for being able to say C<$foo ~~ *>,
nor any big loses for it no longer falling through to MMD.

Any thoughts?

"Twelve? Who needs twelve? Couldn't we make do with six?"  -- Lew Grade,
<keyid 885b170d>   trying to cut production costs on 'Jesus of Nazareth'
<>              "The illegal we do immediately,
the unconstitutional takes a little longer."  Henry Kissinger, June 1972

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