HaloO, On Monday, 2. August 2010 20:02:40 Mark J. Reed wrote: > On Sun, Aug 1, 2010 at 6:02 PM, Jonathan Worthington <jonat...@jnthn.net> wrote: > > No, given-when is smart-matching. The RHS of a smart-match decides what > > happens. If you do True ~~ 1 then that's 1.ACCEPTS(True) which is going > > to do +True and thus match. > > OK, but what about 0 ~~ True? That's what started this thread, > extricated from the complicating trappings of given/when. Right now, > (anything ~~ True) is true, and IMHO that's a misfeature; it's at > least surprising. I'd expect (anything ~~ True) to be synonymous with > ?(anything): true only if the LHS boolifies to true. By the same > token, (anything ~~ False) would be synonymous with !?(anything).
Note also that ($anything ~~ foo()) just throws away $anything. I would opt for a regularization of the smart match table. First of all the generic scalar rule should coerce the LHS to the type of the RHS and then use === on them. This is how the Any ~~ Set case is specced. The cases Stringy and Numeric fall out naturally from this definition. The Bool case should become a special case just like Stringy and Numeric. The auto-invocation of Callable is a good thing but the fact that the return value is not subject to the generic scalar case is a misfeature. That is we loose: given 42 { when foo() {...} when bar() {...} when baz() {...} } which could mean to execute that block whose controlling sub complies with the given and not the one that returns True first. Note that this style is particularly usefull with given True. But then we sort of have the coercing the wrong way around because the idea is to check the return value in boolean context not coercing the True to whatever the type of the return value is. BTW, how is the case with a unary sub written? Could someone please give a rational for the interspersing technique given $anything { when $one {...} when two() {...} when $three {...} } where two() returning a true value prevents the case $three. And if it is considered usefull I support the whenever proposal because different things should look different. BTW, would given $anything { when $one {...} if two() {...} else { when $three {...} } } still smart match $anything with $three? Or is the topic the return value of two() at that point? Regards TSa -- "The unavoidable price of reliability is simplicity" -- C.A.R. Hoare "Simplicity does not precede complexity, but follows it." -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan