From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d74d61525ce986e9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-22 05:30:55 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!skynet.be!skynet.be!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Marius Amado Alves Newsgroups: comp.lang.ada Subject: Re: Implementing Memorize Date: Wed, 22 Oct 2003 12:29:08 +0000 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1066825791 71898 80.67.180.195 (22 Oct 2003 12:29:51 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 22 Oct 2003 12:29:51 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: X-Mailer: Ximian Evolution 1.4.5 X-OriginalArrivalTime: 22 Oct 2003 12:29:03.0521 (UTC) FILETIME=[140AD110:01C39898] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:1412 Date: 2003-10-22T12:29:08+00:00 On Wed, 2003-10-22 at 11:33, Lutz Donnerhacke wrote: > * Lutz Donnerhacke wrote: > > Calculating Fibbonacci numbers recursivly is easy but braindead. Languages > > with access to the symbol table at execution time are able to change the the > > reccuring call with a memorize wrapper which returns already computed values > > immediatly instead of recalculating them. In the referenced article I wrote > > an C-Implementation of such a wrapper. Now I'm looking for a more elegant > > version in Ada. So your problem is generating the Fibonaci number of a given natural N. I would not use recursive calls here because call stack space is usually shorter than the range of naturals. I would use increments in a loop. And I think I would use a precomputed table of values for N = 100, 200... (say). And it is clear that Fib (Natural'Last) is much bigger than Natural'Last so I would look for the M such that Fib (M) <= Natural'Last and Fib (M + 1) > Natural'Last and then constrain the input type to 0 .. M. Or else use a big numbers package for the output type. > ... Took a look at your code. I think you're failing to set the Valid component.