Chapter 2, Building Abstractions with Data
Section - 2.1 - Introduction to Data Abstraction
Exercise 2.7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#lang sicp
(define (make-interval a b) (cons a b))
(define (lower-bound x) (min (car x) (cdr x)))
(define (upper-bound x) (max (car x) (cdr x)))
(define (display-interval x)
(display "[")
(display (lower-bound x))
(display ",")
(display (upper-bound x))
(display "]")
(newline)
)
Sample output:
1
2
3
> (define intrvl (make-interval -50 -100))
> (display-interval intrvl)
[-100,-50]