teachyourselfschemeinfixnumdays6

teachyourselfschemeinfixnumdays6 - Teach Yourself Scheme in...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Teach Yourself Scheme in Fixnum Days by Dorai Sitaram Last modified: Thursday, November 18th, 2004 US/Eastern HTML conversion by TeX2page 2004-09-11 Chapter 1 Enter Scheme The canonical first program is the one that says "Hello, World!" on the console. Using your favorite editor, create a file called hello.scm with the following contents: ;The first program ( begin ( display "Hello, World!" ) ( newline )) The first line is a comment. When Scheme sees a semicolon, it ignores it and all the following text on the line. The begin- form is Scheme's way of introducing a sequence of subforms . In this case there are two subforms. The first is a call to the display procedure that outputs its argument (the string "Hello, World!" ) to the console (or ``standard output''). It is followed by a newline procedure call, which outputs a carriage return. To run this program, first start your Scheme. This is usually done by typing the name of your Scheme executable at the operating-system command line. Eg, in the case of MzScheme [ 9 ], you type mzscheme at the operating-system prompt. This invokes the Scheme listener , which read s your input, eval uates it, print s the result (if any), and then waits for more input from you. For this reason, it is often called the read-eval-print loop . Note that this is not much different from your operating-system command line, which also reads your commands, executes them, and then waits for more. Like the operating system, the Scheme listener has its own prompt -- usually this is > , but could be something else. At the listener prompt, load the file hello.scm . This is done by typing ( load "hello.scm" ) Scheme will now execute the contents of hello.scm , outputting Hello, World! followed by a carriage return. After this, you will get the listener prompt again, waiting for more input from you. Since you have such an eager listener, you need not always write your programs in a file and load them. Sometimes, it is easier, especially when you are in an exploring mood, to simply type expressions directly at the listener prompt and see what happens. For example, typing the form ( begin ( display "Hello, World!" ) ( newline )) at the Scheme prompt produces Hello, World! Actually, you could simply have typed the form "Hello, World!" at the listener, and you would have obtained as result the string "Hello, World!" because that is the result of the listener evaluating "Hello, World!" . Other than the fact that the second approach produces a result with double-quotes around it, there is one other significant difference between the last two programs. The first (ie, the one with the begin ) does not evaluate to anything -- the Hello, World! it emits is a side-effect produced by the display and newline procedures writing to the standard output. In the second program, the form "Hello, World!" evaluates to the result, which in this case is the same string as the form....
View Full Document

Page1 / 98

teachyourselfschemeinfixnumdays6 - Teach Yourself Scheme in...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online