On Monday 15 July 2002 11:22 pm, Deborah Ariel Pickett wrote: > Besides, does > $hashref = some_function_returning_a_hash() > make $hashref simply refer to the result of the function, or does it > make $hashref refer to a hash containing a *copy* of the result of the > function? If Perl6 is going to do fancy things with functions returning > lvalues, which looks like the case, those two things aren't necessarily > the same thing.
I don't think scalar context can ever make copies of aggregate data. Here's a little experiment. sub func { return a => 10; # returns a single pair; not a list or a hash } $foo = func(); # $foo is a PAIR ref, not a hash ref $foo = { func() } # $foo is a CODE ref $foo = { *func() } # $foo is still a CODE ref, I assume? $foo = %{ func() } # die "Not a HASH reference" $foo = hash func(); # This should work > Or, saying the same thing another way, does this: > $href = %hash; > which I presume will be legal Perl6, mean the same as this Perl5: > $href = \%hash; #A It always means A according to some apocalypse. my %hash = (key => "bar"); sub foo { return %hash; } $ref = foo(); # $ref = \%hash %copy = foo(); # %copy = { %hash } %alias := foo(); # \%alias == \%hash %$ref = foo(); # ($ref = {}) = %hash > or this Perl5: > $href = { %hash }; #B The ways I can think to do that are: %$href = %hash; # autovivify $href = {}, then copy $href = hash %hash; # Perhaps * flattening is required? > and how would I say each of A and B in Perl6 unambiguously? I don't much like the effects of using %$foo as an lvalue. Having a context sigil clobber the value doesn't seem very perl5ish. Perhaps I have my blinders on and don't see where Perl5 does that. > Automatic referencing and dereferencing is all well and good, and it > appears that it's here to stay in Perl6 (it's been in most Apocalypses), > but I don't think anyone's actually sat down yet to thrash out exactly > under what circumstances it happens. I think the rule of auto-hashifying only when an explicit pair is found is gonna be hard to swallow. I still have my vote on %() as a hash constructor in addition to {}. :) Ashley Winters -- When you do the community's rewrite, try to remember most of us are idiots.