John Porter writes:
: Buddha Buck wrote:
: > Personally, I'd rather save let for:
:
: I appreciate the sentiment, but I believe it's misplaced
: and unnecessary.
:
:
: > (let ($x,$y,$z,...) = (1,2,3,...) in { FOO })
: >
: > which would be equivilant to:
: >
: > ((sub {my ($x,$y,$z,...) = @_; FOO })(1,2,3,...))
:
: But it's also equivalent to
:
: {
: my ($x,$y,$z,...) = (1,2,3,...);
: FOO
: }
:
: which is far clearer than either of the above syntaces.
I agree, with the possible exception that we still might need to use
a different assignment operator to treat the left side as a prototype.
But think I'd rather attach that info to the operator itself:
my ($x,$y,$z,...) := (1,2,3,...);
rather than using another keyword such as "let".
In Apo2, I said that any list assignment in parens might use
prototyping rules, but I'm leaning the other way again. I'm thinking
we really ought to leave Perl 5's = operator alone, or people will
continually wonder why
($a, $b, $c) = @foo;
no longer does what they expect. The = operator can stay value
assignment, while := (or whatever name we decide on) can be called an
object assignment, or an alias assignment, or a definitional
assignment, or a reference assignment, or some such:
(@foo, @bar) := (@bar, @foo); # swap two arrays
Note that this is another clear case where the variable properties
stay with the variable, but the value properties go with the swapped
values.
I'd also point out that if @foo or @bar were tied, this is probably
an illegal operation, since most tied arrays aren't going to let you
set a reference. At best, they might emulate it by copying the values.
To put it another way, the reference assignment:
(@foo, @bar) := (@bar, @foo); # swap two arrays
is equivalent to the ordinary list assignment:
(@foo.ptr, @bar.ptr) = (@bar.ptr, @foo.ptr);
assuming for the sake of argument that there's a scalar lvalue .ptr
method that can manipulate the variable's internal reference directly.
But a tied array might not be able to implement a .ptr method if the
internal representation is not pointer based. You wouldn't generally
want to store a pointer in a DBM file, for instance.
Larry