I'm a beginner in Lisp and I have this small function which is supposed to print out the head of every list (including lists within lists).
However, when I run the program, it only prints out the very first head, like so:
CL-USER> (first y)
New Y: (1.(2.3))
1
Here is what my program looks like:
Code: Select all
(defun first (aList)
(cond
((not(atom aList))
(format t "~a" (car aList))
(cond
((not(atom(car aList)))
(first(car aList)))
)
)
)
(dolist(item(cdr aList))
(cond
((not(atom item))(first item))
)
)
)
( defvar x ( list 'a 'b 'c 'd ) )
( defvar y ( list ( list 'a 'b ) 'c 'd) )
( defvar z ( list 'a ( list ( list 'b 'c) 'd ) 'e ( list 'f 'g ) ) )
( first x )
( first y )
( first x )
Any tips/advice are welcomed with enormous gratitude.