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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no 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 08:00:30 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!cycny01.gnilink.net!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny03.gnilink.net.POSTED!53ab2750!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: Subject: Re: Implementing Memorize X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: Date: Wed, 22 Oct 2003 15:00:30 GMT NNTP-Posting-Host: 141.154.54.155 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny03.gnilink.net 1066834830 141.154.54.155 (Wed, 22 Oct 2003 11:00:30 EDT) NNTP-Posting-Date: Wed, 22 Oct 2003 11:00:30 EDT Xref: archiver1.google.com comp.lang.ada:1424 Date: 2003-10-22T15:00:30+00:00 List-Id: "Lutz Donnerhacke" wrote in message news:slrnbpch9n.oa.lutz@taranis.iks-jena.de... > In order to implement a generic memorize, I tried the following > (see for the context) > > generic > with function Callback (n : Natural) return Natural; > function Action (n : Natural) return Natural; > > function Action (n : Natural) return Natural is > begin > case n is > when 0 | 1 => return 1; > when others => return Callback(n-1) + Callback(n-2); > end case; > end Action; > > function Fib_Direct is new Action (Fib_Direct); -- won't compile I can see why this doesn't compile: you are using Fib_Direct to define Fib_Direct. We could avoid this bit of circularity by declaring another function to serve as the generic parameter, then implement this other function as a simple call to the generic instantiation, as follows: function Fib_Indirect(n : Natural) return Natural; function Fib_Direct is new Action( Fib_Indirect ); function Fib_Indirect(n : Natural) return Natural is begin return Fib_Direct(n); end Fib_Indirect; Of course, for the particular problem you posted, I would not use generics at all. This implementation works quite nicely: function Fib_Direct(n : Natural) return Natural is begin case n is when 0 | 1 => return 1; when others => return Fib_Direct(n-1) + Fib_Direct(n-2); end case; end Fib_Direct;