Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!shelby!neon!news From: rit@killdeer.Stanford.EDU (Jean-Francois Rit) Newsgroups: comp.lang.lisp Subject: flet, a question of style? Message-ID: <1990Aug4.001913.22597@Neon.Stanford.EDU> Date: 4 Aug 90 00:19:13 GMT Sender: news@Neon.Stanford.EDU (USENET News System) Reply-To: rit@killdeer.Stanford.EDU (Jean-Francois Rit) Organization: Robotics Lab. Stanford University Lines: 41 What is a good use of flet? The way I see it, the advantages of flet over an external defun are: - cleanliness of code: the local function is defined right where it is only needed and that is made clear to the reader. - Use of lexical context: when the flet is defined in the right place, a lot of local variables need not be passed to the function. The cons are: - It is local (obviously) - It is more expensive. Here is the heart of my question. Is it really so, does it always have to be? My own limited tests gave me a bit less than 10% in disfavor of flet. I also noticed that an flet form in the do clause of a MIT loop is not compiled. (defun with-flet (n m) (let ((x (make-array 1))) (flet ((titi-flet (p) (loop for i from 0 to n do (setf (aref x 0) (+ p i))))) (loop for j from 0 to m do (titi-flet j))))) (defun without-flet (n m) (let ((x (make-array 1))) (loop for j from 0 to m do (titi j n x)))) (defun titi (p n x) (loop for i from 0 to n do (setf (aref x 0) (+ p i)))) Anyhow, do the programming masters use or advocate the use of flet like they would for , say, let?