[Parrot-users] A length() runtime written in NQP
Jay Emerson
jayemerson at gmail.com
Wed Jul 6 15:22:10 UTC 2011
I'm trying to write a function which would behave something like (pseudo-code):
a = 0
b = (1, 2, 3)
length(a) # Returns 1
length(b) # Returns 3
Now, in a squaak-like language, I think a is a scalar and b is a pmc.
I tried the following:
sub length(*@args) {
my @arg := @args[0];
my $len := @arg;
pir::return($len);
}
Now, in interactive mode, length(b) seems to work (in terms of what is
printed), but the actual result
of length(b) seems to be the argument, b, itself. So there is a print
generated which evaluates
@arg to the length (perl-like), but the actual thing returned is the
pmc. I tried perl-like
$#arg to try to get the length, but that didn't work.
It would also be nice to know what causes the printing in squaak;
> a = 5
5
>
I'd like to "turn this off" and expect some modification to the
assignment method in Actions.pm is needed,
but don't see how to accomplish this.
Thanks,
Jay
--
John W. Emerson (Jay)
Associate Professor of Statistics
Department of Statistics
Yale University
http://www.stat.yale.edu/~jay
More information about the Parrot-users
mailing list