107 lines
4.8 KiB
HTML
107 lines
4.8 KiB
HTML
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!--
|
|
|
|
Generated from r6rs.tex by tex2page, v 20100828
|
|
(running on MzScheme 4.2.4, :unix),
|
|
(c) Dorai Sitaram,
|
|
http://evalwhen.com/tex2page/index.html
|
|
|
|
-->
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>
|
|
Revised^6 Report on the Algorithmic Language Scheme
|
|
</title>
|
|
<link rel="stylesheet" type="text/css" href="r6rs-Z-S.css" title=default>
|
|
<meta name=robots content="index,follow">
|
|
</head>
|
|
<body>
|
|
<div id=slidecontent>
|
|
<div align=right class=navigation>[Go to <span><a href="r6rs.html">first</a>, <a href="r6rs-Z-H-10.html">previous</a></span><span>, <a href="r6rs-Z-H-12.html">next</a></span> page<span>; </span><span><a href="r6rs-Z-H-2.html#node_toc_start">contents</a></span><span><span>; </span><a href="r6rs-Z-H-21.html#node_index_start">index</a></span>]</div>
|
|
<p></p>
|
|
<a name="node_chap_8"></a>
|
|
<h1 class=chapter>
|
|
<div class=chapterheading><a href="r6rs-Z-H-2.html#node_toc_node_chap_8">Chapter 8</a></div><br>
|
|
<a href="r6rs-Z-H-2.html#node_toc_node_chap_8">Top-level programs</a></h1>
|
|
<p></p>
|
|
<p>
|
|
A <a name="node_idx_290"></a><em>top-level program</em> 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.</p>
|
|
<p>
|
|
</p>
|
|
<a name="node_sec_8.1"></a>
|
|
<h2 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_8.1">8.1 Top-level program syntax</a></h2>
|
|
<p></p>
|
|
<p>
|
|
A top-level program is a delimited piece of text, typically a file, that
|
|
has the following form:
|
|
</p>
|
|
|
|
<tt><import form> <top-level body><p></tt>
|
|
An <import form> has the following form:
|
|
</p>
|
|
|
|
<tt>(import <import spec> <tt>...</tt>)<p></tt>
|
|
A <top-level body> has the following form:
|
|
</p>
|
|
|
|
<tt><top-level body form> <tt>...</tt><p></tt>
|
|
A <top-level body form> is either a <definition> or an
|
|
<expression>.</p>
|
|
<p>
|
|
The <import form> is identical to the import clause in
|
|
libraries (see section <a href="r6rs-Z-H-10.html#node_sec_7.1">7.1</a>),
|
|
and specifies a set of libraries to import. A <top-level
|
|
body> is like a <library body> (see
|
|
section <a href="r6rs-Z-H-10.html#node_sec_7.1">7.1</a>), except that
|
|
definitions and expressions may occur in any order. Thus, the syntax
|
|
specified by <top-level body form> refers to the result of macro
|
|
expansion.</p>
|
|
<p>
|
|
When uses of <tt>begin</tt>, <tt>let-syntax</tt>, or <tt>letrec-syntax</tt>
|
|
from the <tt>(rnrs base (6))</tt> library
|
|
occur in a top-level body prior to the first
|
|
expression, they are spliced into the body; see section <a href="r6rs-Z-H-14.html#node_sec_11.4.7">11.4.7</a>.
|
|
Some or all of the body, including portions wrapped in <tt>begin</tt>,
|
|
<tt>let-syntax</tt>, or <tt>letrec-syntax</tt>
|
|
forms, may be specified by a syntactic abstraction
|
|
(see section <a href="r6rs-Z-H-12.html#node_sec_9.2">9.2</a>).</p>
|
|
<p>
|
|
</p>
|
|
<a name="node_sec_8.2"></a>
|
|
<h2 class=section><a href="r6rs-Z-H-2.html#node_toc_node_sec_8.2">8.2 Top-level program semantics</a></h2>
|
|
<p>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 <expression> that appears before a
|
|
definition in
|
|
the top-level body is converted into a dummy definition
|
|
</p>
|
|
|
|
<tt>(define <variable> (begin <expression> <unspecified>))<p></tt>
|
|
where <variable> is a fresh identifier and <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 <a href="r6rs-Z-H-13.html#node_chap_10">10</a>.)</p>
|
|
<p>
|
|
On platforms that support it, a top-level program may access its command line
|
|
by calling the <tt>command-line</tt> procedure (see library
|
|
section on “Command-line access and exit values”).</p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div class=smallskip></div>
|
|
<p style="margin-top: 0pt; margin-bottom: 0pt">
|
|
<div align=right class=navigation>[Go to <span><a href="r6rs.html">first</a>, <a href="r6rs-Z-H-10.html">previous</a></span><span>, <a href="r6rs-Z-H-12.html">next</a></span> page<span>; </span><span><a href="r6rs-Z-H-2.html#node_toc_start">contents</a></span><span><span>; </span><a href="r6rs-Z-H-21.html#node_index_start">index</a></span>]</div>
|
|
</p>
|
|
<p></p>
|
|
</div>
|
|
</body>
|
|
</html>
|