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

Re: is there a lisp function as follows?



Dan Stanger <Dan.Stanger@evolving.com> writes:
> i have a list for example f '(1 2 3 4 5)
> and i want to split it into 2 parts on a element for example
> (split 3 f) would return 2 values the list (1 2) and (3 4 5)

A non-destructive split is this:

(defun split (item l)
  (let ((rest (member item l)))
    (values (ldiff l rest) rest)
) )

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

                  Bruno


PS: Despite the appearance, this is CLISP. I just modified the prompt:
(defun prompt-string3 () "? ")