Re: Idiomatic lisp - loops



On Mar 17, 4:29 am, Vassil Nikolov <vnikolov+use...@xxxxxxxxx> wrote:
On Fri, 16 Mar 2007 16:03:46 -0400, Raffael Cavallaro said:
| * (defun kv-insert (list elt)
| (stable-sort (push elt list) #'string< :key #'car))
^^^^

Apart from any efficiency considerations (this is O(n log n), while
it can be just O(n)), this either needs a (COPY-LIST LIST) or a
comment explaining why the value is expendable. Also, the PUSH is
gratuitous; this is a job for CONS.

You could have O(n) and non-destructiveness with:

(defun kv-insert (list elt)
(merge 'list (copy-seq list) (list elt) #'string< :key #'car))


But you tell me
Over and over and over again, my friend
Ah, you don't believe
We're on the eve
of destruction.


Tayssir

.



Relevant Pages

  • Re: java.util.regex.Pattern.split issue
    ... "For reason that have a lot to do with US Government bureaucracy, we settled on the one issue everyone could agree on, which was weapons of mass destruction." ... ~ Paul Wolfowitz 2003-06, explaining how the Bush administration sold the Iraq war to a gullible public. ...
    (comp.lang.java.programmer)
  • Re: Idiomatic lisp - loops
    ... Apart from any efficiency considerations, ... comment explaining why the value is expendable. ... Also, the PUSH is ... this is a job for CONS. ...
    (comp.lang.lisp)