Path: utzoo!yunexus!ists!jarvis.csri.toronto.edu!mailrus!hellgate.utah.edu!cdr.utah.edu!moore From: moore%cdr.utah.edu@cs.utah.edu (Tim Moore) Newsgroups: comp.lang.lisp Subject: Re: code Message-ID: <1989Nov18.182509.14667@hellgate.utah.edu> Date: 19 Nov 89 01:25:08 GMT Article-I.D.: hellgate.1989Nov18.182509.14667 References: <464@cs.columbia.edu> <1989Nov18.152356.7962@hellgate.utah.edu> Organization: University of Utah CS Dept Lines: 24 In article <1989Nov18.152356.7962@hellgate.utah.edu> moore%cdr.utah.edu@cs.utah.edu (Tim Moore) writes: > >If you want persistant lexical bindings you probably should be using closures >instead. Here's you fibonacci example, rewritten to use a closure: > >(defun fib-setup (&key ((:n-2 pn-2) 0) ((:n-1 pn-1) 1)) > #'(lambda (&key n-2 n-1) > (and n-2 (setq pn-2 n2)) > (and n-1 (setq pn-1 n1)) > (psetq pn-2 pn-1 pn-1 (+ pn-2 pn-1)) > pn-1)) Oops! That should be: (defun fib-setup (&key ((:n-2 pn-2) 0) ((:n-1 pn-1) 1)) #'(lambda (&key n-2 n-1) (and n-2 (setq pn-2 n-2)) (and n-1 (setq pn-1 n-1)) (psetq pn-2 pn-1 pn-1 (+ pn-2 pn-1)) pn-1)) Tim Moore moore@cs.utah.edu {bellcore,hplabs}!utah-cs!moore "Ah, youth. Ah, statute of limitations." -John Waters