Hi I am having a little trouble testing a list to see if the list contains only strings. I am reading the documentation 2.3(Iterations, and Recursion) + 3.12 (Conditionals) and I can't quite seem to work lists in the way that I want.
I'm trying to keep it as simple as possible,
(define (strings-only? lst)
[cond
[(empty? lst) true]
[else (string?(first lst))
(string?(rest lst))]])
What I assume this does is first checks the list (lst) to see if it's empty. Then it checks the first variable of the list to see if its a string, then checks the rest. When I put in
(define a (list "This" "that"))
It pops back that the test is false. I feel like the problem is with the way I'm trying to iterate through the list with first/rest. Any thoughts would be appreciated.
Aucun commentaire:
Enregistrer un commentaire