On 5/19/05, Joshua Gatcomb <[EMAIL PROTECTED]> wrote:
> All:
> I was hoping the following would give me an outright error
> sub foo (Int $bar) {
>     say $bar;
> }
> foo('hello');

Fortunately you are right.

> I seem to recall, probably incorrectly, that one of the differences
> with int, Int, and no type declaration at all is that one would
> happily autoconvert for you, 1 would autoconvert but forget it ever
> happened, and 1 would be an outright failure.

Uhh... I don't think that's a distinction between int and Int.  Or
you're thinking about "autoconvert" the wrong way.  int just means
that it's implemented with a parrot I register, so if you increment it
too many times it will roll over instead of turning into a bigint. 
But if you pass an int into a sub expecting an Int, Perl will happily
box up your int and make it into a full type.  On the other hand, if
you pass an Int into a sub expecting int, it will probably whine at
you a little bit, because you're losing properties and possibly
first-class data (if your Int was a bigint).

In this case it wouldn't be different if you declared the parameter
int.  In general, you should probably be declaring your parameters
with uppercase types, and if you need the speed, the way to do it is
to inline (which can respect the lowercasehood of variables).


Reply via email to