PasteRack.org
Paste # 52460
2017-10-10 23:17:05

Fork as a new paste.

Paste viewed 76 times.


Embed:

  1. #lang racket
  2.  
  3. ;; characters-in-sexp  : Sexp -> Number
  4. ;; characters-in-sexps : SexpList -> Number
  5. ;; RETURNS: the total number of characters in the strings in the given
  6. ;; Sexp or SexpList
  7. ;; EXAMPLE/TEST:
  8.  
  9.  (define (characters-in-sexp s)
  10.   (cond
  11.     [(string? s) (string-length s)]
  12.     [else (characters-in-sexps s)]))
  13.  
  14.   (define (characters-in-sexps s)
  15.     (cond
  16.       [(empty? s) 0]
  17.       [(+ (characters-in-sexp s) (characters-in-sexps (rest s)))]))
  18.  
  19.     (println
  20.    (characters-in-sexp
  21.     (list "alice"
  22.           (list (list "alice" "bob") "carole")
  23.           "dave")))

=>