| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 |
<HTML> |
| 3 |
<HEAD> |
| 4 |
<TITLE>Macro WITH-UNIQUE-NAMES</TITLE> |
| 5 |
<LINK REL="stylesheet" HREF="style.css" type="text/css"> |
| 6 |
</HEAD> |
| 7 |
<BODY> |
| 8 |
|
| 9 |
<p><i>Macro</i> <b>WITH-UNIQUE-NAMES</b></p><p><b>Syntax:</b></p><p> |
| 10 |
|
| 11 |
<b>with-unique-names</b> <i>({<i>var</i> | (<i>var</i> |
| 12 |
<i>prefix</i>)}<b>*</b>) <i>declaration</i><b>*</b> |
| 13 |
<i>form</i><b>*</b></i> => <i><i>result</i><b>*</b></i> |
| 14 |
|
| 15 |
|
| 16 |
</p><p><b>Arguments and Values:</b></p><p> |
| 17 |
<p><i>var</i>---a <a |
| 18 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#symbol"><i>symbol</i></a>; |
| 19 |
not <a |
| 20 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_e.htm#evaluate"><i>evaluate</i></a>d.</p> |
| 21 |
<p><i>prefix</i>---a <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#string_designator"><i>string designator</i></a>; not |
| 22 |
<a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_e.htm#evaluate"><i>evaluate</i></a>d. The default is <i>var</i>.</p> |
| 23 |
|
| 24 |
<p><i>declaration</i>---a <a href =" |
| 25 |
http://www.lispworks.com/documentation/HyperSpec/Body/sym_declare.html"><b>declare</b></a> |
| 26 |
<a |
| 27 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_e.htm#expression"><i>expression</i></a>; |
| 28 |
not <a |
| 29 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_e.htm#evaluate"><i>evaluate</i></a>d.</p> |
| 30 |
<p><i>form</i>---a <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#form"><i>form</i></a>.</p> |
| 31 |
<p><i>results</i>---the <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_v.htm#value"><i>value</i></a>s |
| 32 |
<a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_r.htm#return"><i>return</i></a>ed by the <i>form</i>s.</p> |
| 33 |
|
| 34 |
</p><p><b>Description:</b></p><p> <a |
| 35 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_e.htm#Execute"><i>Execute</i></a>s |
| 36 |
a series of <a |
| 37 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#form"><i>form</i></a>s |
| 38 |
with each |
| 39 |
<i>var</i> <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_b.htm#bound"><i>bound</i></a> to a <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#fresh"><i>fresh</i></a>, |
| 40 |
<a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_u.htm#uninterned"><i>uninterned</i></a> <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#symbol"><i>symbol</i></a>. The |
| 41 |
<a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_u.htm#uninterned"><i>uninterned</i></a> <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#symbol"><i>symbol</i></a> is created as if by |
| 42 |
a <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#call"><i>call</i></a> to <a href =" http://www.lispworks.com/documentation/HyperSpec/Body/fun_gensym.html"><b>gensym</b></a> with the |
| 43 |
<a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#string"><i>string</i></a> denoted by <i>prefix</i>---or, if |
| 44 |
<i>prefix</i> is not supplied, the <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#string"><i>string</i></a> |
| 45 |
|
| 46 |
denoted by <i>var</i>---as <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#argument"><i>argument</i></a>. |
| 47 |
<p></p> The <a |
| 48 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_v.htm#variable"><i>variable</i></a> |
| 49 |
<a |
| 50 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_b.htm#binding"><i>binding</i></a>s |
| 51 |
created are <a |
| 52 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lexical"><i>lexical</i></a> |
| 53 |
unless <a |
| 54 |
HREF="http://www.lispworks.com/documentation/HyperSpec/Body/dec_specia.htm#special"><b>special</b></a> |
| 55 |
|
| 56 |
<a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_d.htm#declaration"><i>declaration</i></a>s are specified. |
| 57 |
<p></p> |
| 58 |
The <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#form"><i>form</i></a>s are <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_e.htm#evaluate"><i>evaluate</i></a>d in order, and |
| 59 |
the <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_v.htm#value"><i>value</i></a>s of all but the last are discarded (that |
| 60 |
is, the body is an <a HREF="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_i.htm#implicit_progn"><i>implicit progn</i></a>). |
| 61 |
</p><p><b>Examples:</b></p><p> |
| 62 |
<pre> |
| 63 |
|
| 64 |
(with-unique-names (sym1) sym1) => #:SYM13142 |
| 65 |
(with-unique-names ((sym1 "SYM1-")) sym1) => #:SYM1-3143 |
| 66 |
(find-symbol "SYM1-3143") => NIL, NIL |
| 67 |
(with-unique-names ((sym #\Q)) sym) => #:Q3144 |
| 68 |
(with-unique-names ((sym1 :sym1-)) sym1) => #:SYM1-3145 |
| 69 |
(with-unique-names (sym1) (symbol-package sym1)) => NIL |
| 70 |
(with-unique-names (sym8) (eq sym8 sym8)) => T |
| 71 |
(with-unique-names (sym9) (set sym9 42) (symbol-value sym9)) => 42 |
| 72 |
</pre> |
| 73 |
|
| 74 |
</p><p><b>Side Effects:</b></p><p> |
| 75 |
Might increment <a href =" http://www.lispworks.com/documentation/HyperSpec/Body/var_stgensym-counterst.html"><b>*gensym-counter*</b></a> once for each |
| 76 |
<i>var</i>. |
| 77 |
</p><p><b>Affected by:</b></p><p> <a href =" |
| 78 |
http://www.lispworks.com/documentation/HyperSpec/Body/var_stgensym-counterst.html"><b>*gensym-counter*</b></a> |
| 79 |
|
| 80 |
</p><p><b>Exceptional Situations:</b></p><p> |
| 81 |
None. |
| 82 |
</p><p><b>See Also:</b></p><p> |
| 83 |
<a href =" http://www.lispworks.com/documentation/HyperSpec/Body/fun_gensym.html"><b>gensym</b></a>, <a href =" http://www.lispworks.com/documentation/HyperSpec/Body/speope_letcm_letst.html"><b>let</b></a></b> |
| 84 |
</p> |
| 85 |
</p> |
| 86 |
|
| 87 |
<p><b>Notes:</b> |
| 88 |
<p>This is an extension of the classic macro <b>with-gensyms</b>. In |
| 89 |
fact, cl-utilities also exports <b>with-gensyms</b>, and it can be |
| 90 |
used as usual. The exported <b>with-gensyms</b> is actually just an |
| 91 |
alias for <b>with-unique-names</b> which gives a warning at |
| 92 |
compile-time if the extensions of <b>with-unique-names</b> are used. |
| 93 |
|
| 94 |
<p>You are encouraged to use <b>with-unique-names</b> instead of |
| 95 |
<b>with-gensyms</b> because it is a little more flexible and because |
| 96 |
it tells what is going on rather than how it works. This is a somewhat |
| 97 |
controversial point, so go ahead and use whichever you like if you |
| 98 |
have an opinion on it. But if you're a newbie who honestly doesn't |
| 99 |
care, please use <b>with-unique-names</b>. |
| 100 |
|
| 101 |
<p class="footer"><hr><a href="index.html">Manual Index</a></p> |
| 102 |
|
| 103 |
</BODY> |
| 104 |
</HTML> |