-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
189 lines (142 loc) · 11.6 KB
/
index.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Source §3</title>
<link rel="shortcut icon"
type="image/x-icon"
href="/images/sourcepower.ico" />
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source §3</h1>
<!-- changed by MH on 1/7/2019 from default template. See "MH" below -->
<!-- changed by MH on 3/6/2021 from default template. See "MH" below -->
<h3> </h3>
<section>
<article><p>Source §3 is a small programming language, designed for the third chapter
of the textbook
<a href="https://sourceacademy.org/sicpjs">Structure and Interpretation
of Computer Programs, JavaScript Adaptation</a> (SICP JS).</p>
<h2>What names are predeclared in Source §3?</h2>
<p>On the right, you see all predeclared names of Source §3, in alphabetical
order. Click on a name to see how it is defined and used. They come in these groups:</p>
<ul>
<li>
<a href="../AUXILIARY/index.html">AUXILIARY</a>: Auxiliary constants and functions
</li>
<li>
<a href="../MISC/index.html">MISC</a>: Miscellaneous constants and functions
</li>
<li>
<a href="../MATH/index.html">MATH</a>: Mathematical constants and functions
</li>
<li>
<a href="../LISTS/index.html">LISTS</a>: Support for lists
</li>
<li>
<a href="../PAIRMUTATORS/index.html">PAIRMUTATORS</a>: Mutating pairs
</li>
<li>
<a href="../ARRAYS/index.html">ARRAYS</a>: Support for arrays
</li>
<li>
<a href="../STREAMS/index.html">STREAMS</a>: Support for streams
</li>
</ul>
<h2>What can you do in Source §3?</h2>
<p>You can use all features of
<a href="../source_2/">Source §2</a> and all
features that are introduced in
<a href="https://sourceacademy.org/sicpjs/3">chapter 3</a> of the
textbook.
Below are the features that Source §3 adds to Source §2.</p>
<h3>Variable declaration statements</h3>
<p>In Source §3, variables are declared as in:</p>
<p><CODE>let my_variable = x * 4;</CODE></p>
<p>The scope of names declared with <code>let</code> is the
same as
the scope of names declared with <code>const</code>: the closest
surrounding block. The difference is that variables
can be used in assignment statements.</p>
<h3>Variable assignment statements</h3>
<p>Variables can be assigned to as in: <PRE><CODE>let x = 1;
display(x); // x is still 1
x = x + 1;
diplay(x); // now x is 2</CODE></PRE>
Read more on variable declaration and assignment in
<a href="https://sourceacademy.org/sicpjs/3.1.1">section 3.1.1 Local State Variables</a>
of the textbook.</p>
<h3>While loops</h3>
<p>A while loop repeatedly evaluates a predicate and if the predicate returns <code>true</code>,
evaluates a given block. The evaluation terminates when the predicate returns <code>false</code>.
Example:</p>
<PRE><CODE>let x = 0;
while (x < 10) {
display(x);
x = x + 1;
}</CODE></PRE>
<p>will display the numbers from 0 to 9.</p>
<p>While loops are not covered in the textbook.</p>
<h3>For loops</h3>
<p>The pattern of repeatedly testing and changing a particular variable is
supported by for loops. The same program can be written shorter as:</p>
<PRE><CODE>let x = 0;
for (x = 0; x < 10; x = x + 1) {
display(x);
}</CODE></PRE>
<p>The increment statement <CODE>x = x + 1</CODE> is always
evaluated after the body of the loop.</p>
<p>You can limit the scope of the variable to just the for loop, by writing
<code>let</code> after the parenthesis: <PRE><CODE>for (let x = 0; x < 10; x = x + 1) {
display(x);
}</CODE></PRE>
For loops are not covered in the textbook.</p>
<h3>Arrays, array access and array assignment</h3>
<p>Arrays are created using literal array expressions, as follows:</p>
<p><CODE>const my_array = [10, 20, 30];</CODE></p>
<p>The constant <code>my_array</code> now refers to an array with three elements.
The elements in such a literal array expressions have implicit
keys. The first element has key 0, the second has key 1, the third
has key 2 and so on.</p>
<p>An array can be accessed using array access expressions, with
a given key:</p>
<p><CODE>my_array[0] + my_array[1] + my_array[2]; // 60</CODE></p>
<p>Like pairs, arrays can be changed in Source §3. This is done
using array assignment:</p>
<p><CODE>my_array[1] = 200;</CODE></p>
<p>Array assignment and array access in Source §3 are restricted
to integers (numbers with no fractional component) larger than or
equal to 0 and less than 2<SUP>32</SUP>-1. We call such numbers <EM>array indices</EM>.</p>
<p>You can use any array index in array assignment; the array will
automatically adjust its size. Accessing an array at an array
index that has not been assigned yet (using a literal array
expression or an array assignment) will return <code>undefined</code>.</p>
<p>Arrays are not covered in the textbook.</p>
<h2>You want the definitive specs?</h2>
<p>For our development team, we are maintaining a definitive description
of the language, called the
<a href="../source_3.pdf">Specification of Source §3</a>. Feel free to
take a peek!</p></article>
</section>
</div>
<nav>
<h3>Predeclared names</h3><ul><li><a href="global.html#__access_export__">__access_export__</a></li><li><a href="global.html#__access_named_export__">__access_named_export__</a></li><li><a href="global.html#accumulate">accumulate</a></li><li><a href="global.html#append">append</a></li><li><a href="global.html#arity">arity</a></li><li><a href="global.html#array_length">array_length</a></li><li><a href="global.html#build_list">build_list</a></li><li><a href="global.html#build_stream">build_stream</a></li><li><a href="global.html#char_at">char_at</a></li><li><a href="global.html#display">display</a></li><li><a href="global.html#display_list">display_list</a></li><li><a href="global.html#draw_data">draw_data</a></li><li><a href="global.html#enum_list">enum_list</a></li><li><a href="global.html#enum_stream">enum_stream</a></li><li><a href="global.html#equal">equal</a></li><li><a href="global.html#error">error</a></li><li><a href="global.html#eval_stream">eval_stream</a></li><li><a href="global.html#filter">filter</a></li><li><a href="global.html#for_each">for_each</a></li><li><a href="global.html#get_time">get_time</a></li><li><a href="global.html#head">head</a></li><li><a href="global.html#Infinity">Infinity</a></li><li><a href="global.html#integers_from">integers_from</a></li><li><a href="global.html#is_array">is_array</a></li><li><a href="global.html#is_boolean">is_boolean</a></li><li><a href="global.html#is_function">is_function</a></li><li><a href="global.html#is_list">is_list</a></li><li><a href="global.html#is_null">is_null</a></li><li><a href="global.html#is_number">is_number</a></li><li><a href="global.html#is_pair">is_pair</a></li><li><a href="global.html#is_stream">is_stream</a></li><li><a href="global.html#is_string">is_string</a></li><li><a href="global.html#is_undefined">is_undefined</a></li><li><a href="global.html#length">length</a></li><li><a href="global.html#list">list</a></li><li><a href="global.html#list_ref">list_ref</a></li><li><a href="global.html#list_to_stream">list_to_stream</a></li><li><a href="global.html#list_to_string">list_to_string</a></li><li><a href="global.html#map">map</a></li><li><a href="global.html#math_abs">math_abs</a></li><li><a href="global.html#math_acos">math_acos</a></li><li><a href="global.html#math_acosh">math_acosh</a></li><li><a href="global.html#math_asin">math_asin</a></li><li><a href="global.html#math_asinh">math_asinh</a></li><li><a href="global.html#math_atan">math_atan</a></li><li><a href="global.html#math_atan2">math_atan2</a></li><li><a href="global.html#math_atanh">math_atanh</a></li><li><a href="global.html#math_cbrt">math_cbrt</a></li><li><a href="global.html#math_ceil">math_ceil</a></li><li><a href="global.html#math_clz32">math_clz32</a></li><li><a href="global.html#math_cos">math_cos</a></li><li><a href="global.html#math_cosh">math_cosh</a></li><li><a href="global.html#math_E">math_E</a></li><li><a href="global.html#math_exp">math_exp</a></li><li><a href="global.html#math_expm1">math_expm1</a></li><li><a href="global.html#math_floor">math_floor</a></li><li><a href="global.html#math_fround">math_fround</a></li><li><a href="global.html#math_hypot">math_hypot</a></li><li><a href="global.html#math_imul">math_imul</a></li><li><a href="global.html#math_LN2">math_LN2</a></li><li><a href="global.html#math_LN10">math_LN10</a></li><li><a href="global.html#math_log">math_log</a></li><li><a href="global.html#math_log1p">math_log1p</a></li><li><a href="global.html#math_log2">math_log2</a></li><li><a href="global.html#math_LOG2E">math_LOG2E</a></li><li><a href="global.html#math_log10">math_log10</a></li><li><a href="global.html#math_LOG10E">math_LOG10E</a></li><li><a href="global.html#math_max">math_max</a></li><li><a href="global.html#math_min">math_min</a></li><li><a href="global.html#math_PI">math_PI</a></li><li><a href="global.html#math_pow">math_pow</a></li><li><a href="global.html#math_random">math_random</a></li><li><a href="global.html#math_round">math_round</a></li><li><a href="global.html#math_sign">math_sign</a></li><li><a href="global.html#math_sin">math_sin</a></li><li><a href="global.html#math_sinh">math_sinh</a></li><li><a href="global.html#math_sqrt">math_sqrt</a></li><li><a href="global.html#math_SQRT1_2">math_SQRT1_2</a></li><li><a href="global.html#math_SQRT2">math_SQRT2</a></li><li><a href="global.html#math_tan">math_tan</a></li><li><a href="global.html#math_tanh">math_tanh</a></li><li><a href="global.html#math_trunc">math_trunc</a></li><li><a href="global.html#member">member</a></li><li><a href="global.html#NaN">NaN</a></li><li><a href="global.html#pair">pair</a></li><li><a href="global.html#parse_int">parse_int</a></li><li><a href="global.html#prompt">prompt</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#remove_all">remove_all</a></li><li><a href="global.html#reverse">reverse</a></li><li><a href="global.html#set_head">set_head</a></li><li><a href="global.html#set_tail">set_tail</a></li><li><a href="global.html#stream">stream</a></li><li><a href="global.html#stream_append">stream_append</a></li><li><a href="global.html#stream_filter">stream_filter</a></li><li><a href="global.html#stream_for_each">stream_for_each</a></li><li><a href="global.html#stream_length">stream_length</a></li><li><a href="global.html#stream_map">stream_map</a></li><li><a href="global.html#stream_member">stream_member</a></li><li><a href="global.html#stream_ref">stream_ref</a></li><li><a href="global.html#stream_remove">stream_remove</a></li><li><a href="global.html#stream_remove_all">stream_remove_all</a></li><li><a href="global.html#stream_reverse">stream_reverse</a></li><li><a href="global.html#stream_tail">stream_tail</a></li><li><a href="global.html#stream_to_list">stream_to_list</a></li><li><a href="global.html#stringify">stringify</a></li><li><a href="global.html#tail">tail</a></li><li><a href="global.html#undefined">undefined</a></li></ul>
</nav>
<br class="clear">
<footer>
generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> from
<a href="https://github.com/source-academy/js-slang">Github repository js-slang</a>
on Wed Apr 23 2025 02:49:20 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>