elisp @@ macro
[bpt/guile.git] / doc / ref / scheme-ideas.texi
index 55093cf..15cf664 100644 (file)
@@ -1,11 +1,11 @@
 @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.
@@ -14,22 +14,24 @@ Readers who already possess a background knowledge of Scheme may happily
 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
@@ -45,7 +47,7 @@ variable.
 
 
 @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
@@ -82,7 +84,7 @@ that Scheme programs use data types, values and variables.
 
 
 @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.
@@ -119,7 +121,7 @@ the variable happens to be storing at a particular moment.
 
 
 @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:
@@ -200,7 +202,7 @@ of an existing variable.
 
 
 @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
@@ -219,7 +221,7 @@ explicit @code{lambda} expression.
 
 
 @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
@@ -278,7 +280,7 @@ procedure value.
 
 
 @node Simple Invocation
-@subsubsection Simple Procedure Invocation
+@subsection Simple Procedure Invocation
 
 A procedure invocation in Scheme is written like this:
 
@@ -339,7 +341,7 @@ its arguments.)
 
 
 @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
@@ -421,7 +423,7 @@ same ways.
 
 
 @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
@@ -474,6 +476,11 @@ The corresponding forms of the alternative @code{define} syntax are:
 @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
@@ -485,7 +492,7 @@ subsequently read input.)
 
 
 @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
@@ -519,7 +526,7 @@ expressions.
 
 
 @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:
@@ -549,9 +556,10 @@ and then by describing the value and side effects of evaluation for each
 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
 
@@ -582,16 +590,15 @@ one of Scheme's special syntactic expressions.
 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
@@ -626,8 +633,8 @@ cannot be expressed as literal data; they must be created using 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
@@ -654,8 +661,8 @@ If there is no variable with the specified name, evaluation of 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
@@ -745,8 +752,8 @@ obtained from @var{arg1} as its arguments.  The resulting value is a
 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
@@ -790,7 +797,7 @@ syntax, see @xref{Syntax Summary}.
 
 
 @node Tail Calls
-@subsubsection Tail calls
+@subsection Tail calls
 @cindex tail calls
 @cindex recursion
 
@@ -906,7 +913,7 @@ those explicitly described are guaranteed.
 
 
 @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
@@ -935,7 +942,7 @@ REPL and checking that it gives the expected @var{result}.
 
 
 @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
@@ -962,11 +969,11 @@ same as a procedure which returns its last argument, because the
 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.
 
@@ -980,7 +987,7 @@ until either there are no expressions left, or one of them evaluates to
 
 
 @node About Closure
-@subsection The Concept of Closure
+@section The Concept of Closure
 
 @cindex closure
 
@@ -1006,7 +1013,7 @@ more detail.
 @end menu
 
 @node About Environments
-@subsubsection Names, Locations, Values and Environments
+@subsection Names, Locations, Values and Environments
 
 @cindex location
 @cindex environment
@@ -1054,7 +1061,7 @@ closure; the next subsection shows how it is done.
 
 
 @node Local Variables
-@subsubsection Local Variables and Environments
+@subsection Local Variables and Environments
 
 @cindex local variable
 @cindex variable, local
@@ -1095,7 +1102,7 @@ expression, and therefore the value of the variable @code{area}.
 
 
 @node Chaining
-@subsubsection Environment Chaining
+@subsection Environment Chaining
 
 @cindex shadowing an imported variable binding
 @cindex chaining environments
@@ -1146,7 +1153,7 @@ level environment.
 
 
 @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
@@ -1177,13 +1184,13 @@ scoping, the following subsection presents an example of non-lexical
 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
@@ -1288,7 +1295,7 @@ this identifier refer to the top level variable.
 
 
 @node Closure
-@subsubsection Closure
+@subsection Closure
 
 Consider a @code{let} expression that doesn't contain any
 @code{lambda}s:
@@ -1356,7 +1363,7 @@ present examples that explore the usefulness of this concept.
 
 
 @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
@@ -1398,7 +1405,7 @@ object with an association to this environment.
 
 
 @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
@@ -1449,7 +1456,7 @@ that would not be accessible at top level.
 
 
 @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
@@ -1507,7 +1514,7 @@ correctly.
 
 
 @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