From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed1.bredband.com!bredband!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: good lisp style ? Date: 22 Aug 2002 14:37:12 +0000 Organization: Naggum Software, Oslo, Norway Lines: 46 Message-ID: <3239015832424650@naggum.no> References: <3D64D77F.FDA2059D@in.the.newsgroup> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: maud.ifi.uio.no 1030027033 11209 129.240.64.16 (22 Aug 2002 14:37:13 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 22 Aug 2002 14:37:13 GMT Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.lisp:38512 * Eli Bendersky 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.