Hi, I'm incredibly new to Lisp and I've got to write a program that calculates the depth of an expression. Here's what I've got so far:
(DEFUN depth (L)
(IF (NIL L) 0)
(IF (NIL (SECOND L)) 0)
(IF (ATOM (SECOND L)) (1+depth(CDR L)))
)
What it's supposed to do is return 0 if the list L is empty or only has one atom (the two base cases) and if not, return 1 plus the depth of the CDR of the list. Whenever I try to test the code, I get an illegal argument error. I tried to test the function with(depth (1 2 4))
and get this: Error: Illegal argument in functor position: 1 in (1 2 4).
Any help would be much appreciated.