ad1 TITLE

types and structures

=head1 VERSION

  Maintainer: David Nicol <[EMAIL PROTECTED]>
  Date: 17 Aug 2000
  Version: 1
  Mailing List: [EMAIL PROTECTED]
  Number: 122

=head1 ABSTRACT


We adopt C base types, and C structure syntax.


=head1 DESCRIPTION


the C programming language has a flexible and efficient method
of describing the hardware representation of packed data:  the
C<struct> keyword.

C has several variable types: C<int>, C<float>, and C<char>
are the standard ones, and the "derivative" ones are C<double>, C<short>
and any of the above prefixed with C<unsigned>.

Perl6 will use these types as well as the familiar perl types, which will
all appear in packable defined types as a memory address pointer.

The equivalent of C's C<struct> keyword will be our qs{} structure quoting
operator, which can take the same arguments as a C<struct> block and produce
an equivalent description (a "type definition") of a block of memory, which
is called a "struct." (rather than a "pseudohash" which is something
that acts very similar but has a different internal representation.)

Or we could use the C<struct> keyword as well, so that the C


        struct rec  
        {    
            int a,b,c;    
            float d,e,f;  
        }; 
 
        struct rec r; 


could become, in perl6 


        # $rec =  qs 
        $rec =  struct 
        {    
            int a,b,c;    
            float d,e,f;  
        }; 
 
        my $rec $r_as_a_perl5_ref; 
        my $rec %r_as_a_typed_perl6_hash; 
        my $rec %r; # much tighter interface IMO: let the compiler
                    # worry about what type it is


Perl structs appear in perl syntax as hashes with an ordered set of fixed
keys, returning items of the type as defined in their type definitions: records
of type $rec as defined above allow access to their internals via
associative array syntax.  the C statement C<r.a=5> gets replaced with
a completely functionally equivalent C<$r{a}=5>



=head1 IMPLEMENTATION

Conversion routines are defined between the SV and the base types,
after that it's all bookkeeping.

C<my> appears to be taking over a lot of C<tie>'s duties.

=head1 REFERENCES

http://www.howstuffworks.com/c5.htm for C structures


RFC 61 (v2): Interfaces for linking C objects into perlsubs 
RFC 75 (v1): first class interface definitions

-- 
print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'[EMAIL PROTECTED]',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>

Reply via email to