PasteRack.org
Paste # 32633
2017-10-10 23:13:05

Fork as a new paste.

Paste viewed 161 times.


Embed:

#lang racket

;; characters-in-sexp  : Sexp -> Number
;; characters-in-sexps : SexpList -> Number
;; RETURNS: the total number of characters in the strings in the given
;; Sexp or SexpList
;; EXAMPLE/TEST:

 (define (characters-in-sexp s)
  (cond
    [(string? s) (string-length s)]
    [else (characters-in-sexps s)]))
  
  (define (characters-in-sexps s)
    (cond
      [(empty? s) 0]
      [(+ (characters-in-sexp s) (characters-in-sexps (rest s)))]))
    
    (begin-for-test
  (check-equal?
   (characters-in-sexp
    (list "alice" 
          (list (list "alice" "bob") "carole")
          "dave"))
   23)
 

=>

prog:19:4: read: expected a `)' to close `('
  possible cause: indentation suggests a missing `)' before line 20
  context...:
   /home/pasterack/racket68/collects/syntax/module-reader.rkt:186:17: body
   /home/pasterack/racket68/collects/syntax/module-reader.rkt:183:2: wrap-internal
   /home/pasterack/racket68/collects/racket/../syntax/module-reader.rkt:65:9: lang:read-syntax
   /home/pasterack/racket68/share/pkgs/scribble-lib/scribble/private/manual-code.rkt:112:0: get-tokens
   /home/pasterack/racket68/share/pkgs/scribble-lib/scribble/private/manual-code.rkt:56:0: typeset-code15
   /home/pasterack/pasterack/tmp/32633/32633code.scrbl: [running body]
   loop
   ...cket/cmdline.rkt:179:51
   /home/pasterack/racket68/share/pkgs/scribble-lib/scribble/run.rkt: [running body]