title: LISP: How can I test if two lists have the same elements?
body: <p>I want to write a function that takes as parameters two lists and checks if every element in the first one is included in the second ( the order of the elements doesn't matter). The function will also be checking if the two list have the same length (the two list can't have duplicate elements) because if not then the function will return nill/false.</p>
  
  <p>For example: 
  (A B C D E F) and (B E A F D C) have the same elements
  (nil) and (nil) have the same elements</p>
  
  <p>(A B C D E F) and (A B C D E F G) don't have the same elements</p>
  
  <p>The problem is that I know only some basic commands and I can use just those ones. These are almost all the commands that I know: </p>
  
  <pre><code>CAR, CDR, LENGTH, NULL, MEMBER, NOT, AND, OR, NOT, MAPCAR, APPLY, DO, SETQ, LET
  </code></pre>
  
  <p>I wrote the following function up until now, but I don't know how to check for duplicate members and it doesn't work properly for all the lists that I want to check:</p>
  
  <pre><code>(defun same-elem-p (lst1 lst2)
    (cond ((not (null lst1))
           (cond ((member (car lst1) lst2)
                  (same-elem-p (cdr lst1) lst2))
                 (t nil)))
          (t t))) 
  </code></pre>
  
  <p>I hope I explained the problem well enough.</p>