Re: Argument Type Checking

2005-05-23 Thread David Storrs


On May 19, 2005, at 10:56 PM, Luke Palmer wrote:


In general, you should probably be declaring your parameters
with uppercase types, [...]

Luke



If so, wouldn't it make sense that 'int' is the boxed type (one less  
keystroke) and 'Int' is the special case?  Optimize for the common  
case, and all that.


Of course, it would go against the consensus of other languages.

--Dks


Re: Argument Type Checking

2005-05-23 Thread Brent 'Dax' Royal-Gordon
David Storrs [EMAIL PROTECTED] wrote:
 If so, wouldn't it make sense that 'int' is the boxed type (one less
 keystroke) and 'Int' is the special case?  Optimize for the common
 case, and all that.

Think of it as being like module names--all-lowercase modules are
special (pragmata), while intercaps modules are normal (modules and
classes).  Similarly, all-lowercase types are special (unboxed), while
intercaps types are normal (boxed classes).

-- 
Brent 'Dax' Royal-Gordon [EMAIL PROTECTED]
Perl and Parrot hacker


Argument Type Checking

2005-05-19 Thread Joshua Gatcomb
All:
I was hoping the following would give me an outright error

sub foo (Int $bar) {
say $bar;
}
foo('hello');

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.

Ok - so could someone set me straight?
What should that code snippet do?  Would it do anything different if
Int had been int?

Cheers,
Joshua Gatcomb
a.k.a. L~R


Re: Argument Type Checking

2005-05-19 Thread Luke Palmer
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).

Luke