sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit 47a191e56e0cea10269dd6ff5a80242814f1463f
parent e33cb77079e7573b62dd44be493f4ef2975446d3
Author: rsiddharth <s@ricketyspace.net>
Date:   Fri,  8 Jun 2018 23:44:59 +0000

Add net/ricketyspace/sicp/two/two.scm

Diffstat:
net/ricketyspace/sicp/two/two.scm | 43+++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/two/two.scm 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)))))