Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) 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

$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


In reply to Re^2: RFC: Idiom for named read-write arguments (aliases) instead of using $_[0] etc by LanX
in thread RFC: Idiom for named read-write arguments (aliases) instead of using $_[0] etc by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2015-07-04 21:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls