Stuart Cook skribis 2006-06-18 22:59 (+1000):
> pugs> sub infix:<pv>($x, $cond) { $cond ?? ($x,) !! () }; say 1, 2,
> (3 pv 1), 4
> 1234
> bool::true
> pugs> sub infix:<pv>($x, $cond) { $cond ?? ($x,) !! () }; say 1, 2,
> (3 pv 0), 4
> 124
> bool::true
> I couldn't think of a good name for the new operator, though.
pugs> sub infix:<?!>($cond, $x) { $cond ?? ($x,) !! () }
undef
pugs> 1, 2, (0 ?! 3), 4
(1, 2, 4)
pugs> 1, 2, (1 ?! 3), 4
(1, 2, 3, 4)
pugs> 1, 2, 0 ?! 3, 4
(1, 2, 4)
pugs> 1, 2, 1 ?! 3, 4
(1, 2, 3, 4)
I'd always use it with parens, though.
Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html