Welcome to the CHICKEN Scheme pasting service

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)))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the procedure that returns the car of a car?
Visually impaired? Let me spell it for you (wav file) download WAV