I need an example. What does a simple program in Scheme look like?
Here's one that consists of a single command:
What does it do?(sqrt 23)
It directs Scheme to compute the square root of 23. Start Scheme in interactive mode, type in that command, and watch what happens:
In interactive mode, when you ask Scheme to compute the value of an arithmetic expression, it writes out the computed value before printing the next prompt. (In the implementation of Scheme that I use, the prompt is a greater-than sign followed by a space -- you can see it at the beginning of the interaction shown above. I've used this font for what the programmer types and this one for what Scheme displays so that you can follow the exchange more easily.)> (sqrt 23) 4.79583152331272
In fact, one can use Scheme as a desk calculator. If you type in a sequence of arithmetic expressions, Scheme will simply print out the value of each one:
Scheme's logarithms are natural (base e) rather than common (base 10).> (sqrt 39) 6.2449979983984 > (cos 0.7853981634) 0.707106781184743 > (log 14.7) 2.68784749378469
Next topic
Previous topic
Table of contents
This document is available on the World Wide Web as
http://www.math.grin.edu/~stone/scheme-web/first-program.html