title: How do I define a Scheme procedure that takes a set (a list of distinct elements) and generates a list of all subsets of the set?
body: <p>First off, I wanted to clarify that I understand that there are similar questions to what I am asking, but I have a very specific output case that I am trying to replicate.</p>
  <p>I am trying to create a Scheme procedure that allows me to take a set and generate a list that shows all possible subsets of that set.</p>
  <p>For example, if I call: <code>(subsets '(a b c ))</code> I should get: <code>'((a b c) (b c) (a c) (c) (a b) (b) (a) ())</code> (in that order specifically)</p>
  <p>Here is what I have so far:</p>
  <pre><code>(define (subsets givenList)
    (if (null? givenList)
        (list null)
        (let ((rest (subsets (cdr givenList))))
          (append rest (map (lambda (x)
                              (cons (car givenList) x))
                            rest)))))
  </code></pre>
  <p>My output for this is: <code>(() (c) (b) (b c) (a) (a c) (a b) (a b c))</code> but that is not the specific output that I am looking for.
  Any suggestions?</p>