New answers tagged


What you are looking for is known in Common Lisp as tailp and is present in Emacs Lisp as cl-tailp: (defun cl-tailp (sublist list) "Return true if SUBLIST is a tail of LIST." (while (and (consp list) (not (eq sublist list))) (setq list (cdr list))) (if (numberp sublist) (equal sublist list) (eq sublist list)))


Use nthcdr: (let* ((x '(4 5)) (y `(1 2 3 . ,x))) (eq (nthcdr (- (length y) (length x)) y) x)) ;; => t (defun foo (list list2) "Return t if LIST ends with LIST2." (eq (nthcdr (- (length list) (length list2)) list) list2)) (let ((x (list 4 5))) (foo (cons 1 (cons 2 x)) x)) ;; => t ;; it is ok if LIST is shorter than ...


I think xuchunyang's is the correct answer, as seq-intersection is a generic function that can work on any built-in or user-defined sequence type, accepts a custom equality predicate, and perfectly conveys the intention, which is to determine whether two sequences intersect. All these benefits come with some performance overhead, of course, but the ...


You can use seq-intersection, it is documented in its docstring and (elisp) Sequence Functions: seq-intersection is a compiled Lisp function in `seq.el'. (seq-intersection SEQUENCE1 SEQUENCE2 &optional TESTFN) Return a list of the elements that appear in both SEQUENCE1 and SEQUENCE2. Equality is defined by TESTFN if non-nil or by `equal' if ...

Top 50 recent answers are included