@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
-@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005
+@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2012
@c Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
-@node Basic Ideas
-@section Basic Ideas in Scheme
+@node Hello Scheme!
+@chapter Hello Scheme!
In this chapter, we introduce the basic concepts that underpin the
elegance and power of the Scheme language.
skip this chapter. For the reader who is new to the language, however,
the following discussions on data, procedures, expressions and closure
are designed to provide a minimum level of Scheme understanding that is
-more or less assumed by the reference chapters that follow.
+more or less assumed by the chapters that follow.
-The style of this introductory material aims about halfway between the
-terse precision of R5RS and the discursive randomness of a Scheme
-tutorial.
+The style of this introductory material aims about halfway between the terse
+precision of R5RS and the discursiveness of existing Scheme tutorials. For
+pointers to useful Scheme resources on the web, please see @ref{Further
+Reading}.
@menu
* About Data:: Latent typing, types, values and variables.
* About Procedures:: The representation and use of procedures.
* About Expressions:: All kinds of expressions and their meaning.
* About Closure:: Closure, scoping and environments.
+* Further Reading:: Where to find out more about Scheme.
@end menu
@node About Data
-@subsection Data Types, Values and Variables
+@section Data Types, Values and Variables
This section discusses the representation of data types and values, what
it means for Scheme to be a @dfn{latently typed} language, and the role
@node Latent Typing
-@subsubsection Latent Typing
+@subsection Latent Typing
The term @dfn{latent typing} is used to describe a computer language,
such as Scheme, for which you cannot, @emph{in general}, simply look at
@node Values and Variables
-@subsubsection Values and Variables
+@subsection Values and Variables
Scheme provides many data types that you can use to represent your data.
Primitive types include characters, strings, numbers and procedures.
@node Definition
-@subsubsection Defining and Setting Variables
+@subsection Defining and Setting Variables
To define a new variable, you use Scheme's @code{define} syntax like
this:
@node About Procedures
-@subsection The Representation and Use of Procedures
+@section The Representation and Use of Procedures
This section introduces the basics of using and creating Scheme
procedures. It discusses the representation of procedures as just
@node Procedures as Values
-@subsubsection Procedures as Values
+@subsection Procedures as Values
One of the great simplifications of Scheme is that a procedure is just
another type of value, and that procedure values can be passed around
@node Simple Invocation
-@subsubsection Simple Procedure Invocation
+@subsection Simple Procedure Invocation
A procedure invocation in Scheme is written like this:
@node Creating a Procedure
-@subsubsection Creating and Using a New Procedure
+@subsection Creating and Using a New Procedure
Scheme has lots of standard procedures, and Guile provides all of these
via predefined top level variables. All of these standard procedures
@node Lambda Alternatives
-@subsubsection Lambda Alternatives
+@subsection Lambda Alternatives
Since it is so common in Scheme programs to want to create a procedure
and then store it in a variable, there is an alternative form of the
@noindent
For details on how these forms work, see @xref{Lambda}.
+Prior to Guile 2.0, Guile provided an extension to @code{define} syntax
+that allowed you to nest the previous extension up to an arbitrary
+depth. These are no longer provided by default, and instead have been
+moved to @ref{Curried Definitions}
+
(It could be argued that the alternative @code{define} forms are rather
confusing, especially for newcomers to the Scheme language, as they hide
both the role of @code{lambda} and the fact that procedures are values
@node About Expressions
-@subsection Expressions and Evaluation
+@section Expressions and Evaluation
So far, we have met expressions that @emph{do} things, such as the
@code{define} expressions that create and initialize new variables, and
@node Evaluating
-@subsubsection Evaluating Expressions and Executing Programs
+@subsection Evaluating Expressions and Executing Programs
In Scheme, the process of executing an expression is known as
@dfn{evaluation}. Evaluation has two kinds of result:
type of expression individually.
@noindent
-So, some@footnote{These definitions are approximate. For the whole and
-detailed truth, see @xref{Formal syntax and semantics,R5RS
-syntax,,r5rs}.} definitions@dots{}
+So, some@footnote{These definitions are approximate. For the whole
+and detailed truth, see @ref{Formal syntax and semantics,R5RS
+syntax,,r5rs,The Revised(5) Report on the Algorithmic Language
+Scheme}.} definitions@dots{}
@itemize @bullet
The following subsections describe how each of these types of expression
is evaluated.
-@c @menu
-@c * Eval Literal:: Evaluating literal data.
-@c * Eval Variable:: Evaluating variable references.
-@c * Eval Procedure:: Evaluating procedure invocation expressions.
-@c * Eval Special:: Evaluating special syntactic expressions.
-@c @end menu
-
-@c @node Eval Literal
+@menu
+* Eval Literal:: Evaluating literal data.
+* Eval Variable:: Evaluating variable references.
+* Eval Procedure:: Evaluating procedure invocation expressions.
+* Eval Special:: Evaluating special syntactic expressions.
+@end menu
-@subsubheading Evaluating Literal Data
+@node Eval Literal
+@subsubsection Evaluating Literal Data
When a literal data expression is evaluated, the value of the expression
is simply the value that the expression describes. The evaluation of a
using the shorthand form of @code{define} (@pxref{Lambda Alternatives}).
-@c @node Eval Variable
-@subsubheading Evaluating a Variable Reference
+@node Eval Variable
+@subsubsection Evaluating a Variable Reference
When an expression that consists simply of a variable name is evaluated,
the value of the expression is the value of the named variable. The
variable reference expression signals an error.
-@c @node Eval Procedure
-@subsubheading Evaluating a Procedure Invocation Expression
+@node Eval Procedure
+@subsubsection Evaluating a Procedure Invocation Expression
This is where evaluation starts getting interesting! As already noted,
a procedure invocation expression has the form
numeric value that is the length of the argument string, which is 12.
-@c @node Eval Special
-@subsubheading Evaluating Special Syntactic Expressions
+@node Eval Special
+@subsubsection Evaluating Special Syntactic Expressions
When a procedure invocation expression is evaluated, the procedure and
@emph{all} the argument expressions must be evaluated before the
@node Tail Calls
-@subsubsection Tail calls
+@subsection Tail calls
@cindex tail calls
@cindex recursion
@node The REPL
-@subsubsection Using the Guile REPL
+@subsection Using the Guile REPL
If you start Guile without specifying a particular program for it to
execute, Guile enters its standard Read Evaluate Print Loop --- or
@node Syntax Summary
-@subsubsection Summary of Common Syntax
+@subsection Summary of Common Syntax
This subsection lists the most commonly used Scheme syntactic
expressions, simply so that you will recognize common special syntax
evaluation of a procedure invocation expression does not guarantee to
evaluate the arguments in order.
-@code{if} and @code{cond} (@pxref{if cond case}) provide conditional
+@code{if} and @code{cond} (@pxref{Conditionals}) provide conditional
evaluation of argument expressions depending on whether one or more
conditions evaluate to ``true'' or ``false''.
-@code{case} (@pxref{if cond case}) provides conditional evaluation of
+@code{case} (@pxref{Conditionals}) provides conditional evaluation of
argument expressions depending on whether a variable has one of a
specified group of values.
@node About Closure
-@subsection The Concept of Closure
+@section The Concept of Closure
@cindex closure
@end menu
@node About Environments
-@subsubsection Names, Locations, Values and Environments
+@subsection Names, Locations, Values and Environments
@cindex location
@cindex environment
@node Local Variables
-@subsubsection Local Variables and Environments
+@subsection Local Variables and Environments
@cindex local variable
@cindex variable, local
@node Chaining
-@subsubsection Environment Chaining
+@subsection Environment Chaining
@cindex shadowing an imported variable binding
@cindex chaining environments
@node Lexical Scope
-@subsubsection Lexical Scope
+@subsection Lexical Scope
The rules that we have just been describing are the details of how
Scheme implements ``lexical scoping''. This subsection takes a brief
scoping and examines in detail how its behavior differs from the
corresponding lexically scoped code.
-@c @menu
-@c * Scoping Example:: An example of non-lexical scoping.
-@c @end menu
+@menu
+* Scoping Example:: An example of non-lexical scoping.
+@end menu
-@c @node Scoping Example
-@subsubheading An Example of Non-Lexical Scoping
+@node Scoping Example
+@subsubsection An Example of Non-Lexical Scoping
To demonstrate that non-lexical scoping does exist and can be useful, we
present the following example from Emacs Lisp, which is a ``dynamically
@node Closure
-@subsubsection Closure
+@subsection Closure
Consider a @code{let} expression that doesn't contain any
@code{lambda}s:
@node Serial Number
-@subsubsection Example 1: A Serial Number Generator
+@subsection Example 1: A Serial Number Generator
This example uses closure to create a procedure with a variable binding
that is private to the procedure, like a local variable, but whose value
@node Shared Variable
-@subsubsection Example 2: A Shared Persistent Variable
+@subsection Example 2: A Shared Persistent Variable
This example uses closure to create two procedures, @code{get-balance}
and @code{deposit}, that both refer to the same captured local
@node Callback Closure
-@subsubsection Example 3: The Callback Closure Problem
+@subsection Example 3: The Callback Closure Problem
A frequently used programming model for library code is to allow an
application to register a callback function for the library to call when
@node OO Closure
-@subsubsection Example 4: Object Orientation
+@subsection Example 4: Object Orientation
Closure is the capture of an environment, containing persistent variable
bindings, within the definition of a procedure or a set of related