;; 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 week7_w) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "htdp"))))) ;; make-secret : nat -> (nat -> symbol) ;; makes up a secret and then returns ;; a function that lets you guess the secret (define (make-secret n) (local [(define secret (random n))] (lambda (guess) (cond [(= guess secret) 'yes] [else 'no])))) ;; guess-secret : (nat -> symbol) -> nat (define (guess-secret secret) (guess-helper secret 0)) ;; guess-helper : (number -> symbol) number -> number ;; guesses a secret, assuming that the secret is at least n (define (guess-helper secret n) (cond [(symbol=? (secret n) 'yes) n] [else (guess-helper secret (+ n 1))])) (define sec3 (make-secret 100000)) (guess-secret sec3)