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...)

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.

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.

sub suchthat(Any $v, &predicate) { predicate($v) ?? $v !! undef }

So now:

$a = 1|2|3|4|5
say suchthat($a, odd)
>>> 1|3|5

$b = 1&2&3&4&5
say suchthat($a, odd)
>>> 1&3&5

And in the poker example:

@p = 1|11, 2, 1|11;
@d = 1|11, 3, 1|11;

$pv = suchthat([+] @p, {$_ <= 21})
$dv = suchthat([+] @d, {$_ <= 21})

if $pv and (!$dv or $pv > $dv) { say 'p wins!' };

        - MtnViewMark

Mark Lentczner
http://www.ozonehouse.com/mark/
m...@glyphic.com



Reply via email to