[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is there a lisp function as follows?



(defun split (item l)
  
  "Returns two values - the list l up to the first occurence of item, and
   the rest of l after and including item.  Split is destructive."
  
  (let ( (rest (member item l)) )
    (setf (nthcdr (- (length l) (length rest)) l) nil)
    (values l rest)))



? (setf l '(1 2 3 4 5))
(1 2 3 4 5)
? (split 3 l)
(1 2)
(3 4 5)
? l
(1 2)
? (setf l '(1 2 3 4 5))
(1 2 3 4 5)
? (split 7 l)
(1 2 3 4 5)
NIL
? 


Erann Gat
gat@jpl.nasa.gov