Reputation: 1207
I am currently struggling with this function that is meant to filter values.
(defun filter (operator val sequence)
(if (funcall operator val (first sequence))
(filter (function operator) val (rest sequence))
(cons (list (first sequence))
(filter (function operator) val (rest sequence)))))
Calling this function with
(filter (function >) 6 '(5 6))
Gives
*** Eval error *** Symbol's function definition is void: operator
This snippet works fine though.
(defun example (lhs rhs operator)
(funcall operator lhs rhs))
(example 4 5 (function +))
=> 9
My guess is that the function forgets which function it was called with originally but I have no idea what is wrong, some pointers in the right direction would be much appreciated!
Upvotes: 1
Views: 141
Reputation: 85767
The error message Symbol's function definition is void: operator
refers to this line:
(filter (function operator) val (rest sequence))
You're trying to access a function called operator
, which doesn't exist because operator
is just a function parameter (a normal variable). (This parameter happens to be bound to a function value, but that doesn't matter.)
This should fix it:
(filter operator val (rest sequence))
Upvotes: 3