[Parrot-users] Parrot + R

Jay Emerson jayemerson at gmail.com
Wed Jul 6 16:00:00 UTC 2011


I tried this:

sub length(*@args) {
    my @arg := @args[0];
    my @len;
    @len[0] := + at arg;
    return @len;
}

This (I think) results in a pmc object containing the length, rather
than a scalar float object, am I right?  This solves the problem with
the print() in my last email.  This is a good learning process,
understanding these little detours.

Jay

On Wed, Jul 6, 2011 at 11:52 AM, Jay Emerson <jayemerson at gmail.com> wrote:
> Thanks!  May be a real step in the right direction.  !_)  Now, though:
>
> b = length(a)
> print(a)
>
> generates the error "elements() not implemented in class 'Float'",
> where the print function is:
>
> sub print(*@args) {
>    my $arg := @args[0];
>    pir::say(pir::join(' ', $arg));
>    pir::return();
> }
>
> So is this telling me that in the print function, the length is a
> scalar of type float, and that this isn't an acceptable type for use
> with pir::join?
>
>
>
>
> 2011/7/6 Tadeusz Sośnierz <tadzikes at gmail.com>:
>> On Wednesday 06 of July 2011 17:36:37 Jay Emerson wrote:
>>> Like: in NQP, how do I find the length of @anarray ?  Does the answer
>>> to this require knowledge of the type of the array (fixed versus
>>> resizable, integer versus float)?
>> Hello Jay. You can use prefix:<+> in nqp, like the following:
>>    > my @a; @a.push(1); @a.push(2); say(+ at a)
>>    2
>> That numifies the array, which becomes the number of elements.
>> No need to specify a type or anything, arrays in nqp are pretty self-aware :)
>>
>> --
>> Tadeusz Sośnierz
>>
>
>
>
> --
> John W. Emerson (Jay)
> Associate Professor of Statistics
> Department of Statistics
> Yale University
> http://www.stat.yale.edu/~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