;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname 22.4.2) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
; An empty list has no parts.
; empty : a constant
; empty? : anything -> boolean
; A cons has two parts: first (a string) and rest (a los).
; cons : string los -> nelos
; first : nelos -> string
; rest : nelos -> los
; cons? : anything -> boolean
#|
(define (function-on-nelos L)
; L a nelos
; (first L) a string
; (rest L) a los
; (function-on-los (rest L)) whatever this returns
...)
|#
; A los is either an empty-list or a nelos.
#|
(define (function-on-los L)
; L a los
(cond [(empty-list? L) ...]
[(nelos? L) (function-on-nelos L)]
))
|#
(define english (cons "hello" empty))
(define span-eng (cons "buenos dias" english))
(define heb-span-eng (cons "shalom" span-eng))
(define fhse (cons "bonjour" heb-span-eng))
(define afhse (cons "salaam" fhse))
(define dwarfs (cons "sleepy" (cons "sneezy" (cons "dopey" (cons "doc" (cons "happy" (cons "bashful" (cons "grumpy" empty))))))))


; Worked exercise 22.4.2
; count-strings : los -> number
; count-strings-on-nelos : nelos -> number

(check-expect (count-strings empty) 0)
(check-expect (count-strings english) 1)
(check-expect (count-strings span-eng) 2)
(check-expect (count-strings afhse) 5)
(check-expect (count-strings dwarfs) 7)


; can’t call (count-strings-on-nelos empty)
; because empty isn’t a nelos
(check-expect (count-strings-on-nelos english) 1)
(check-expect (count-strings-on-nelos span-eng) 2)
(check-expect (count-strings-on-nelos afhse) 5)
(check-expect (count-strings-on-nelos dwarfs) 7)

(define (count-strings L)
  ; L a los
  (cond [(empty? L) 0]
        [(cons? L) (count-strings-on-nelos L)]
        ))

(define (count-strings-on-nelos L)
  ; L a nelos
  ; (first L) a string
  ; (rest L) a los
  ; (count-strings (rest L)) a number
  (+ 1 (count-strings (rest L))) )

; Alternative version, all in one function:
#|
(define (count-strings L)
  ; L a los
  (cond [(empty? L) 0]
        [(cons? L)
         ; L a nelos
         ; (first L) a string
         ; (rest L) a los
         ; (count-strings (rest L)) a number
         (+ 1 (count-strings (rest L))) ]
        ))
|#