in reply to Re: RFC: Idiom for named read-write arguments (aliases) instead of using $_[0] etc
in thread RFC: Idiom for named read-write arguments (aliases) instead of using $_[0] etc
Thanks for pointing out this subtle difference!
After some meditation I actually I prefer this not being a fatal error!
The (lisp like) possibility of having references to literals always confused me to hell.
Back in time when LISP was running on 4 KB RAM it certainly made sense to avoid copies, but nowadays?
this little experiment shows whats happening when dereferencing a ref to a literal
$x=\1; $y=$$x; # equivalent to $y = 1, i.e. a copy $y++; print $y; #> 2
it's a copy and I thinks thats saner.
The other point is what a modifier-routine should return.
> But they all have a return value of the swapped list, so they're useful even when modifying the parameter list isn't the goal, right?
There are many possibilities:
- dual use by returning the swap => fault tolerance
- empty return to avoid double use => explicit use, ignore error
- carping if defined wantarray. => runtime warnings
But actually these design decisions are out of my scope, cause it doesn't inflict the idiom, cause it's the same problem when using $_[0] aliases etc.
for simplicity I'd simply add an empty return() to the example:
sub swap { my ($a, $b) = \(@_); ( $$a, $$b ) = ( $$b, $$a ); return; }
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: RFC: Idiom for named read-write arguments (aliases) instead of using $_[0] etc
by davido (Cardinal) on Sep 02, 2012 at 17:07 UTC |