list-split pasted by siiky on Thu May 16 10:53:51 2024

(define (list-split lst x)
  (define (list-split% lst x ret elem)
    (if (null? lst)
        (if (null? elem)
            ret
            (cons (reverse elem) ret))
        (if (equal? x (car lst))
            (list-split% (cdr lst) x (cons (reverse elem) ret) '())
            (list-split% (cdr lst) x ret (cons (car lst) elem)))))
  (reverse (filter (o not null?) (list-split% lst x '() '()))))

Since we are using srfi-1... added by mario-goulart on Thu May 16 11:12:55 2024

(define (list-split lst x #!optional (comp equal?))
  (let ((pos (list-index (lambda (elt) (comp elt x)) lst)))
    (unless pos
      (error 'list-split "Element not in the list" x lst))
    (receive (left right)
        (split-at lst pos)
      (list left (cdr right)))))