From 47a191e56e0cea10269dd6ff5a80242814f1463f Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Fri, 8 Jun 2018 23:44:59 +0000 Subject: Add net/ricketyspace/sicp/two/two.scm --- net/ricketyspace/sicp/two/two.scm | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 net/ricketyspace/sicp/two/two.scm (limited to 'net/ricketyspace') diff --git a/net/ricketyspace/sicp/two/two.scm b/net/ricketyspace/sicp/two/two.scm new file mode 100644 index 0000000..948ec39 --- /dev/null +++ b/net/ricketyspace/sicp/two/two.scm @@ -0,0 +1,43 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; . + +(define-module (net ricketyspace sicp two two) + #:export (make-point + x-point + y-point + make-segment + start-segment + end-segment + midpoint-segment)) + +;;; Util +(define (avg a b) + (/ (+ a b) 2.0)) + + +;;; Point +(define (make-point x y) + (cons x y)) + +(define (x-point point) + (car point)) + +(define (y-point point) + (cdr point)) + +;;; Segment +(define (make-segment start end) + (list start end)) + +(define (start-segment segment) + (car segment)) + +(define (end-segment segment) + (cadr segment)) + +(define (midpoint-segment segment) + (make-point (avg (x-point (start-segment segment)) + (x-point (end-segment segment))) + (avg (y-point (start-segment segment)) + (y-point (end-segment segment))))) -- cgit v1.2.3