At 12:17 PM 8/18/00 -0600, Nathan Torkington wrote:
>Perl6 RFC Librarian writes:
> > There has been a proposed new core function C<want()>. this seems
> > to be generally regarded as a good thing. Fine. If it is implemented
> > we should use it. Offending functions (See RFC 37) should use
> > C<want()> internally to determine what to return i.e; a list or a hash.
>
>This implies that the internals can tell 'hash context' from 'list
>context', which they current cannot.  Because Perl says you put a
>list into a hash:
>
>   $foo = func();        # scalar
>   @foo = func();        # list context
>   %foo = func();        # still list context
>
>I'm very nervous about adding another context (isn't context confusing
>enough already?) without good justification for it.

Well, here's one. (Yep, I'm digging through all my vacation mail)

The core will already know.

Whether this justifies exposing the information's for someone else to 
judge, but the core will know what context something is in. This is for 
optimization reasons. While it's straightforward enough to know that this 
is a hash copy:

   %foo = %bar;

which can be optimized, it's less easy to optimize this:

   sub foo {
     my %hash;
     %hash = (1..10000);
     return %hash;
   }

   %bar = foo();

without return knowing its argument's in list(hash) context. If we know 
that, though, the function return can be quicker than it would be if we 
flatten and reconstitute the hash.


                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to