;; 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-intermediate-lambda-reader.ss" "lang")((modname lect04a) (read-case-sensitive #t) (teachpacks ((lib "world.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "world.ss" "teachpack" "htdp"))))) ;;;; REVIEW: ;;;; Process a list-of-strings. ; A list-of-strings is: ; empty, or ; (cons [string] [list-of-string]) ; examples: empty (cons "ehllo" empty) (cons "aloha" (cons "ehllo" empty)) (define words (list "supercalifragi" "xyz" "ehllo there" "aloha" "ehllo")) (check-expect (filter-longs "a very long string" empty) empty) (check-expect (filter-longs "a very long string" (cons "ehllo" empty)) empty) (check-expect (filter-longs "shrty" (cons "ehllo there" empty)) (cons "ehllo there" empty)) (check-expect (filter-longs "shrty" words) (cons "supercalifragi" (cons "ehllo there" empty))) ; filter-longs : string (list-of string) -> (list-of string) ; (define (filter-longs-v1 ref alos) (cond [(empty? alos) empty] [(cons? alos) (let* {[other-longs (filter-longs-v1 ref (rest alos))] } (if (> (string-length (first alos)) (string-length ref)) (cons (first alos) other-longs) other-longs))])) (define (filter-longs-v2 ref alos) (cond [(empty? alos) empty] [(cons? alos) (let* {[other-longs (filter-longs-v2 ref (rest alos))] } `(,@(if (> (string-length (first alos)) (string-length ref)) `(,(first alos)) '()) ,@other-longs))])) (define filter-longs filter-longs-v1)