I want to test for equality amongst lists, but I really only care that the members are the same, not the ordering. Are there any simple operators to check for this?
A rather trivial example
(my-equal? (a b) (b a))
Should return #t.
Obviously, this particular example can easily be done by checking for both lists and then reversing the second and checking again
(or (equal? (a b) (b a)) (equal? (a b) (reverse (b a)))
But is there a way in general? I could have a stab at writing a function but I can only imagine something quite complicated that would do the work. I am guessing this must be a fairly common need and I wonder if scheme has an operator in-built that can do the work here.
I am using mit-scheme 9.0.1
If your implementation has SRFI 1 available, there is lset=
to achieve what you want:
Set operations on lists
If you were using Racket, I would point you to this page, with built-in support for sets.
No, that's not answering your question, I know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With