At 7:04 PM +0100 4/23/04, 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.

Well, it depends on what you consider a variable and what you consider a value, though we do have things rather mashed up in spots.


There are three components to all this:

*) The name
*) The container
*) The value

The name is the slot in whatever nametable you're looking in--the global tables or lexical pads or whatever. As far as we're concerned the name is untyped, and you can stick anything in there you want. (Which'd correspond to perl6's rebinding)

The container holds a value, and it is typed. (The container, that is) This is represented (generally) by a PMC. The container is responsible for maintaining type integrity, and Doing The Right Thing when handed a value.

The value is what's inside the PMC. It's often a low-level type (string, int, or number) but in many cases, especially (though not universally) the case of objects, it's another PMC. The value is also typed.

The container determines what happens with get and set actions on the variable.

The value determines what happens with other (add, subtract, multiply... anything overridable) actions on the variable.

In some (really many) cases the container and value are represented by a single entity--that is, the container PMC provides the semantics for the value in the PMC. This is what happens with the PerlScalar (and its subtypes) PMC. These are, for all intents and purposes, value types.

In other cases, the container and the value are represented by two separate entities. The container's still a PMC, but a reference PMC, and it delegates all value entries to the referred-to PMC. These, as you'd expect, are reference types.

There are some interesting issues when mixing value and reference types. Not interesting in the good sense, of course, but, then, when is it ever?

Objects, FWIW, don't *have* to be reference types, and the current ParrotObject scheme actually has them as value types, which needs fixing--they ought to be reference types, so assignment rebinds the container to a new value. OTOH, the semantics there for perl are a bit mushy.

And yes, if anyone's wondering--this muddled split between value and container are likely to bite us in annoying ways in the future, and'll probably go down as Parrot's single biggest design flaw. (Even if we decide to go with cuneiform as the base system for string constants...(
--
Dan


--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to