On Tue, Feb 15, 2005 at 03:07:53PM -0600, Rod Adams wrote:
> I see it this way:
> When perl sees a function call, and one of the arguments is a junction, 
> there are three basic options:
> 1) If the junction is wrapped up in some larger container, like a slurpy 
> list, pass it on as is.
> 2) If the function in question is an "outputing" one, throw an exception.
> 3) autothread over the function.
> 
> Consider the following:
> 
> $x = 3|4;
> $y = fun($x);
> sub fun ($x) {
>  warn "enter: fun($x)\n" if $DEBUG;
>  $x + 1;
> }
> 
> Which option from above is in effect? I do not think I left any room for 
> the junction to be enclosed in a larger container, so option #1 is out. 
> That leaves #2 and #3.
> If we autothread, the C<say> only gets a regular scalar, and is happy, so 
> we could get the dreaded repeated outputs.

As you've written things above, C<fun> is autothreaded (your option #3), 
and we'll see two C<warn> output lines if $DEBUG is set.  Whether or 
not the repeated outputs are "dreaded" is a matter of perspective.  
Since the caller has chosen to pass a junction to C<fun>, the caller 
shouldn't be overtly surprised when C<fun> is autothreaded, or that it 
generates multiple output lines.  In fact, I'd be concerned if it didn't.

> If so, has Dan signed off on this?
> If not, how does Patrick resolve whether to autothread or raise exception?

Well, the ultimate answer is that both Dan and Patrick (and others)
will negotiate the exact interface when we get to that point, and 
that we don't seem to be too concerned about it at the moment.
(It could just be that we're both burying our heads in the sand 
hoping it'll be magically "solved" by the other.  :-)

However, in working out these examples I'm fairly comfortable that 
it can be made to work at the Perl 6 compiler level if need be, 
although it will probably be a lot more efficient if we can find a 
way to do it within Parrot.

The how to "resolve whether to autothread or raise exception" question
is moot for the example above, because S09 makes it fairly clear 
that C<fun> will always autothread when it is called, resulting in

    $y = any( fun(3), fun(4) );

The various permutations of C<fun> that I've tried in order to get
things to break haven't broken yet.  But perhaps I'm just not 
sufficiently creative in my attempts to destroy things.

OTOH, what happens with...?

    sub nofun($x is rw) {
        $x += 2;
    }

    $y = 3 | 4;
    nofun($y);

Pm

Reply via email to