summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/ricketyspace/sicp/two/two.scm43
1 files changed, 43 insertions, 0 deletions
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
+;;;; <https://creativecommons.org/licenses/by-sa/4.0/>.
+
+(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)))))