I apologize in advanced if this has been answered elsewhere, however I can't seem to find a detailed explanation for the issue I am having. This is also my first post on SO...
Basically this is a homework assignment, however, I am not looking for a solution as I have already seen a working solution for this on SO. Frankly I want to implement my own solution so I can learn as I am very interested in getting my head wrapped around lisp / scheme. The idea is to count how many 0's or whatever element / atom are within a list then display / return.
I am sure by looking at the code it will be easy to see what my logic is doing. The issue I am having is incrementing the totalZeros variable each time I recurse. (+ 5 myNum) would certainly add 5 to whatever myNum is. Hence why doesn't (+ 1 totalZeros) seem to be working? When I step through the debugger I can see that the totalZeros variable never changes. It is always zero...
(define (countZeros aList)
(define totalZeros 0)
(define (iterator aList)
(let ((listSize (length aList)))
(if (> listSize 0)
(let ((tempVar (car aList)))
(when (eq? tempVar 0)
(+ 1 totalZeros))
(iterator (cdr aList)))
0)))
(let ((listSize (length aList)))
(when (> listSize 0)
(iterator aList))
(display totalZeros)))