;; The first three lines of this file were inserted by DrRacket. 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 lists) (read-case-sensitive #t) (teachpacks ((lib "universe.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "universe.ss" "teachpack" "2htdp"))))) (define L1 (cons 42 (cons 69 (cons 613 empty)))) (first L1) (rest L1) (first (rest L1)) (rest (rest L1)) ;; a list-of-strings is (cons string list-of-strings) ;; or empty (define GROCERIES (cons "milk" (cons "cookies" (cons "bread" empty)))) (define YOUR-GROCERIES (cons "milk" (cons "cookies" (cons "tea" (cons "bread" empty))))) ;; len: list-of-strings -> number ;; consumes list and produces the number of items in the list (define (len alos) (cond [(empty? alos) 0] [else (+ 1 (len (rest alos)))])) (check-expect (len GROCERIES) 3) (check-expect (len empty) 0) ;; contains-tea? list-of-strings -> boolean ;; consumes list and determines if it has "tea" in it (define (contains-tea? alos) (cond [(empty? alos) false] [else (or (string=? "tea" (first alos)) (contains-tea? (rest alos)))])) (check-expect (contains-tea? GROCERIES) false) (check-expect (contains-tea? YOUR-GROCERIES) true) ;; template for functions over list-of-strings ;;(define (los-template a-los) ;; (cond [(empty? a-los) ...] ;; [else ... (first a-los) ;; ... (rest a-los) ...]))