File: progv.htm

package info (click to toggle)
nyquist 3.20%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 58,008 kB
  • sloc: ansic: 74,743; lisp: 17,929; java: 10,723; cpp: 6,690; sh: 171; xml: 58; makefile: 40; python: 15
file content (133 lines) | stat: -rw-r--r-- 4,952 bytes parent folder | download | duplicates (7)
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
<html><head><title>XLISP progv</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>progv</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>

<p><div class="box">

<dl>
<dt>(<b>progv</b> <i>symbols values</i> [<i>expr1 expr2</i> ... ])</dt>
<dd><i>symbols</i> - a list of symbols to be bound<br>
<i>values</i> - a list of values to be bound to symbols<br>
<i>exprN</i> - expressions for the body of the loop<br>
returns - the value of the last expression</dd>
</dl>

</div></p>

<h2>Description</h2>

<p>The 'progv' special form is basically a 'block' construct that contains a
block of code [expressions] to evaluate. 'progv' is different from
<nobr><a href="prog1.htm">prog1</a></nobr>, <a href="prog2.htm">prog2</a>
and <a href="progn.htm">progn</a> in that it contains a pair of lists,
'symbols' and 'values'. Before evaluating the expressions, 'progv'
will dynamically bind the 'values' to the corresponding 'symbols'.
<nobr>If there</nobr> are too many 'symbols' for the 'values', the 'symbols'
with no corresponding 'values' will be bound to <a href="nil.htm">NIL</a>.
<nobr>The variables</nobr> will be unbound after the execution of 'progv'.
<nobr>The value</nobr> of the last 'expr' will be returned as the result of
'progv'. <nobr>If there</nobr> are no 'exprs',
<a href="nil.htm">NIL</a> is returned.</p>

<h2>Examples</h2>

<pre class="example">
&gt; (progv '(var) '(2)
    (print var)
    (print "two"))
2      <font color="#008844">; output of PRINT</font>
"two"  <font color="#008844">; output of PRINT</font>
"two"  <font color="#008844">; return value</font>

&gt; (setq a "beginning")   <font color="#008844">; initialize A</font>
"beginning"

&gt; (progv '(a) '(during)  <font color="#008844">; bind A to a new value</font>
    (print a))
DURING  <font color="#008844">; output of PRINT</font>
DURING  <font color="#008844">; return value     restore A the original value</font>

&gt; (print a)
"beginning"              <font color="#008844">; prints the original value</font>
"beginning"

&gt; (progv '(no-way) '(no-how))
NIL

&gt; (progv)
<font color="#AA0000">error: too few arguments</font>
</pre>

<p><b>Note:</b> 'progv' is different from
<nobr><a href="prog.htm">prog</a></nobr>, which allows symbols and
initialization forms, in that 'progv' allows its 'symbols' and 'values' to
be evaluated. This allows you to pass in forms that generate the 'symbols'
and their 'values'.</p>

<p><b>Note:</b> <nobr><a href="prog1.htm">prog1</a></nobr>,
<nobr><a href="prog2.htm">prog2</a></nobr>, <a href="progn.htm">progn</a>
and 'progv' do not allow the use of <a href="return.htm">return</a> or
<a href="go.htm">go</a> or tags for <a href="go.htm">go</a>.</p>

<p><b>Important:</b> In contrast to all other binding constructs, 'progv'
binds global variables and not lexical variables, so 'progv' behaves
like:</p>

<pre class="example">
(defun <font color="#0000CC">progv</font> (symbols values &amp;rest body)  <font color="#008844">; this function does</font>
  (push symbol-values <font color="#AA5500">*internal-stack*</font>)   <font color="#008844">; not really work,</font>
  (setq symbols values)                   <font color="#008844">; it only demonstates</font>
  (prog1                                  <font color="#008844">; the principle</font>
    (eval body)
    (setq symbol-values (pop <font color="#AA5500">*internal-stack*</font>))))
</pre>

<p>Variables bound by 'progv' can be manipulated by global functions
including <nobr><a href="symbol-value.htm">symbol-value</a></nobr>.
<nobr>All changes</nobr> to the 'progv' variables by other functions, called
in the 'progv' body, will be lost after 'progv' is finished, because the
original value from the beginning of 'progv' will be restored. This can be
good or bad, depending on the situation.</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>