develooper Front page | perl.perl5.porters | Postings from July 2012

Re: What would having a & prototype after the first position break?

Thread Previous | Thread Next
From:
Robert Sedlacek
Date:
July 4, 2012 12:33
Subject:
Re: What would having a & prototype after the first position break?
Message ID:
1341430384.28287.6.camel@gomorrah
On Wed, 2012-07-04 at 12:23 -0600, Darin McBride wrote:
> sub do_stuff($;&); # implementation not important, I think.
> 
> my %foo;
> my $foo;
> do_stuff $foo { 'something here' };
> 
> Now, is that passing in $foo as the first parameter and a code ref that returns 
> a static string as the second, or passing in a value contained in %foo as that 
> first parameter, and no code ref?
> 
> Don't get me wrong, I've wanted to be able to put & somewhere other than the 
> first parameter on many occassions.  But first the syntax has to not surprise 
> the reader[0], and we use enough squiggles already for so many different 
> purposes, especially the braces, so a bit of care might be required.
> 
> [0] Surprise with new syntax is fine.  Surprise with something that could be 
> one of multiple syntaxes, probably not so much.

I'm not sure you'd even need to make it optional, since perl would have
to decide if the '{' belongs to the '$foo' and is a hash access or is a
whole new argument.

However, only '&' prototypes seem to not require a comma afterwards, so
shouldn't the above always parse as hash access? I'd assume the code for
the above prototype would be

  do_stuff $foo, { 'something here' };

Or am I missing something?

regards,
Robert

-- 
Robert 'phaylon' Sedlacek

Perl 5 Consultant for
Shadowcat Systems Limited - http://shadowcat.co.uk/


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About