http://qs321.pair.com?node_id=824449


in reply to Re^6: in search of a more elegant if then else
in thread in search of a more elegant if then else

Out of interest, do you have a preference amongst those 4?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^8: in search of a more elegant if then else
by TimToady (Parson) on Feb 21, 2010 at 03:13 UTC
    I have a vague preference for the last one, but only because it's most like how I'd actually write it:
    my @filtered = do for $s.comb -> $a, $b { [ $a, $b ] if $a ne $b; }
    or maybe slightly clearer would be:
    my @filtered = gather for $s.comb -> $a, $b { take [ $a, $b ] if $a ne $b; }
    But mathematicians are likely to prefer the list comprehension syntax, I suspect.