develooper Front page | perl.perl6.language | Postings from December 2001

Re: Apropos of nothing...

Thread Previous | Thread Next
From:
Damian Conway
Date:
December 15, 2001 20:55
Subject:
Re: Apropos of nothing...
Message ID:
200112160455.PAA15622@indy05.csse.monash.edu.au

Piers posed the following puzzles:
 
   > @ary[0] = foo()   # scalar

Yes.

   > @ary[1,2] = foo() # list context

Yes.


   > @bar = 1;
   > @ary[@bar] = foo() # ? probably list or maybe scalar...

List. With an explicit array as index, it's definitely a (one-element) slice.

   
   > @bar = (1,2);
   > @ary[@bar] = foo() # list?

List. Same reason as previous.


   > @bar is constant = 1;
   > @ary[@bar] = foo() # We know at compile time there's only one thing in
   >                    # @bar. Does that mean foo() is in a scalar context
   >                    # now?

List. Same reason as previous.


   > sub a_scalar { 1 };
   > sub an_array { my @a = (1,2) }
   > sub context { wantarray ? (1,2) : 1 }

sub context { want 'LIST' ?? (1,2) :: 1 }


   > @ary[a_scalar()] = foo() # ???
   > @ary[an_array()] = foo() # ???
   > @ary[context()]  = foo() # ???

I'm not sure Larry has decided how this will be handled yet.
If forced to guess, I'd guess the square brackets will impose
scalar context on &a_scalar, &an_array, and &context, making
the indexing operation a scalar look-up (not a slice), so each 
call to &foo is in scalar context.


   > At around this point, Dan was heard to say 'Mommy, make the bad man go
   > away!'

Please don't scare the new Perl serf, Piers.


   > And, just for laughs:
   > 
   > $ref = [1,2];
   > @ary[$ref] = foo();      # probably a syntax error

Unlikely. Scalar context, I'd expect
(though Larry would have to confirm that).


Damian

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About