Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Data Represented as Procedures
; 2.2 Representing data with procedures
(define (make-point x y)(cons x y))
(define (x-point point) (car point))
(define (y-point point) (cdr point))
(define a-point (make-point 0 0))
(define b-point (make-point 2 2))
(x-point a-point)
(y-point a-point)
(define (make-segment start-point end-point)(cons start-point end-point))
(define (start-point segment) (car segment))
(define (end-point segment) (cdr segment))
(define segment (make-segment a-point b-point))
(define (mid-point segment)
(make-point (/ (+ (x-point (start-point segment)) (x-point (end-point segment))) 2)
(/ (+ (y-point (start-point segment)) (y-point (end-point segment))) 2)))
(mid-point segment) ;--> (1 . 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.