Setting up MIT Scheme on Ubuntu 18.04Tue 31 July 2018 by jmhal
I'm going through Structure and Interpretation of Computer Programs and for exercise 1.3 there is this question:
Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
All the other questions for this section may be solved with pen and paper, but I think this one is easier to see when you code. First, let's install scheme on Ubuntu:
$ sudo apt install mit-scheme
Secondly, let's create a file max-three-sum-squares.scm with the following content:
(define (max-three-square x y z) ( cond ((and (> x z) (> y z)) (+(* x x)(* y y))) ((and (> x y) (> z y)) (+(* x x)(* z z))) ((and (> z x) (> y x)) (+(* z z)(* y y))) ) ) (display (max-three-square 3 4 5)) (display "\n")
To execute the program, we have to call the interpreter with the code, but requesting it not to display any debug information (hence the --quiet flag):
$ scheme --quiet < max-three-sum-squares.scm
That's it, you are now a little schemer.