Skip to content

Commit

Permalink
pp: wide only using filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoBasso committed Sep 11, 2017
1 parent 6450d54 commit 067b542
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 08-abstraction/pp01-wide-only.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#lang htdp/isl
(require 2htdp/image)

;
; PROBLEM:
;
; Use the built in version of filter to design a function called wide-only
; that consumes a list of images and produces a list containing only those
; images that are wider than they are tall.
;


(define I1 (rectangle 20 10 "solid" "red")) ;; Wide.
(define I2 (rectangle 10 20 "solid" "red")) ;; Not wide.
(define I3 (rectangle 30 30 "solid" "green")) ;; Not wide.
(define I4 (rectangle 45 44 "solid" "magenta")) ;; Wide.

;; (listof Image) -> (listof Image)
;; Produce list of images with those for which wide? produce #t.
(check-expect (wide-only empty) empty)
(check-expect (wide-only (list I2 I3)) empty)
(check-expect (wide-only (list I1 I4)) (list I1 I4))
(check-expect (wide-only (list I1 I2 I3 I4)) (list I1 I4))

(define (wide-only loi)
(filter wide? loi))

;; Image -> Boolean
;; Produce #t if img w > img h; #f otherwise.
(define (wide? img)
(> (image-width img) (image-height img)))

0 comments on commit 067b542

Please sign in to comment.