Reputation: 43
I was wondering how to count the number of elements For example, counting the number of elements in (list 'a 'b 'c' 'd). Thank you!
Upvotes: 1
Views: 13799
Reputation: 417
If you want to do see how you can do it yourself recursively, one way to do it is this:
(define (my-length lst)
(if (empty? lst)
0
(+ 1 (my-length (rest lst)))))
Upvotes: 1
Reputation: 295
Based on racket documentation :
http://docs.racket-lang.org/reference/pairs.html#%28def.%28%28quote.~23~25kernel%29._length%29%29
(length lst) Returns the number of elements in lst.
Upvotes: 6