Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Re: Re: Re: Exegesis 6 - Named binding

by Cine (Friar)
on Jul 31, 2003 at 14:05 UTC ( #279578=note: print w/replies, xml ) Need Help??

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

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;


Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Exegesis 6 - Named binding
by broquaint (Abbot) on Jul 31, 2003 at 14:29 UTC
    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://279578]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-08-18 05:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found