develooper Front page | | Postings from August 2000

Re: 122 (v1): types and structures

Michael Fowler
August 24, 2000 16:06
Re: 122 (v1): types and structures
Message ID:
[I am not subscribed to the perl6-language-data list, so I would appreciate
it if responses are CC'd to me.]

On Thu, Aug 24, 2000 at 08:45:50AM -0700, Nathan Wiger wrote:
> How is RFC 122 different from RFC 15? Seems like they accomplish a
> similar thing but RFC 15 is a much more Perlish approach. The problem
> with RFC 15 is that it's titled "stronger typing though tie", which
> implies that tie should be used, but it probably shouldn't be.

RFC 15 more than just implies tie should be used for strong type checking. 
The point of the RFC was to allow those who wish for strong typing to use
it, while interfering in the least possible way with others who don't.

I don't see why tie shouldn't be used for strong type checking.  Your
snippet of code

>         use types;
>         $rec = struct {
>             int($a, $b, $c);
>             float($d, $e, $f);
>         };

would work just fine if types automatically exports int() and float(), which
would look something like:

    sub int   { foreach (@_) { tie($_, "types::int")   } }
    sub float { foreach (@_) { tie($_, "types::float") } }

This will obviously not work with hashes or arrays, unless a subroutine can
get at its original arguments uncollapsed (which is entirely possible, if
some RFCs are adopted).

From an input standpoint (verifying a value is allowed, e.g. you can't
int($x) and then say $x = 4.1) this would work fine.  One might run into
problems when interfacing with a lower-level language, but that can probably
be easily solved by converting the SV* into an appropriate type (e.g. a
types::int-tied SV* converted into int before being passed to a C function).

By the way, int() is not a good name, for what should be readily apparent
reasons; I prefer integer().

Programmer, System Administrator
-- Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About