I want a function that does something like this:
>(function '(1 2 3 4) '(1 2 3 4 5))
#t
When in this case is returning #t because all elements of the first list are contained in the second list. Is there a function that does that without having to worry about order?
Using
memq
works swell on small lists, however since we have hash tables available we might as well use them:Of course you may choose to use immutable ones instead since it's more idiomatic and still a lot faster than
memq
:So as far as I know there is no built in function for this, and I believe the shortest way to define such function would be something like this.
In this case, you aren't comparing the lists as lists, but as sets, so it would make much more sense to use a structure designed to be used that way. Racket provides hash sets in its standard library. This makes the function you're looking for trivial.