I have two lists, lst1
and lst2
. I want to define a function to check if they share some elements. For example:
(share-some-elements? '(a b) '(a c))
⇒ true(share-some-elements? '(a b) '(d e f))
⇒ false(share-some-elements? '(a b) '(a b d e))
⇒ true
I have an implementation:
(define (share-some-elements? lst1 lst2)
(ormap (λ (x) (member x lst1)) lst2))
Which checks if each element in lst2
is a member of lst1
, and returns true if any of them is.
My questions are:
- What are the other ways of doing this?
- How can I extend this to support any number of lists? ie.
(all-share-some-elements? '(a b) '(a c) '(a d))
⇒ true(all-share-some-elements? '(a b) '(a c) '(b d))
⇒ false(all-share-some-elements? '(a b) '(a c) '(b d a))
⇒ true
There is a similar question on how to do this on two lists in python: Checking if two lists share at least one element, which doesn't quite answer my questions.