Search code examples
lispcommon-lisp

How can I get the part of a list in front of a special element?


With the MEMBER I get the searched element and the rest of the LIST. But how did I get the elements befor the searched element is coming?

(CDR (MEMBER 'DURCH '(ZEIT MAL LAENGE DURCH MASSE MAL ZEIT))); with this I get (MASSE MAL ZEIT)
;But how did I get (ZEIT MAL LAENGE) 


Solution

  • Sometimes these functions are so easy to write and the solution is so transparent to read that there's no point in working out which combination of standard functions will do what you want:

    (defun elts-before (l elt &key (test #'eql))
      (loop for e in l
            until (funcall test e elt)
            collect e))