On Sat, Feb 12, 2005 at 01:03:26AM -0600, Rod Adams wrote:
> I also find the following incredibly disturbing:
> >perl6 -e "$x = 'cat'|'dog'; say $x;"
> dog
> cat
> 
> Getting iterated executions of a statement without explicitly iterating 
> it bothers me greatly. I work heavily in databases, where updating or 
> inserting twice with one call can be fatal to data consistency.

FWIW, I also find it incredibly disturbing.  Although I don't have
to deal with it yet in the side-effect-free FP6, I think one way
to solve this is for the "say" to return a junction of IO actions.

Normally a statement-separating semicolon "launches" IO actions
obtained by evaluating the left-side statement, then moves on to
handle the right-side statement.  For example, "say" will have
this signature:

    multi sub say ([EMAIL PROTECTED]) returns IO of Bool { ... }

The "IO of Bool" can only be launched by a toplevel sequencing,
obtained by the destructive assignment:

    my $a = say("xxx"); # output "xxx\n" on screen; $a is now a Bool
    say("yyy");         # output "yyy\n" on screen; retval is discarded

but not via the nondestructive binding:

    my $a := say("xxx");    # nothing outputted, $a is "IO of Bool"
    $a;                     # this runs the action.

Your example then becomes:

    $x := 'cat'|'dog';      # $x is now Junction of String
    say $x;                 # Junction of (IO of String)

the toplevel sequencing only handles "IO of ..." types, so the junction
above will not print anything.  Instead it may raise a warning of "using a
Junction in a void context", or something equally ominous.

(Haskell users will notice the equivalency of toplevel sequencing with
monadic I/O).

> So, if we are not having Sets, how exactly does one tell if what they 
> are holding is a single value scalar, or a multi-value junction?

$x.isa("Junction").

> Can a junction hold values of completely different types, or just 
> different values of the same type?

A junction typed as "Junction of Scalar" (as is the default) can
probably hold pretty much anything.  There is also "Junction of Class"
and the amazingly weird "Junction of Any".

> If evaluation of one value of a junction causes an error, is $! now a 
> junction as well?

I don't have answers for this one.

Thanks,
/Autrijus/

Attachment: pgpptSG36y9vx.pgp
Description: PGP signature

Reply via email to