PasteRack.org
Paste # 40851
2017-10-10 23:14:10

Fork as a new paste.

Paste viewed 174 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.     (begin-for-test
  20.   (check-equal?
  21.    (characters-in-sexp
  22.     (list "alice"
  23.           (list (list "alice" "bob") "carole")
  24.           "dave"))
  25.    23))

=>

begin-for-test: undefined;

 cannot reference an identifier before its definition

  in module: 'm