Page 1 of 1

unbound variable

Posted: Thu Oct 08, 2015 4:01 am
by fluffhead
I am trying to use two functions 'addtopowerset' and 'powerset' to get the power set of a list.
When I run the powerset function I get an error: unbound variable addtopowerset.
I don't understand why I am getting an error.

Here is my code:

(defun addtopowerset(x pset)
(append (list (list x))
(list (list(car pset)))
(list (cdr pset))
(list pset)
(list (cons x pset))
(list (cons x(list (car pset))))
(list (cons x(list (car (cdr pset)))))
(list (cons x(list (car (reverse pset)))))))

(defun powerset(lst)
(cond
((null lst) nil)
((funcall addtopowerset((car lst)(cdr lst))
(remove-duplicates (powerset(lst)) :test #'equal))
(powerset(cdr lst)))))

Re: unbound variable

Posted: Thu Oct 08, 2015 2:18 pm
by David Mullen
Don't use funcall to call the function directly. And on the remove-duplicates line in the powerset function, the reference to LST shouldn't be in parentheses by itself.