File: programs.tex

package info (click to toggle)
r6rs-doc 1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,868 kB
  • ctags: 2,046
  • sloc: lisp: 5,409; makefile: 190
file content (80 lines) | stat: -rw-r--r-- 2,912 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
\chapter{Top-level programs}
\label{programchapter}

A \defining{top-level program} specifies an entry point for defining and running
a Scheme program.  A top-level program specifies a set of libraries to import and
code to run.  Through the imported libraries, whether directly or through the
transitive closure of importing, a top-level program defines a complete Scheme
program.

\section{Top-level program syntax}
\label{programsyntaxsection}

A top-level program is a delimited piece of text, typically a file, that 
has the following form:
%
\begin{scheme}
\hyper{import form} \hyper{top-level body}%
\end{scheme}
%
An \hyper{import form} has the following form:
%
\begin{scheme}
(import \hyper{import spec} \dotsfoo)%
\end{scheme}
%
A \hyper{top-level body} has the following form:
\begin{scheme}
\hyper{top-level body form} \dotsfoo%
\end{scheme}
%
A \hyper{top-level body form} is either a \hyper{definition} or an
\hyper{expression}.

The \hyper{import form} is identical to the import clause in
libraries (see section~\ref{librarysyntaxsection}), 
and specifies a set of libraries to import.  A \hyper{top-level 
 body} is like a \hyper{library body} (see
section~\ref{librarybodysection}), except that 
definitions and expressions may occur in any order.  Thus, the syntax
specified by \hyper{top-level body form} refers to the result of macro
expansion.

When uses of {\cf begin}, {\cf let-syntax}, or {\cf letrec-syntax}
from the \rsixlibrary{base} library
occur in a top-level body prior to the first
expression, they are spliced into the body; see section~\ref{begin}.
Some or all of the body, including portions wrapped in {\cf begin},
{\cf let-syntax}, or {\cf letrec-syntax}
forms, may be specified by a syntactic abstraction
(see section~\ref{macrosection}).

\section{Top-level program semantics}

A top-level program is executed by treating the program similarly to a library, and
evaluating its definitions and expressions.
The semantics of a top-level body may be roughly explained by
a simple translation into a library body: 
Each \hyper{expression} that appears before a
definition in
the top-level body is converted into a dummy definition 
%
\begin{scheme}
(define \hyper{variable} (begin \hyper{expression} \hyper{unspecified}))%
\end{scheme}
%
where \hyper{variable} is a fresh identifier and \hyper{unspecified}
is a side-effect-free expression returning an unspecified value.
(It is generally impossible to determine which forms are 
definitions and expressions without concurrently expanding the body, so
the actual translation is somewhat more complicated; see
chapter~\ref{expansionchapter}.)

On platforms that support it, a top-level program may access its command line 
by calling the {\cf command-line} procedure (see library 
section~\extref{lib:command-line}{Command-line access and exit values}).

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "r6rs"
%%% End: