From a8c783445fff7a3f301dbe352ac51895cab9e979 Mon Sep 17 00:00:00 2001 From: siddharth Date: Sat, 9 Oct 2021 21:04:26 -0400 Subject: ex: do ex 2.47 --- ex/2/47.rkt | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ex/2/47.rkt (limited to 'ex/2') 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") -- cgit v1.2.3