Subject: Re: clever flatten?
From: Erik Naggum <>
Date: 1996/02/10
Newsgroups: comp.lang.lisp
Message-ID: <>

[Sunil Mishra]

|   Why not write your own function? I don't really understand what the
|   constraints are, perhaps I should give an example of what might work,
|   and you tell me what's wrong with it. I'm also trying to keep memory
|   constraints in mind, and this will result in an ugly function.
|   (defun flatten (tree &aux (output '(())) output-end)
|     (declare (special output-end))
|     (setq output-end output)
|     (flatten-loop tree)
|     (cdr output))
|   (defun flatten-loop (tree)
|     (declare (special output-end))
|     (mapc #'(lambda (tree-el)
|   	    (cond ((listp tree-el)
|   		   (flatten-loop tree-el))
|   		  (t (push tree-el (cdr output-end))
|   		     (setq output-end (cdr output-end)))))
|   	tree))

using a lexical variable in a closure around a `labels' form, you could do
away with the expensive special variable and the separate function.

#<Erik 3032985139133767>
imagine if the buyers of the first PC's with PC-DOS didn't have to upgrade.