Luke Palmer wrote:
sub foo($x) {
if ($x != 4) {
print "Not four\n";
}
if ($x == 4) {
print "Four\n";
}
}
sub oof($x) {
if ($x != 4) {
print "Not four\n";
}
else {
print "Four\n";
}
}
If given 3 | 4, foo would print "Not Four\nFour\n", while oof would
print "Not four\n".
Maybe not. We're still pondering the interactions of subroutines and
junctive arguments. There are two possibilities (naturally ;-):
1. Passing a junction as a subroutine argument calls the
subroutine (in parallel, perhaps in separate threads)
with each value of the junction, then juncts the results
(in which case both C<foo> and C<oof> print both strings).
2. Junctions are just passed in as any other scalar argument.
(in which case what Luke suggested is correct).
The reason that 1) might be a better semantics is that it makes
something like:
sub longest_common_substr($a, $b) {
my $substrs_a = substr $a, any(0,$a.end), any(0,$a.length);
my $substrs_b = substr $a, any(0,$a.end), any(0,$a.length);
my $common = $substrs_a == $substrs_b;
return $common >= any($common.states);
}
work correctly.
That is, we generally want C<f($a|$b|$c)> to produce C<f($a)|f($b)|f($c)>.
In those cases where the junction *should* be passed into the subroutine
(primarilyboolean predicates, I suspect), that would have to be marked
explicitly:
sub even ($x is junctive) { # Allow C<even> to work on junctions too
return $x % 2 == 0;
}
Note that C<even> would work for regular scalars too, since they can be
considered a degenerate case of a disjunction (or of a conjunction or
abjunction, for that matter).
I don't know how much this would come up in practice, but I do see it
as an issue. The question is: are junctions more useful if they do
or don't collapse upon examination?
I'm fairly solidly convinced that it's better if they don't.
Damian