GNU Emacs and MIT Scheme on Mac OS X
Today, I planned to go back to the basics by taking 6.001 Structure and Interpretation of Computer Programs offered by MIT OpenCourseWare. I'll save the reason behind it for another post.
For running the programs that are used in the class, I decided to use MIT/GNU Scheme. I am running GNU Emacs 23 on my Mac OS X. After some research, I figured out the best way of doing this is through xscheme.
First, download the MIT/GNU Scheme binary for Mac OS X and copy it to your Applications directory. Then configure Emacs to use the downloaded binary by adding the following lines to your .emacs.
(setq scheme-program-name "/Applications/mit-scheme.app/Contents/Resources/mit-scheme")
(require 'xscheme)
Now write your Scheme program.
; Compute the square root of a given number using successive
; approximation.
(define (sqrt value)
(define (is-good-enough? guess value)
(< (abs (- (* guess guess) value)) 0.0000001))
(define (try guess value)
(if (is-good-enough? guess value)
guess
(try (/ (+ guess (/ value guess)) 2) value)))
(try 1 value))
(sqrt 4.0)
Invoke the Scheme process by 'M-x run-scheme'. Send the Scheme buffer to the Scheme process by 'M-o' and now you are able to run Scheme programs from Emacs.
Below is the screenshot of Scheme running under my Emacs session.