home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / 2093 < prev    next >
Encoding:
Text File  |  1992-07-24  |  1.6 KB  |  42 lines

  1. Path: sparky!uunet!mcsun!Germany.EU.net!ira.uka.de!chx400!sicsun!disuns2!disuns2.epfl.ch!simon
  2. From: simon@lia.di.epfl.ch (Simon Leinen)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Advice on recursion?
  5. Message-ID: <SIMON.92Jul24122911@liasg1.epfl.ch>
  6. Date: 24 Jul 92 10:29:11 GMT
  7. References: <1992Jul23.192749.129@cerberus.ulaval.ca>
  8. Sender: news@disuns2.epfl.ch
  9. Organization: DI-LIA -- Ecole Polytechnique Federale de Lausanne
  10. Lines: 27
  11. Nntp-Posting-Host: liasg1.epfl.ch
  12. In-reply-to: vachon@chicoutimi.gel.ulaval.ca's message of 23 Jul 92 19:27:49 GMT
  13. X-Md4-Signature: b93cb3623b02d0860da2c86c88916b7e
  14.  
  15. In article <1992Jul23.192749.129@cerberus.ulaval.ca>
  16. vachon@chicoutimi.gel.ulaval.ca (Pierre Vachon) writes:
  17.  
  18.      Are there disadvantages to using 'labels' like this:
  19.  
  20.       (defun foo (arg)
  21.     (let ((...))
  22.  
  23.       (labels ((recursive (arg1 arg2)
  24.                 (body)))
  25.         (recursive 'foo 'bar))))
  26.  
  27. This is exactly what I use most often.  The main drawback I see is
  28. that you typically cannot trace the internal function if it
  29. misbehaves.  Maybe some Lisps have an extension that permits (TRACE
  30. (LABELS FOO RECURSIVE)) or something, but I don't know any.
  31.  
  32. Decent Lisp compilers of course optimize a tail recursion to a loop.
  33. Good compilers also integrate the internal function into the caller,
  34. in which case the LABELS version is always as efficient as an explicit
  35. loop construct (at least Lucid and CMU CL can claim this, I believe).
  36.  
  37. So in the cases where the recursive version seems more natural (which
  38. depends a lot on the observer), there is no reason to sacrifice
  39. clarity for speed anymore, if you assume a state-of-the-art compiler.
  40. -- 
  41. Simon.
  42.