counting non-numeric characters.
Posted: Fri Sep 27, 2013 1:45 pm
Hello everyone
I am very very new to Lisp. We only had 3 cases so far on lisp. This is out second assignment and i am a bit lost. Any help is appreciated. Please keep in my i have to do everthing with recursion. I can't use any variables except for the parameters.
Write a function called "notnums" that will take a list of arbitrary length and nesting complexity and return the number of non-numbers the list contains, anywhere (i.e., at any level of nesting) in the list. Your function should be able to handle the following input:
* (notnums '(a 9 (5 b) c (d (e 7))))
5
* (notnums '(7 a 8 b c 9 10))
3
* (notnums '(1 (2 (3)) y 5 (x) 9))
2
* (notnums '(a 1 (b 2) ())
2
* (notnums '(* b (a (- 2) c 3) (+ 5))
6
So far i have
(defun notnums (A)
(if (endp A)
0
(1+(notnums (rest A))))
)
This is the function i wrote last week to count the number of atoms in a list. I am trying to modify it for this assignment but i am totally lost.
Thanks.
I am very very new to Lisp. We only had 3 cases so far on lisp. This is out second assignment and i am a bit lost. Any help is appreciated. Please keep in my i have to do everthing with recursion. I can't use any variables except for the parameters.
Write a function called "notnums" that will take a list of arbitrary length and nesting complexity and return the number of non-numbers the list contains, anywhere (i.e., at any level of nesting) in the list. Your function should be able to handle the following input:
* (notnums '(a 9 (5 b) c (d (e 7))))
5
* (notnums '(7 a 8 b c 9 10))
3
* (notnums '(1 (2 (3)) y 5 (x) 9))
2
* (notnums '(a 1 (b 2) ())
2
* (notnums '(* b (a (- 2) c 3) (+ 5))
6
So far i have
(defun notnums (A)
(if (endp A)
0
(1+(notnums (rest A))))
)
This is the function i wrote last week to count the number of atoms in a list. I am trying to modify it for this assignment but i am totally lost.
Thanks.