On Apr 25, 2004, at 11:01 PM, Piers Cawley wrote:

Jeff Clites <[EMAIL PROTECTED]> writes:

On Apr 23, 2004, at 11:04 AM, Simon Cozens wrote:

[EMAIL PROTECTED] (Jeff Clites) writes:
So what does "$foo = 12" in that context actually mean in Perl6?

Another interesting question is "in Perl 6, are variables typed, values typed, or a little of both?"

It seems that Parrot has been working primarily on the assumption that
it's
values that are typed, and punting variable typing to the IMCC code
generation
layer.

That's my worry--whether we have a problem. (No problem with typed
values, of course.) If variables are typed, _and_ that typing is
lexically scoped, then I think that we don't have a problem, and it can
be handled at the compilation level, by inserting the appropriate type
checks right before each assignment.

Which begs the question of what happens when you do, something like:

    my Dog $spot;
    some_func(\$spot);

    ...

    sub some_func($thing) {
        $$thing = Cat.new();
    }

Yep, that's exactly the case I was thinking about. If the typing is truly lexical, then that shouldn't be an error, but then "my Dog" only guarantees that assignments in the same lexical scope can only put Dogs in $spot, not that $spot will only ever hold a Dog. But that doesn't seem very useful.


It could be argued that our current PerlUndef is all very well, but it
confuses the roles of container and value.

The way other languages typically handle this is via static typing. That is, rather than having a "container object", they do their type checking statically, so for cases like this either some_func() would have to be prototyped as taking a Dog parameter, or you would get an error trying to pass $spot into it.


It feels like we are treading in uncharted territory here, and it could be a bit of cake-and-eat-it-ness. Let's look at what other languages do:

1) C, C++, Java--all statically typed, with enforcement at compile time (and dynamic, checked casts). They don't help much.

2) Smalltalk--completely dynamic; no typing of declarations. Also doesn't help.

3) Objective-C--dynamic typing, but with optional static-style declarations. Sounds promising. But it turns out that these only allow compile-time warnings, but do nothing at runtime. (Type mismatches are only warnings at compile time, and statically-typed variable can be passed without warning into a method typed as taking a generic object reference.) Hmm, still not much help.

I don't (right off) know of any other language which has something "in between" variables and objects. That is, containers. They're feeling a bit artificial.

But this is just off the top of my head.

Maybe the declaration above should translate to something like:

    new $P0, 'PerlScalar';
    $P0.set_type('Dog');
    store_lex '$spot', -1, $P0

Yeah, I've been wondering how a Perl6 declaration is intended to compile. It seems like that should be the most basic thing--the first thing spelled out by parrot. But, it's kind of not clear.


JEff



Reply via email to