unbound variable

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
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.
Post Reply
fluffhead
Posts: 1
Joined: Wed Oct 07, 2015 8:12 am

unbound variable

Post by fluffhead » Thu Oct 08, 2015 4:01 am

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)))))

David Mullen
Posts: 78
Joined: Mon Dec 01, 2014 12:29 pm
Contact:

Re: unbound variable

Post by David Mullen » Thu Oct 08, 2015 2:18 pm

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.

Post Reply