Article View: comp.lang.logo
Article #6Re: too many levels recursion- MSWlogo.2.1
From: Brian Harvey
Date: Sun, 01 Nov 1992 02:01
Date: Sun, 01 Nov 1992 02:01
40 lines
2352 bytes
2352 bytes
IZZYOB9@MVS.OAC.UCLA.EDU (Bob Stocks) writes: > I've just written a small >spiral procedure to teach my 6th grade students about loops >and it works fine on the apple IIc at school using appleLogo >but when I run it on MSW Logo I get a message saying "too many >levels of recursion." Apple Logo, like every (I think) commercial Logo implementation, uses a technique called tail call elimination (sometimes called "tail recursion elimination" but that's just a special case). This means that if the very last thing your procedure does is to call another procedure, Logo treats that final procedure call as if it were a GOTO instead. This is important because ordinarily every procedure call requires Logo to save away some information, such as the context to which the called procedure should return. But if procedure A calls B, and if B calls C as its very last act, then instead of C returning to B and then B immediately returning to A, Logo can set things up so that C returns directly to A. (This is a simplified story leaving out a *lot* of details, but it's good enough to make the point.) MSWLogo, like its ancestor LSRHS Logo, doesn't know about tail call elimination. The WHILE procedure that you're calling is implemented tail recursively, something like this: TO WHILE :CONDITION :ACTION IF NOT (RUN :CONDITION) [STOP] RUN :ACTION WHILE :CONDITION :ACTION END Since the call to WHILE is the last thing in WHILE, tail call elimination can carry out the specified action any number of times without having to save any extra information each time. But in a Logo without tail call elimination, each time through the WHILE requires saving some context, and eventually you run out of memory. P.S. Berkeley Logo does know about tail call elimination, so you might try that. It doesn't have the fancy Windows bells and whistles, though.
Technical Details
Message-ID:
<1cvdp4INNl5v@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!yale.edu!spool.mu.edu!agate!anarres.CS.Berkeley.EDU!bhReferences:
<19921031144805IZZYOB9@MVS.OAC.UCLA.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!yale.edu!spool.mu.edu!agate!anarres.CS.Berkeley.EDU!bh From: bh@anarres.CS.Berkeley.EDU (Brian Harvey) Newsgroups: comp.lang.logo Subject: Re: too many levels recursion- MSWlogo.2.1 Date: 1 Nov 1992 02:01:08 GMT Organization: University of California, Berkeley Lines: 40 Message-ID: <1cvdp4INNl5v@agate.berkeley.edu> References: <19921031144805IZZYOB9@MVS.OAC.UCLA.EDU> NNTP-Posting-Host: anarres.cs.berkeley.edu