develooper Front page | perl.perl6.language | Postings from January 2004

Re: Comma Operator

Thread Previous | Thread Next
Jonathan Lang
January 20, 2004 20:13
Re: Comma Operator
Message ID:
Joe Gottman wrote:
>    About a month ago, a thread here suggested that we change the meaning
> of the comma operator.  Currently, in scalar context the expression
>     foo(), bar()
> means "evaluate foo(), discard the result, then return the value of
> bar()".
> It was suggested that this be changed to return the 2-element array
> (foo(), bar()).  Has Larry ruled on this yet?

Not that I'm aware of.  For the most part, the previous discussion was
focusing on what to replace the comma with in the case of "discard all but
the last result", and my impression was that any ruling on the change
would likely be contingent on the presence or absence of a suitable
replacement.  That said, 

>     By the way, even if we do make this change, I think that in void
> context the expression
>     foo(), bar()
> should still simply evaluate its parameters in order for their side-
> effects.  This would allow comma expressions to remain as-is in loop 
> statements (formerly for statements), which is where most of them are 
> found anyway.  

I do like this suggestion.  In the majority of cases where I've used the
comma operator, I've either enclosed the whole thing in parentheses to
turn it into a list, or I've treated it as a sequence of operators where
even the last result got discarded.  I've rarely been interested in just
the last result, and I wouldn't mind that functionality being provided by
means of a C<last> function which evaluates the list parameters for their
side effects and returns the value of the last list parameter.  

Jonathan "Dataweaver" Lang

Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes

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