Scheme is a small dialect of Lisp, designed by Guy Steele and Gerald Sussman in 1975. These lessons use GNU Guile 3: guile hello.scm runs a file, and guile alone opens a REPL with the prompt scheme@(guile-user)>. Type ,q to leave the REPL.
Scheme · Lesson 1 · On the house
Hello, Scheme: running Guile and the REPL
Run Scheme files with GNU Guile, try expressions at the REPL, write prefix calls, and print with display, write and newline. Lesson 1 is free — on the house.
Lessons · Scheme · Lesson 1 of 10 · On the house
Hello, Scheme: running Guile and the REPL
Run Scheme files with GNU Guile, try expressions at the REPL, write prefix calls, and print with display, write and newline.

Guile compiles a file the first time it runs and prints ;;; note: auto-compilation is enabled to stderr. guile --no-auto-compile hello.scm skips that step, which keeps quick scripts quiet.
Every Scheme program is made of expressions. A call is written in prefix form inside parentheses: the procedure comes first and the arguments follow, so (+ 1 2 3) is 6 and (* 2 (+ 3 4)) is 14. Inner expressions are evaluated before the outer call uses them.
There are no operator precedence rules to learn, because the parentheses show the structure exactly. Whitespace and line breaks between items do not matter, so long calls can be split over several lines.
(display x) prints a value in human-readable form and (newline) prints a line break. (write x) prints the value as Scheme would read it back, so a string keeps its double quotes and a character shows as #\a.
A semicolon starts a comment that runs to the end of the line. #| ... |# comments out a block, and #; comments out exactly one following expression.
At the REPL, Guile prints the value of each expression as $1 = 6, $2 = 14 and so on. In a script nothing is printed unless you call display or write.
hello.scm
;; hello.scm : run with guile hello.scm
(display "Hello, Scheme!")
(newline)
(display (+ 1 2 3))
(newline)
(display (* 2 (+ 3 4)))
(newline)
(write "a string") ; write keeps the quotes
(newline)
(display "a string") ; display does not
(newline)
#;(display "this whole expression is skipped")
(display (list 'sum (+ 10 20)))
(newline)
Quiz
Quiz
Quiz
Quiz
Check
Match the still for: Hello, Scheme: running Guile and the REPL.
Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.