Guided Practice 6.4: S-expressions

Design the following functions:

;; characters-in : Sos -> Number
;; characters-in-loss : LoSS -> Number
;; RETURNS: the total number of characters in the strings
;; EXAMPLE/TEST:
(begin-for-test
  (check-equal?
   (characters-in
    (list "alice" 
          (list (list "alice" "bob") "carole")
          "dave"))
   23)

;; subst : SoS String String -> SoS
;; GIVEN: a SoS and two strings, old and new
;; RETURNS: a sos just like the given one, except that
;; all instances of old are changed to new.
;; EXAMPLE/TEST:
(begin-for-test
  (check-equal? 
    (subst
      (list "alice" 
        (list (list "alice" "bob") "dave") 
        "eve"
        "bob")
      "bob"
      "ted")
    (list "alice" 
      (list (list "alice" "ted") "dave") 
      "eve"
      "ted")))

[ANSWER]


Last modified: Mon Sep 26 13:45:59 Eastern Daylight Time 2016