summaryrefslogtreecommitdiff
path: root/docsrc/xlisp/xlisp-doc/reference/prog-star.htm
blob: 98ba7b1eb7eb87f957a213541e2def421a9188b8 (plain)
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
<html><head><title>XLISP prog*</title>

<link rel="stylesheet" type="text/css" href="reference.css">

</head>

<body>

<a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>

<hr>

<h1>prog*</h1>

<hr>

<p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
<tr valign="top">
  <td><nobr>Type:</nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%"><nobr>special form (fsubr)</nobr></td>
</tr>
<tr valign="top">
  <td><nobr>Source:</nobr></td>
  <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
  <td width="100%"><nobr>xlcont.c</nobr></td>
</tr>
</tbody></table></p>

<h2>Syntax</h2>

<dl>
<dt>(prog* ([<i>binding</i> ... ]) [<i>expr</i> ... ])</dt>
<dd><i>binding</i> - a variable binding which is can take one of
<dl><dd><i>symbol</i><br>
(<i>symbol init-expr</i>)</dd>
<dl><dd><i>symbol</i> - a symbol<br>
<i>init-expr</i> - an initialization expression for <i>symbol</i></dd></dl></dl>
<i>expr</i> - expressions comprising the body of the loop which may contain
<a href="return.htm">return</a>s,
<a href="go.htm">go</a>s or tags for
<a href="go.htm">go</a><br>
returns - <a href="nil.htm">NIL</a> or the argument passed to
the <a href="return.htm">return</a> function</dd>
</dl>

<h2>Description</h2>

<p>The 'prog*' special form is basically a 'block' construct that contains
symbols with optional initializations and a block of code [expressions] to
evaluate. The 'prog*' special form evaluates its initializations in
sequential order as opposed to <a href="">prog</a> which does it in no
specified order. The first form after the 'prog*' is the 'binding' form. It
contains a series of 'symbols' or 'bindings'. The 'binding' is a 'symbol'
followed by an initialization expression 'init-expr'. If there is no
'init-expr', the 'symbol' will be initialized to
<a href="nil.htm">NIL</a>. The order of execution of the bindings
is sequential. If a <a href="return.htm">return</a> form is
evaluated, its value will be returned. Otherwise,
<a href="nil.htm">NIL</a> is returned. When the 'prog*' is
finished execution, the 'symbols' that were defined will no longer exist or
retain their values.</p>

<h2>Examples</h2>

<pre class="example">
(prog* (i j)                 <font color="#008844">; PROG* with vars I and J</font>
       (print i) (print j))  <font color="#008844">; prints  NIL NIL  returns NIL</font>

(prog* ((i 1) (j 2))         <font color="#008844">; PROG* with vars I and J</font>
       (print i) (print j)
       (return (+ i j)))     <font color="#008844">; prints 1 2  returns 3</font>

(prog* () (print "hello"))   <font color="#008844">; prints "hello"  returns NIL</font>

(prog ((i 1) (j (+ i 1)))    <font color="#008844">; PROG won't work due to order</font>
      (print (+ i j)) )      <font color="#008844">; error: unbound variable - I</font>

(prog* ((i 1) (j (+ i 1)))   <font color="#008844">; PROG* will work due to order</font>
       (print (+ i j)) )     <font color="#008844">; prints 3  returns NIL</font>
</pre>

<p>See the
<a href="../manual/xlisp-man-021.htm#prog*">prog*</a>
special form in the <nobr>XLISP 2.0</nobr> manual.</p>

<p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</nobr></a></p>

<hr>

<a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>

</body></html>