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)))))
unbound variable
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.
-
- Posts: 78
- Joined: Mon Dec 01, 2014 12:29 pm
- Contact:
Re: unbound variable
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.