Em Dom, 2009-03-29 às 22:57 -0700, Mark Lentczner escreveu:
> What I see here is that there is a tendency to want to think about,
> and operate on, the eigenstates as a Set, but this seems to destroy
> the "single value" impersonation of the Junction.
> Further, if one ever calls .!eigenstates() on a Junction, then you
> have really bollox'd your code up, as then this code fails if the
> value you thought was a Junction happens to be, actually, just a
> single value! (Unless .!eigenstates() is defined on Object, and
> returns a Set of self...)
++
This is the most important semantic deadlock, thanks for putting it so
clearly.
> I think what is needed is a "single value" threshing function, which
> can be applied to, well, single values. Such a function would take a
> value and a predicate, and if the predicate applied to the value is
> true, returns the value, else it returns... nothing. If such a
> function were applied to a Junction, then the result would be a
> Junction of just those those eigenstates that "passed" this function.
> The "nothings" would not end up contributing to the Junction.
Well, that can be thought as grep.
my @i = 1|11, 9, 1|11;
my @j = 6,9,6;
my $a = [+] @i;
my $b = [+] @j;
my $va = $a.grep: * <= 21;
my $vb = $b.grep: * <= 21;
if ($va && $vb) {
if ($va > $vb) {
# a wins
} elsif ($vb > $va) {
# b wins
} else {
# draw
}
}
If we have grep as a method in Any, the call to grep will autothread,
returning a junction of the values, so, as $a is any(11, 21, 31), $va
would be any(11,21,()), which should collapse as expected.
> Now, I'm not sure I know how to return "nothing" in Perl6, but I'll
> guess that undef can serve the purpose, since I can't think of a
> useful use of undef as part of a Junction.
Well, you return nothing simply by calling "return;" it will produce an
empty capture, which could be seen simply as ().
daniel