hossman has asked for the wisdom of the Perl Monks concerning the following question:

I finally got arround to reading Exegesis 6, and for the most part it's all cool and everything, and makes a lot of sense, but then something jumps out at me in the section "You Are What You Eat -- Not!"...

...Perl 6 allows us to specify both the storage type of a variable (i.e. what kinds of values it can contain) and the implementation class of the variable (i.e. how the variable itself is actually implemented).

The is keyword indicates what a particular container (variable, parameter, etc.) is — namely, how it's implemented and how it operates. Saying:

sub bark(@dogs is Pack) {...}

specifies that, although the @dogs parameter looks like an Array, it's actually implemented by the Pack class instead.

Now, the part about using "is" to indicate the acctual implimentation of a container makes sense to me for variables -- except when those variables are sub parameters, because parameters (by default) are just aliases to the arguments. It seems like the only way you should be able to say "@dog is SomeClass" is if you also say "is copy" so that perl creates @dog as an instance of SomeClass and copies all of the items in the argument container into @dog (using whatever STORE method is defined in SomeClass.

Does that sub bark(@dogs is Pack) seem wrong to anybody else?

(The only way i can think of that it might work, is if the is SomeClass attribute of a parameter indicates that an exception should be thrown if something other then SomeClass is passed in -- but that seems like a non-standard use of the "is" keyword)

Replies are listed 'Best First'.
Re: Ex6: Using "is" on aliased sub parameters?
by bbfu (Curate) on Aug 05, 2003 at 19:37 UTC

    Makes sense to me.

    (The only way i can think of that it might work, is if the is SomeClass attribute of a parameter indicates that an exception should be thrown if something other then SomeClass is passed in -- but that seems like a non-standard use of the "is" keyword)

    That's pretty much how it works (as I understand it), but it's only a side-effect of the fact that you're giving the parameter a type. That is, it's standard in the same way that:

    my SomeClass $foo; # a.k.a. my $foo is SomeClass; my SomeOtherClass $bar = stuff(); $foo = $bar; # compile-time exception

    producing an exception is standard when SomeOtherClass is not a child of SomeClass. It just has the benefit of letting us make the compiler enforce some of the "correctness" of the passed values.

    Again, this is just how I understand it from the Exegesis and Apocolypse. I could be horribly wrong, of course. :)

    Update: Re: The sub parameter being an alias. Am I correct in remembering that one of the Apocolypses indicated that the properties (such as type; or it may have just been the type) are properties of the name we give the variables, and not the actual value/container? This is why the fact that the parameter is just an alias doesn't bother me.

    bbfu
    Black flowers blossom
    Fearless on my breath