Hi,
Back at OSCON, under the influence of beer, I agreed to take a crack at
implementing junctions in Perl 6 on Parrot. I've started working on
making good on that. I've not got any of this in a state where I'm happy
to send in a patch for people to play with, and it's my first time
hacking on the Perl 6 compiler so I won't check it in without review
first. However, with the very, very basic stuff I have implemented I can
now do things like:
my $x = 1 | 2 | 3; $x = $x * 5; my @y = $x.values; say @y;
5 10 15
my $x = 1 | 2 | 3; if $x == 2 { say "true" } else { say "false" }
true
my $x = 1 & 2 & 3; if $x == 2 { say "true" } else { say "false" }
false
if none(1,2,3) == 4 { say "true" } else { say "false" }
true
if none(1,2,3) == 3 { say "true" } else { say "false" }
false
I've run up against a Parrot issue that is kinda getting in the way.
Basically, all comparison operations have been implemented in Parrot
using the cmp function rather than having separate MMD methods for less
than and greater than. I've got equality to work by tweaking the == and
!= operators to not use cmp, but rather the is_equal_num MMD method.
However, the current state of affairs stops me implementing <, >, <= and >=.
The problem is that cmp can't give sensible answers with regard to
junctions. For example, what should it return for all(1,2) cmp 2?
They're not all less than 2, so it can't return -1. Clearly 1 isn't the
right answer, and clearly 0 isn't either.
The only sensible thing to do is to thread the junction through cmp
outside of the implementation of the operator and get a junction of
results - and as far as I understand that is what it's spec'd to do in
Perl 6. It'd be desirable for operations that really do support
junctions and can give back a boolean result to be able to do so,
however, without going through constructing an intermediate junction and
then having to analyse that. Thus I think we need <, <=, > and >= MMD
methods (plus the string variants) rather than relying on cmp for
everything. Maybe we can write some default implementations of these
that fall back on cmp, though, since in the majority of cases just
having cmp is fine.
Thoughts?
Thanks,
Jonathan