diff options
author | siddharth <s@ricketyspace.net> | 2021-10-09 21:04:26 -0400 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-10-09 21:04:26 -0400 |
commit | a8c783445fff7a3f301dbe352ac51895cab9e979 (patch) | |
tree | 5b37fd7b2ea3423795b755db3e23864c19bc69b7 /ex | |
parent | a20522dc1688d7719026db84a4c7863990868d4a (diff) |
ex: do ex 2.47
Diffstat (limited to 'ex')
-rw-r--r-- | ex/2/47.rkt | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ex/2/47.rkt b/ex/2/47.rkt new file mode 100644 index 0000000..1d2abd3 --- /dev/null +++ b/ex/2/47.rkt @@ -0,0 +1,57 @@ +;;;; License: CC0-1.0 + +#lang racket + +(provide make-frame + make-frame-alt) + +(require "46.rkt") + + +;;; frame functions + +(define (make-frame origin edge1 edge2) + (list origin edge1 edge2)) + +(define (origin-frame frame) + (car frame)) + +(define (edge1-frame frame) + (car (cdr frame))) + +(define (edge2-frame frame) + (car (cdr (cdr frame)))) + + +;;; alternative frame functions + +(define (make-frame-alt origin edge1 edge2) + (cons origin (cons edge1 edge2))) + +(define (origin-frame-alt frame) + (car frame)) + +(define (edge1-frame-alt frame) + (car (cdr frame))) + +(define (edge2-frame-alt frame) + (cdr (cdr frame))) + +;;; tests + +(module+ tests + (require rackunit) + + (define f1 (make-frame (make-vect 1 2) (make-vect 3 4) (make-vect 5 6))) + (define f2 (make-frame-alt (make-vect 1 2) (make-vect 3 4) (make-vect 5 6))) + + ;; test selectors for make-frame + (check-equal? (origin-frame f1) '(1 . 2)) + (check-equal? (edge1-frame f1) '(3 . 4)) + (check-equal? (edge2-frame f1) '(5 . 6)) + + ;; test selectors for make-frame-alt + (check-equal? (origin-frame-alt f2) '(1 . 2)) + (check-equal? (edge1-frame-alt f2) '(3 . 4)) + (check-equal? (edge2-frame-alt f2) '(5 . 6)) + "all tests ran") |