23 lines
1.0 KiB
Plaintext
23 lines
1.0 KiB
Plaintext
;; 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-intermediate-lambda-reader.ss" "lang")((modname main) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
|
|
; foo: (bar: A → A) → (A → A)
|
|
(define (foo bar)
|
|
(local [(define (baz buzz)
|
|
(bar (bar buzz)))] baz))
|
|
|
|
(check-expect ((foo add1) 1) 3)
|
|
|
|
; goodies: (good?: A → Boolean, l: [A]) → [Index]
|
|
; Returns a list of indices considered "good."
|
|
(define (goodies good? l)
|
|
(local [; goodies/help: (good?: A → Boolean, l :[A], i: Int, a: [Index]) → [Index]
|
|
(define (goodies/help l i a)
|
|
(cond [(empty? l) (reverse a)]
|
|
[(good? (first l)) (goodies/help (rest l) (add1 i) (cons i a))]
|
|
[else (goodies/help (rest l) (add1 i) a)]))]
|
|
(goodies/help l 0 '())))
|
|
|
|
(check-expect (goodies even? '(1 2 3 4 5)) '(1 3))
|
|
(check-expect (goodies even? '()) '())
|