diff options
author | rsiddharth <s@ricketyspace.net> | 2018-06-08 23:44:59 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2018-06-08 23:44:59 +0000 |
commit | 47a191e56e0cea10269dd6ff5a80242814f1463f (patch) | |
tree | 0804c6b94c13024e65a8f256b0ff16a4b97eef94 | |
parent | e33cb77079e7573b62dd44be493f4ef2975446d3 (diff) |
Add net/ricketyspace/sicp/two/two.scm
-rw-r--r-- | net/ricketyspace/sicp/two/two.scm | 43 |
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))))) |