• .Re: Alternatives 4

    From Robert L.@21:1/5 to All on Sat Mar 19 01:08:52 2022
    From Paul Graham's "On Lisp".

    (defun before (x y lst &key (test #'eql))
    (and lst
    (let ((first (car lst)))
    (cond ((funcall test y first) nil)
    ((funcall test x first) lst)
    (t (before x y (cdr lst) :test test))))))


    If x is found in lst before y, return the tail starting with x.

    Scheme:

    (define (before x y lst compare)
    (let ((r (member x lst
    (lambda (a b) (or (compare x b) (compare y b))))))
    (and r (not (compare y (car r))) r)))

    (before 4 5 '(0 5 2 4 5 8 9) =)
    ===>
    #f

    (before 4 5 '(0 2 4 5 8 9) =)
    ===>
    (4 5 8 9)

    (before 4 4 '(0 2 4 5 8 9) =)
    ===>
    #f

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)