This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: list-split


> is there another way to split a list than to use list-head and
> list-tail?
> 
> I would like to avoid running twice through the list to the point where
> the list should be splitted.

hi,

pardon me for using elisp in a guile mailing list, but see below for one
solution.  (is this already somewhere?)  you can setcdr the result of
`find-border' to effect a split.

thi

----------

(defun find-border (item list)
  "Find ITEM in LIST, returning border list that looks like (prev ITEM ...).
The \"border\" is between prev and ITEM."
  (if (or (null list)
	  (null (cdr list)))
      nil
    (if (equal item (cadr list))
	list
      (find-border item (cdr list)))))

(find-border 'c '(a b c d e)) ; => (b c d e)