Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion A6: overloading multis on constness of parameters

Newsgroups: perl.perl6.language
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.perl.org
Return-Path: <pdcaw...@bofh.org.uk>
Mailing-List: contact perl6-language-h...@perl.org; run by ezmlm
Delivered-To: mailing list perl6-langu...@perl.org
Delivered-To: perl6-langu...@perl.org
X-Authentication-Warning: TiBook.bofh.org.uk: pdcawley set sender to pdcaw...@bofh.org.uk using -f
To: "Joe Gottman" <jgott...@carolina.rr.com>
Cc: "Perl6" <perl6-langu...@perl.org>
Subject: Re: A6: overloading multis on constness of parameters
Date: Thu, 13 Mar 2003 00:15:42 +0000
In-Reply-To: <004d01c2e83b$47b8c0c0$cf6e1918@carolina.rr.com> ("Joe Gottman"'s message of "Tue, 11 Mar 2003 21:01:21 -0500")
Message-ID: <m2u1e886kx.fsf@TiBook.bofh.org.uk>
User-Agent: Gnus/5.090016 (Oort Gnus v0.16) XEmacs/21.5 (brussels sprouts, darwin)
References: <004d01c2e83b$47b8c0c0$cf6e1918@carolina.rr.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-SMTPD: qpsmtpd/0.21-dev, http://develooper.com/code/qpsmtpd/
X-Spam-Check-By: one.develooper.com
X-Spam-Status: No, hits=-2.4 required=7.0 tests=CARRIAGE_RETURNS,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_03_05,USER_AGENT,USER_AGENT_GNUS_UA,X_AUTH_WARNING version=2.44
X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/
Approved: n...@nntp.perl.org
From: pdcaw...@bofh.org.uk (Piers Cawley)
Lines: 32

"Joe Gottman" <jgott...@carolina.rr.com> 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