Subject: Re: good lisp style ? From: Erik Naggum <email@example.com> Date: 22 Aug 2002 14:37:12 +0000 Newsgroups: comp.lang.lisp Message-ID: <firstname.lastname@example.org> * Eli Bendersky <email@example.com> This is very rude. People should be able to contact you directly. | I've written the following function to find out all pairs in a list: It looks like a nice Scheme function, which is usually the same as an ugly Common Lisp function. | Although it is functional and short, I'm concerned about the usage of mapcar | in the recursion with append. Is this good style? I'm not talking about | efficiency, because turning a clear function into something ugly, but one | that is a tail-recursion is only good for some applications, not all. There is no tail-recursion here. Just because some recursive call occurs textually at the end does not mean tail-recursion applies. Tail-recursion applies when the caller simply returns the value of the recursive call. In this case, you use the returned value from the recursive call to return a different value. To do this for something as simple as list traversal is really bad style. And what /is/ the point with this useless micro-level "functional style"? What is /important/ in functional style is that you do not destructively modify variable bindings or mutable objects that you have not created yourself. I completely fail to understand this obsession with a limited language just because you have some theory that dictates something. If goto is considered harmful, it leads to convoluted code in many cases. In this case, your code is very complex and hard to read and is only a good example of how functional style should not be taught. | So, what do you think? (defun list-pairs (list) (loop for (head . tail) on list nconc (loop for element in tail collect (list head element)))) "Find" is used in Common Lisp to return an existing object from some sort of database, like `find´, `find-class´, `find-method´, `find-package´, `find-symbol´, etc. -- Erik Naggum, Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.