[% setvar title types and structures %]
Note: these documents may be out of date. Do not use as reference! |
To see what is currently happening visit http://www.perl6.org/
types and structures
Maintainer: David Nicol <perl6rfc@davidnicol.com> Date: 17 Aug 2000 Mailing List: perl6-language@perl.org Number: 122 Version: 1 Status: Developing
We adopt C base types, and C structure syntax.
the C programming language has a flexible and efficient method
of describing the hardware representation of packed data: the
struct
keyword.
C has several variable types: int
, float
, and char
are the standard ones, and the "derivative" ones are double
, short
and any of the above prefixed with 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 struct
keyword will be our qs{} structure quoting operator, which can take the same arguments as a 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 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 r.a=5
gets replaced with
a completely functionally equivalent $r{a}=5
Conversion routines are defined between the SV and the base types, after that it's all bookkeeping.
my
appears to be taking over a lot of tie
's duties.
www.howstuffworks.com for C structures
RFC 61 (v2): Interfaces for linking C objects into perlsubs RFC 75 (v1): first class interface definitions