Reputation: 78
I keep getting some random errors while trying to call my function that has to return the level of a node from a binary tree.
This is my method
(defun nodeLevel(x index l)
(cond
((null l) nil)
((equal (car l) x) index)
((equal (cadr l) 1) (nodeLevel ( x (+ index 1) (cddr l))))
((equal (cadr l) 2) (nodeLevel ( x (+ index 1) (cddr l))))
(t nodeLevel(x (+ index 1) (cddddr l)))
)
)
This is how i call it
(nodeLevel 'D '0 '(A 2 B 0 C 2 D 0 E 0) )
Upvotes: 0
Views: 226
Reputation: 70287
You have extra parentheses. When you call a function, the entire call goes in parens, but the arguments don't get their own set. You've written
(nodeLevel (x (+ index 1) (cddr l)))
What you probably meant was
(nodeLevel x (+ index 1) (cddr l))
Upvotes: 3