CISC108 Lecture Notes - Lecture 9: Complex Instruction Set Computing, Animage
Document Summary
;; examples: (define lon1 empty) ;; the empty list (define lon2 (cons 3 lon1)) ;; the list: 3 (define lon3 (cons 45 lon2)) ;; the list 45, 3. ;; lon-fun : list-of-number -> (define (lon-fun lon) (cond [(empty? lon) ] ;; lon lon : any list of numbers. ;; produces: list of squares of those numbers (check-expect (square-all lon1) empty) (check-expect (square-all lon2) (cons 9 empty)) (check-expect (square-all lon3) (cons (sqr 45) (cons 9 empty))) (define (square-all lon) (cond [(empty? lon) empty] [(cons? lon) (cons (sqr (first lon)) (square-all (rest lon)))])) (require 2htdp/image) ;; examples: (define loi1 (cons (square 50 solid red) (cons (square 3 solid blue) empty))) ;; area: image -> number (define (area an-image) (* (image-height an-image) (image-width an-image))) ;; loi loi : any list of images. ;; produces: list of sizes of those images (check-expect (sizes loi1) (cons (* 50 50) (cons (* 3 3) empty))) (define (sizes loi) (cond [(empty? loi) empty]