When learning any new programming language, one is supposed to encounter the stock example of an easy program: one that prints out ``Hello, world!'' What would that program look like in Scheme?
Let's do this one as the first program to be executed in batch mode. Use your text editor to create a file containing just these two lines:
(If you don't have a text editor, your HTML client program may be able to download a copy of the file for you.)(display "Hello, world!") (newline)
Now submit that file to Scheme in batch mode. The cheerful greeting
should appear somewhere on your screen.Hello, world!
I don't get it. Explain the structure of the program.
It consists of two commands. The first command directs Scheme to write out the string of characters between the double-quotation marks. The second one tells it to terminate the output line and start a new one.
Why are the commands in parentheses?
Scheme uses parentheses to collect the parts of a command. It generally ignores spaces and line breaks, so that the programmer can lay out the parts of a command however she likes without changing its meaning or effect, so long as the parenthesis-groupings are intact.
Why did we have to do this in batch mode? Wouldn't the program do the same thing in interactive mode?
Sure, but in interactive mode it would also generate a prompt before each of the commands. Moreover, it would report on the result of the first command before looking at the second one. The output from the program would be interleaved with Scheme's own attempts to interact with the programmer. Here's how it looks under the SCM implementation of Scheme:
Some implementations of Scheme avoid this problem by having program output appear in a separate window. This is much less confusing, although it means that you have one more window to keep track of.> (display "Hello, world!") Hello, world!#<unspecified> > (newline) #<unspecified>
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/hello-world.html