home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / 3172 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.3 KB  |  38 lines

  1. Newsgroups: comp.lang.lisp
  2. Path: sparky!uunet!spool.mu.edu!torn!nott!bnrgate!bcars267!news
  3. From: emcoop@bnr.ca (hume smith)
  4. Subject: Re: Re: Lucid Lisp complains about this code fragment
  5. Message-ID: <21495.1993Jan5.094839@bcars148>
  6. Sender: news@bnr.ca (usenet)
  7. Nntp-Posting-Host: bcars148
  8. Organization: Bell-Northern Research, Ottawa, Canada
  9. X-Poster: Emacs-NNTP-0.1
  10. References: <1ibjv0INN2pk@early-bird.think.com> <1iat18INNii@MINERVA.CIS.YALE.EDU>
  11. Date: Tue, 5 Jan 1993 14:48:39 GMT
  12. Lines: 24
  13.  
  14. In <1ibjv0INN2pk@early-bird.think.com>, barmar@think.com (Barry Margolin) said:
  15. > In Common
  16. > Lisp, if you don't want TWEAK to be in the global namespace, you should
  17. > write:
  18. > (defun add-noise-to-list-of-numbers (l)
  19. >   (flet ((tweak (x)
  20. >            (+ x
  21. >           (- (* (random 1000) .0001) .05))))
  22. >     (mapcar #'tweak l)))
  23.  
  24. you could also say
  25.  
  26. (defun add-noise-to-list-of-numbers (l)
  27.   (mapcar #'(lambda (x) (+ x (* (random 1000) .0001) -.05)) l))
  28.  
  29. but that may be less efficient - for instance, in XLisp, each time
  30. add-noise-to-list-of-numbers is called a new closure is made.  i think.
  31. --
  32. Hume Smith                      Wenn ich des Tages nicht dreimal
  33. hume.smith@acadiau.ca           mein Schaelchen Coffee trinken darf,
  34. emcoop@bnr.ca                   so werd' ich ju zu meiner Qual
  35.                                 wie ein verdorrtes Ziegenbraetchen.
  36.  
  37.