Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Re: Re: Exegesis 6 - Named binding

by broquaint (Abbot)
on Jul 31, 2003 at 13:40 UTC ( #279571=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Exegesis 6 - Named binding
in thread Exegesis 6 - Named binding

Either it is the same as %details{who} = "me", %details{why} = $because, which would make sence because of the unary * operator or it would be the same as %details = ();%details{who} = "me", %details{why} = $because
The reason I suspect it to be behave like the latter is because the flattening behaviour of the * in this context. If we broke it down it might look something like this
%data = << why dunno who them where there which this >>; *%data = ( who => 'me', why => 'because' ); ## which if we expand the splat expands to (I think) %data.kv = ( who => 'me', why => 'because' );
That of course assumes the kv method is lvaluable, but basically it looks like it's assigning all of %data to the RHS. Whereas with named binding it will just be the keys who and why which are bound, otherwise we assume that named binding behaviour is also used in straight assignments, which isn't the case. Again this is all speculation, but I'm hoping it's not too far off, or at least raising some interesting issues. Perhaps in this particular instance the splat is a no-op, or maybe it's a slurp and %data isn't run-over (but that would in turn make the assignment look like a right-to-left pipe ...).


Replies are listed 'Best First'.
Re: Re: Re: Re: Exegesis 6 - Named binding
by Cine (Friar) on Jul 31, 2003 at 14:05 UTC
    I still think its the former.
    Given that
    %data = << why dunno who them where there which this >>;
    I would assume that writing *%data in any context is equivalent to writing
    (why => "dunno", who => "them", where => "there", which => "this")
    So assuming we can use this as an lvalue, an assignment with a list of pairs to this would be the same as taking each pair and assigning it to the value with the specific key. So *%data = *%values should be compiled as
    multi sub infix:=(List of Pair @assign is rw, List of Pair @values) re +turns List of Pair { my %assign := *@assign; for @values { %assign{.key} = .value; } return *%assign; }
    Let me take another example and go back to part(). We could write:
    my $fish = "hest"; ($sheep, $goats, $fish) := part Animal::Cat, @animals;
    So the question here is, is $fish eq "hest" after this, or undef?
    Alternatly we could have written
    my $hest = "hest"; %result := ($sheep, $goats, fish => $hest) := part Animal::Cat, @anima +ls;
    Would that give the same result?

    Update: Forgot the multi keyword
    Update: As broquaint pointed out below, I forgot to use the binding operator as I indented to...
    Update: And the second example is completly bogus, because it would endeed result in a compile time error. Was
    ($sheep, $goats, $fish => "hest") := part Animal::Cat, @animals;

    T I M T O W T D I
      So *%data = *%values should be compiled as ...
      But this would implicitly cast the plain assignment to a binding, which is kind of icky, hence the reason I suspect that %data will be clobbered.
      So the question here is, is $fish eq "hest" after this, or undef?
      I think in the first example $fish will become undef as part doesn't return enough args. Not only that, because of the lack of binding, the LHS will be assigned whatever part returns in the order it is returned. As for the second example, you still have the problem of lack of binding, and you're assigning a pair to nothing, and if the value of a pair is assigned to when a pair is used on the LHS of a simple assign then you might get a compile-time error as you'd be assigning to the constant string "hest".

      Update (WRT to Cine's update): given your definition of := then nothing would happen to $fish as it would have nothing to bind to, and I'm hoping that would be how it is implemented, as binding a variable to nothing doesn't make much sense.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://279571]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-12-04 12:36 GMT
Find Nodes?
    Voting Booth?

    No recent polls found