HaloO,

Luke Palmer wrote:
On 8/3/05, Aankhen <[EMAIL PROTECTED]> wrote:

On 8/3/05, Piers Cawley <[EMAIL PROTECTED]> wrote:

So how *do* I pass an unflattened array to a function with a slurpy parameter?

Good question.  I would have thought that one of the major gains from
turning arrays and hashes into references in scalar context is the
ability to specify an unflattened array or a hash in a sub call
without any special syntax...

I thought that the obsoletion of special syntax stems from the
type system. Piers seems to have the same view. See his example
of &map in his parallel reply.


Well, you can, usually.  This is particularly in the flattening
context.  In most cases, for instance:

    sub foo ($a, $b) { say $a }
    my @a = (1,2,3);
    foo(@a, "3");

Passes the array into $a.  If nothing flattened by default, then you'd
have to say, for example:

    map {...} [EMAIL PROTECTED];

And even:

    for [EMAIL PROTECTED] -> $x {...}

Which I'm not sure people want.

Ups, I thought the for special form would work as follows.

0. the syntax: for expression &block
1. determine (return) type of expression
2. create an iterator for that type
3. Use the iterator until it runs out (is that when it returns undef?)
4. bind the block owner to successive return values of the iterator
   and call the block; if the block is pointy bind its environment as
   well.

With the above

  for @a -> $x {...}  # use Iterator of Array

and

  for [EMAIL PROTECTED] -> $x {...}  # use Iterator of List

produc the same sequence of values in $x but through different
paths in type space. As long as no user defined types are involved,
I dought they are distinguishable at all.

Here's an idea how a sub becomes its own iterator:

   sub foo() does Iterator[foo]
   {
       random;
   }

   for foo() -> $x { say }   # endless loop of random output

How are roles/types composed into Code subtypes?


And the way you pass an array in slurpy context as a single reference
is to backwhack it.  What it comes down to is that either you're
backwhacking things a lot or you're flattening things a lot.  Perl
currently solves it by making the common case the default in each
"zone" of parameters.

I would be interested to hear arguments to the contrary, however.

OK, I gave my 0.02.
--
$TSa.greeting := "HaloO"; # mind the echo!

Reply via email to