"Joe Gottman" <[EMAIL PROTECTED]> writes:

>    Will it be possible in perl6 to overload multis on the const-ness of a
> parameter, like C++ does?  For instance,
>
>    multi getX(Foo $self:) returns Int {...} #const version
>    multi getX(Foo $self: is rw) returns Int is rw {...} #non-const version
>
>    If getX were called on a const Foo object then the first getX would be
> called, and if it were called on a non-const Foo object the second one would
> be.

Speaking of multis and constants, Greg McCarroll wondered on IRC if
this would work:

    multi factorial (Int 0) { 1 }
    multi factorial (Int $n) { $n * factorial($n-1) }

Disregarding the fact that you should really write that as:


    sub factorial (Int $n) {
        my multi tail_fac ($result, 0) { $result }
        my multi tail_fac ($result, $n) { tail_fac( $result * $n, $n - 1 ) }
        tail_fac(1, $n);
    }

(Assuming you want to do it recursively that is...)


-- 
Piers

Reply via email to