I’ve been struggling with this question for the past few hours, scoured the internet for help, and I still can’t seem to figure it out.
The question is simple:
Write a recursive program (in lisp) that takes a list and returns the number of ‘a atoms in the list.
From the research I’ve done, it seems like LISP has an implicit counter in it, where if you just do (+ 1) it will keep track? Is this off?
Please help, I’m pretty frustrated…
The idea here is not to use a global variable, but instead to keep the count “in the stack”.
Here’s a Scheme solution. I’m sure you’ll be able to convert this to whatever Lisp dialect you’re using:
If that’s not DRY enough for you, here’s a more condensed version: