Reputation: 31597
I tried to define this function that takes multiple integers and keeps those that are different from 0. It does not work, apparently, the recursive call (filter $?tail)
does not match with the parameter list. Can this be done in CLIPS?
(deffunction filter (?head $?tail)
(if (= (length $?tail) 0) then
(if (!= ?head 0) then (return ?head))
(return $?tail))
(if (= ?head 0) then
(return (filter $?tail)))
(bind $?result ?head (filter $?tail))
(return $?result)
)
Upvotes: 0
Views: 597
Reputation: 1599
The function filter is declared with 2 parameters filter(?head $?tail)
but you are calling it with only one (filter $?tail)
Is the recursion needed? This problem can be solved easily with the function delete-member$
:
(delete-member$ $?list 0)
Example:
CLIPS> (delete-member$ (create$ 6 7 0 8 0 7) 0)
(6 7 8 7)
CLIPS>
Upvotes: 0