|Perl Monk, Perl Meditation|
Re^2: RFC: Idiom for named read-write arguments (aliases) instead of using $_ etcby LanX (Canon)
|on Sep 02, 2012 at 12:23 UTC||Need Help??|
> 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) );
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
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 $_ aliases etc.
for simplicity I'd simply add an empty return() to the example: