note
LanX
<i>> Second, as long as we're working so hard to modify the parameter list, let's make the following a fatal error:
swap( qw(this that) );</i><P>
Thanks for pointing out this subtle difference!<P>
After some meditation I actually I prefer this not being a fatal error!<P>
The (lisp like) possibility of having references to literals always confused me to hell. <P>
Back in time when LISP was running on 4 KB RAM it certainly made sense to avoid copies, but nowadays?<P>
this little experiment shows whats happening when dereferencing a ref to a literal
<c>
$x=\1;
$y=$$x; # equivalent to $y = 1, i.e. a copy
$y++;
print $y; #> 2
</c><P>
it's a copy and I thinks thats saner.<P>
The other point is what a modifier-routine should return.<P>
<i>> 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?</i><P>
There are many possibilities:<P>
- dual use by returning the swap => fault tolerance<P>
- empty return to avoid double use => explicit use, ignore error<P>
- carping if defined wantarray. => runtime warnings<P>
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.<P>
for simplicity I'd simply add an empty return() to the example:<P>
<c>
sub swap {
my ($a, $b) = \(@_);
( $$a, $$b ) = ( $$b, $$a );
return;
}
</c>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-708738">
<p>Cheers Rolf
</div></div>
991197
991217