Re: Idiomatic lisp - loops
- From: stamant@xxxxxxxx (Rob St. Amant)
- Date: Fri, 16 Mar 2007 16:00:41 -0400
oversby@xxxxxxxxxxxxxx writes:
I'm trying to write a loop that inserts a dotted key/value pair in
order into a list of ordered
key/value pairs.
So far I've got a recursive solution:
(defun kv-insert (list elt)
(if (null list) '()
(let* ((h (car list))
(k1 (car elt))
(k2 (car h)))
(cond ((string< k1 k2) (cons elt list))
((string= k1 k2) (cons elt (cdr list)))
(t (cons h (kv-insert (cdr list) elt)))))))
I find this pretty comprehensible. Is it by design that if an element
has a key that's string> that the key of the last element of the list,
it's discarded?
(KV-INSERT '((a . 1) (b . 2)) '(c . 3))((a . 1) (b . 2))
.
- Follow-Ups:
- Re: Idiomatic lisp - loops
- From: oversby
- Re: Idiomatic lisp - loops
- References:
- Idiomatic lisp - loops
- From: oversby
- Idiomatic lisp - loops
- Prev by Date: Re: Idiomatic lisp - loops
- Next by Date: Re: Idiomatic lisp - loops
- Previous by thread: Re: Idiomatic lisp - loops
- Next by thread: Re: Idiomatic lisp - loops
- Index(es):
Relevant Pages
|