Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Simply because a pair has the same key value as one of the variables on the left side, it is assigned to that?
I believe this is so we have behaviour orthogonal to that of named sub/method/etc parameters. As you can pass named parameters into a sub and it will do the right thing e.g
sub func(Int $this, Str $that) { ... } func(279544, "a string"); ## or with named parameters func(that => 'thing you do', this => 0xdeadbeef);
So we don't need to maintain order of the arguments we pass in as perl6 will do the right thing and alias the arguments to correct positions in the parameter list. Now when we do named binding it's pretty much the same thing, but without the sub call e.g
($this, $that) := ( 279544, 'a string' ); ## or with named parameters ($this, $that) := (that => 'thing you do', this => 0xdeadbeef);
Also notice that both the parameter list and the named binding alias their arguments as well as putting the arguments in the right place.
Then simply because of my naming of the variables I assign to, I would get the reverse result?
If you're performing a simple assign, then yes, the reversing of the variables that are being to assigned to will get the reverse data (same as perl5). But of course if you bind instead and the return is a list of pairs then it should DTRT e.g
sub &part(Selector $is_sheep, *@data) { ## body here return *%herd; } ($goat, $sheep) = part Animal::Cat, @animals;
Now regardless of the order of the LHS, the values should be bound correctly as the flattening of %herd produces a list of pairs.
makes no sence to me either, unless a colon is missing as in
Indeed, because without the binding colon you don't get the named binding behaviour. I'll speculate that it'll empty out %details and then assign it whatever is on the RHS.
HTH

_________
broquaint

Disclaimer: IANAP6DG (I Am Not A Perl6 Design Guru ;)


In reply to Re: Exegesis 6 - Named binding by broquaint
in thread Exegesis 6 - Named binding by Cine

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-11-27 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?