Reputation: 59
i am new to lisp, and have some troubles with my function:
(setf (symbol-function 'reduce-our)
#'(lambda(new-expression)
(setf expression nil)
(loop while (not (equal new-expression expression)) do
(setf expression new-expression)
(setf new-expression (reduce-once-our expression))
(if (not (equal 'new-expression 'expression))
(format t " ==> ~A Further reductions are impossible.~%"
new-expression)
new-expression))))
(reduce-our '(^ x => x))
This thows next error:
Error: The value ^ is not of the expected type NUMBER.
I thought that lisp is trying to evaluate my input list in while loop, but
(not (equal nil '(^ x => x)))
works just fine, and i am sure that my function does the same check. So. i don't understand where and why happens this error.
Upvotes: 1
Views: 2166
Reputation: 139321
Are you sure that the error happens in this function? You should look at the backtrace.
Additionally:
(setf (symbol-function 'reduce-our)
#'(lambda (new-expression)
...))
is typically written as
(defun reduce-our (new-expression)
...)
Then:
(setf (symbol-function 'reduce-our)
#'(lambda(new-expression)
(setf expression nil) ...
Where is the variable expression
introduced? It is undeclared. Setting the value does not declare a variable.
Then:
while (not (foo ...))
is just
until (foo ...)
And
(if (not (foo)) a b)
is
(if (foo) b a)
Also: improve the indentation. The editor in Lisp will do that for you. It increases readability for you and others.
Upvotes: 3