develooper Front page | perl.perl6.language | Postings from February 2005

Re: scoping functions as list operators?

Thread Previous | Thread Next
From:
Luke Palmer
Date:
February 24, 2005 19:09
Subject:
Re: scoping functions as list operators?
Message ID:
20050225030946.GA15183@navi.cx
Stéphane Payrard writes:
> 
> Giving scoping functions the status of list operators
> would allow to drop parentheses when not used in conjunction
> with initializer so one could write:
> 
>   my $a, $b, $c;
> 
> instead of
> 
>   my ($a, $b, $c);

Hmm, but that kills the Perl 5 ability to do concise inline 'my's:

    while my $line = =$fh {...}

However, since 'for' is getting revamped so that there isn't a need to
use inline 'my' as much, your proposal might be going somewhere.  As you
point out, we don't have a low precedence equals, so we're just creating
a red herring:

    my $x, $y;   # fine
    my $x, $y = (1, 2);  # oops!

We have discussed making equals low precedence enough to eliminate the
parentheses in the standard swap:

    $x, $y = $y, $x;

But there are a couple of arguments against that.  First, Perl
programmers like to make assignments within listops.  Second, the
parentheses make a nice visual "pill" so that you can easily see the
multiple assignment.

I don't think it's a good idea to make a new low precedence assignment.
Let's say we made it <-. Does that imply that there is also
low-precedence binding :<- and compile-time binding ::<- ?  Those don't
look right.  I think we're weighing making good ol' assignment low
precedence vs. having parentheses on 'my'.

Luke

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