From d59896a3a3288052b5a04e22164c3801a60c058a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 3 May 2016 22:15:08 -0700 Subject: [PATCH] minor refactorings --- beautiful-racket/br/demo/txtadv/expander.rkt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/beautiful-racket/br/demo/txtadv/expander.rkt b/beautiful-racket/br/demo/txtadv/expander.rkt index bb63d08..af11bf1 100644 --- a/beautiful-racket/br/demo/txtadv/expander.rkt +++ b/beautiful-racket/br/demo/txtadv/expander.rkt @@ -239,11 +239,9 @@ (<= 1 (length input) 2)) (let* ([verb (car input)] [response - (cond - [(= 2 (length input)) - (handle-transitive-verb verb (cadr input))] - [(= 1 (length input)) - (handle-intransitive-verb verb)])] + (case (length input) + [(2) (handle-transitive-verb verb (cadr input))] + [(1) (handle-intransitive-verb verb)])] [result (response)]) (cond [(place? result) @@ -278,11 +276,10 @@ (and (verb-transitive? verb) (cond - [(ormap (λ (thing) - (and (eq? (thing-name thing) obj) - thing)) - (append (place-things current-place) - player-inventory)) + [(for/first ([thing (in-list (append (place-things current-place) + player-inventory))] + #:when (eq? (thing-name thing) obj)) + thing) => (λ (thing) (or (find-verb verb-in (thing-actions thing)) (λ () @@ -296,7 +293,7 @@ ;; Show what the player is carrying: (define (show-inventory) (printf "You have") - (if (null? player-inventory) + (if (zero? (length player-inventory)) (printf " no items.") (for-each (λ (thing) (printf "\n a ~a" (thing-name thing)))