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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,f0f0d8e1d84a1aae,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!h23g2000vbc.googlegroups.com!not-for-mail From: jpwoodruff Newsgroups: comp.lang.ada Subject: Idiom for tail recursion? Date: Sun, 31 May 2009 14:04:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: <814eff38-3e01-4f70-aeb7-48a1ae651dfc@h23g2000vbc.googlegroups.com> NNTP-Posting-Host: 24.8.140.151 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1243803874 18363 127.0.0.1 (31 May 2009 21:04:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 31 May 2009 21:04:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h23g2000vbc.googlegroups.com; posting-host=24.8.140.151; posting-account=eLk0BgoAAAA-yA75xm1L7heSizMaESVg User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6142 Date: 2009-05-31T14:04:34-07:00 List-Id: To entertain myself, I'm making a program that implements the DEVS specification for discrete event simulation. The book I'm studying describes a reference implementation in Scheme. The program proceeds by passing a series of messages among objects that are instances of only a couple class hierarchies. The messages cycle among the objects in (fairly convoluted) cycles of mutually recursive dispatching calls. Simulation time advances as the program traverses the outermost cycles of activation. In scheme, the functions are tail-recursive - the last call of each of the respective mutually recursive procedures does the recurse. This paradigm is crystal clear in that language and the implementation doesn't grow the stack. But in Ada it appears that I'm going to have a stack of calls that won't return. I guess the program will quit running when I raise an exception for that purpose. Or maybe it won't halt, who knows :-}. I most definitely do not see a transform to an iterative algorithm. So the question: what idiom comes fairly close to the flavor of the tail-recursion and won't blow stack? John