On Fri, Jun 23, 2006 at 06:18:51PM +0300, Markus Laire wrote:
> multi sub talk (String $msg1, String $msg2) { say "$msg1 $msg2" }
> multi sub talk (String $msg, Int $times) { say $msg x $times; }
> multi sub talk (String $msg, Num $times) { say "Please use an integer"; }
> multi sub talk (String $msg, Range $r) { say "$_: $msg" for $r }
> 
> talk("Hello", "World"); # String and String
> talk("Hi", 2); # String and Int
> talk("Test", 1.23); # String and Num
> talk("Hello", 3..5); # String and Range
> talk(123, 3); # Int and Int
> 
> I think that would print
>  Hello World
>  HiHi
>  Please use an integer
>  3: Hello
>  4: Hello
>  5: Hello
>  123123123
> 
> In last example, there is no exact match for parameters (Int, Int), so
> IMHO perl6 would select the closest match, which in this case is
> (String, Int) because Int can be converted to String.

An alternate interpretation would be that the last one is actually a compile-
time error because none of the sigs match (Int,Int) and for a call to
work with 2 Int parameters, you'd need to be explicit:

talk(~123,3);

But I'm not sure which way perl6 actually leans.  

Though it seems to me that automatic type conversion by the compiler is
a way to get yourself in trouble.  Not that perl shouldn't let the
programmer get himself in trouble, but this seems like one of those
things that should require asking to turn on rather than asking to
turn off.

my two cents,

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to