Hi

I've sent these files to Dan, but still didn't any answer. Meanwhile,
somebody can have some more time than he too look into these files.

They are POD's documenting PMC's (Arrays, PerlArrays and PerlHashes).
If you think they are interesting, put them on the doc dir for parrot,
and I'll do some more POD's for new PMC's.

Meanwhile, I'll try to learn some more parrot.

Best regards,
Alberto Simões
-- 
Alberto Manuel B. Simoes
Departamento de Informática - Universidade do Minho
http://alfarrabio.di.uminho.pt/~albie - http://numexp.sf.net
# -*- cperl -*-

=head1 Perl Array PMC

=head2 Creation

To create a new PMC with a PerlArray object:

   new P0, .PerlArray

=head2 Size

Perl array can be initialized to the empty array using

   set P0, 0

and we can check the PerlArray size, putting the value on register
C<I0> using

   set I0, P0

We can create an empty array but with some chunks allocated. This method is the
same to initialize the array to the empty array. In this case, use the number of
chunks you want:

   set P0,5

=head2 Index access

You can set the value 3 on the position 5 from the array using

   set P0, 5, 3

In the same mood, to access the element use

   set I0, P0, 5

As in Perl, negative indexes are seen as indexes from the end of the
array. This way, you can set the last element of the array to the
value 7 using

   set P0, -1, 7

Note that you can put on each chunk a integer, number, string or
PMC. You must have caution when accessing the value, as you should use
the correct type of register.

=head2 Using keys of different types

You can use string or numbers as indexes for the array if they
represent an integer.  So, these are correct instructions:

   set P0, 5.0, 3
   set P0, "10", 6
   set P0, 15, 9

which sets values on positions 5, 10 and 15.

=head2 Abbreviating

It is possible to abbreviate, or simplify the notation using a perlish
way of accessing elements on the array:

   set P0[5], 3     # P0[5] = 3

   set I0, 5
   set I1, P0[I0]   # I1 = P0[5] = 3

=head2 Trueness

You can get a boolean value from a Perl Array.  If you use an empty
Perl Array in a condition, it will return false (no elements).

        new P0, .PerlArray
        if P0, JUMP         # This will never succeed

After adding a value (for example, P0[0] = 1), it will return a true
value (the Perl Array has elements).

        new P0, .PerlArray
        set P0, 0, 1
        if P0, JUMP         # This will succeed

If you don't add a value, but force a size different from zero the the
array, it will return a true value:

        new P0, .PerlArray
        set P0, 1
        if P0, JUMP         # This will succeed

=cut




# -*- perl -*-

=head1 Perl Hash PMC

=head2 Creation

As with other PMC's, create the hash with

    new P0, .PerlHash

=head2 Storing Elements

To store elements on the hash use

    new P0, .PerlHash
    set P0, "key", "value"

Note that you can use register in the same way:

    new P0, .PerlHash
    set S0, "one"
    set S1, "two"
    set P0, S0, 1     # $P0{one} = 1
    set P0, S1, 2     # $P0{two} = 2

=head2 Abbreviating

It is possible to abbreviate, or simplify the notation using a perlish
way of accessing elements on the hash:

   set P0[5], 3     # $P0{5} = 3

   set I0, 5
   set I1, P0[I0]   # I1 = $P0{5} = 3

=head2 Size of the Hash

To get the number of keys (size of the array) use

    set I0, P0

where P0 is the Perl Hash PMC and I0 the register where to store the
size.

=cut
__END__

=head1 Array PMC

Implementation of a generic array. Each cell can contain any atomic
data.

=head2 Creation

To create a PMC array use

   new P0, .Array

And P0 will contain your array object.

=head2 Size

You can check a PMC array size using

   set I0, P0

and I0 will contain the array size;

=head2 Access Elements

You can create an empty element using

   set P0, 1

which changes the array size, but not stores any value.

To store the value C<-7> on first position, use

   set P0, 0, -7

Notice that array indexes are the second parameter, and start at 0 as
Perl or C.

To get the value from that position, use

   set I0, P0, 0

where the last parameter is the index we are using.

=head2 Data Types

Note that all examples are storing integers (so, using C<In>
registers). To use strings or numbers, you should use registers
C<Sn> and C<Nn>.

=cut


Reply via email to