From ... From: Erik Naggum Subject: Re: clever flatten? Date: 1996/02/10 Message-ID: <19960210T235219Z@arcana.naggum.no>#1/1 X-Deja-AN: 138839500 references: organization: Naggum Software; +47 2295 0313 newsgroups: comp.lang.lisp [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. # -- imagine if the buyers of the first PC's with PC-DOS didn't have to upgrade.