LISP AGAIN
2 messages in this thread
This is a follow-up to my previous LISP question regarding the minimum value
in a list. I think I can get that value – but now I need to be able to delete
that value from the list, any ideas ? – What I am trying to do is to
re-organize the values in a list in sequential order – starting with the
smallest value and proceeding to the highest value. Am I re-inventing the
wheel ?
Dave Maki
David,
Here's what you want:
(defun remove (item alist)
(if (member item alist)
(append
(reverse (cdr (member item (reverse alist))))
(cdr (member item alist))
)
alist
)
However, why not just insert your list items in sorted order:
(defun insert (item alist)
(cond
((or (null alist) (< item (car alist)))
(cons item alist))
((= item (car alist))
alist)
((cons (car alist) (insert item (cdr alist))))
)
)
Just start with a null list, then
(setq yourlist (insert newitem yourlist))
for each one. Phil Kreiker, Looking Glass Microproducts