Re: Conditionally included list elements
* Juerd [EMAIL PROTECTED] [2006-06-18 14:10]: pugs my @foo = 1, 2, 3, { 4 if 0 }.(), 5; say @foo.perl [1, 2, 3, 5] bool::true pugs my @foo = 1, 2, 3, { 4 if 1 }.(), 5; say @foo.perl [1, 2, 3, 4, 5] bool::true That’s “conceptually noisy” though… I don’t know if I’d end up picking $foo, $bar, { $baz if $wibble }.(), $quux over $foo, $bar, ( $wibble ?? $baz !! () ), $quux With more complex “movable parts,” there would be even less difference between the two than here. Does Perl 6 have `do BLOCK` like Perl 5? That would make it $foo, $bar, do { $baz if $wibble }, $quux which I find more acceptable. Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;
Re: Conditionally included list elements
Hi Stuart, * Stuart Cook [EMAIL PROTECTED] [2006-06-18 15:05]: On 6/18/06, A. Pagaltzis [EMAIL PROTECTED] wrote: Is there a construct in Perl 6 to express this more immediately? Something along the lines of the following would seem ideal: $foo, $bar, ( $baz if $wibble ), $quux How about this: pugs sub infix:pv($x, $cond) { $cond ?? ($x,) !! () }; say 1, 2, (3 pv 1), 4 1234 bool::true Good point! I like. However, what are the evaluation semantics here? Neither the ternary nor the `if`-based solutions evaluate the expression they return if the condition turns out to be false. Wouldn’t your solution evaluate it unconditionally? Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: Conditionally included list elements
On Sun, Jun 18, 2006 at 05:18:14PM +0200, A. Pagaltzis wrote: pugs sub infix:pv($x, $cond) { $cond ?? ($x,) !! () }; say 1, 2, (3 pv 1), 4 However, what are the evaluation semantics here? Neither the ternary nor the `if`-based solutions evaluate the expression they return if the condition turns out to be false. Wouldn’t your solution evaluate it unconditionally? That can be solved with an explicit thunk: sub infix:pv1 ($x, $cond) { $cond ?? ($x(),) !! () }; say 1, 2, {3} pv 1, 4 Or maybe 'is lazy' on $x? -- Gaal Yahas [EMAIL PROTECTED] http://gaal.livejournal.com/
Re: Conditionally included list elements
On Sun, Jun 18, 2006 at 05:18:52PM +0200, A. Pagaltzis wrote: : Maybe TheLarry can enlighten us… :-) We already have the operator you want. It's spelled Cxx?. :-) Larry
Re: Conditionally included list elements
* Larry Wall [EMAIL PROTECTED] [2006-06-18 19:05]: On Sun, Jun 18, 2006 at 05:18:52PM +0200, A. Pagaltzis wrote: : Maybe TheLarry can enlighten us… :-) We already have the operator you want. It's spelled Cxx?. :-) Nice. :-) How’s it used? S03 doesn’t list it. Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;
Re: Conditionally included list elements
On Sun, Jun 18, 2006 at 07:27:57PM +0200, A. Pagaltzis wrote: : * Larry Wall [EMAIL PROTECTED] [2006-06-18 19:05]: : On Sun, Jun 18, 2006 at 05:18:52PM +0200, A. Pagaltzis wrote: : : Maybe TheLarry can enlighten us… :-) : : We already have the operator you want. It's spelled Cxx?. :-) : : Nice. :-) How’s it used? S03 doesn’t list it. Nope. Doesn't list the C**- or C||! operators either. :-) (Hint: it doesn't matter if you put a space between the Cxx and the C?.) Larry
Re: Conditionally included list elements
* Larry Wall [EMAIL PROTECTED] [2006-06-18 19:40]: On Sun, Jun 18, 2006 at 07:27:57PM +0200, A. Pagaltzis wrote: * Larry Wall [EMAIL PROTECTED] [2006-06-18 19:05]: We already have the operator you want. It's spelled Cxx?. :-) Nice. :-) How’s it used? S03 doesn’t list it. Nope. Doesn't list the C**- or C||! operators either. :-) (Hint: it doesn't matter if you put a space between the Cxx and the C?.) Ahh. So you’re telling me that Perl 5 has the same operator, but it spells it Cx!!. Clever! Regards, -- #Aristotle *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined wantarray]/e;$1}; Just-another-Perl-hacker;