| 1 |
<html><head> |
| 2 |
|
| 3 |
<title>Nyquist</title> |
| 4 |
|
| 5 |
<style type="text/css"> |
| 6 |
.example { |
| 7 |
color: #000000; |
| 8 |
background-color: #F5F5F5; |
| 9 |
padding: 8px; |
| 10 |
border: #808080; |
| 11 |
border-style: solid; |
| 12 |
border-width: 1px; |
| 13 |
width:auto; |
| 14 |
} |
| 15 |
.button { |
| 16 |
color: #000000; |
| 17 |
background-color: #F5F5F5; |
| 18 |
padding-top: 1px; |
| 19 |
padding-bottom: 1px; |
| 20 |
padding-left: 4px; |
| 21 |
padding-right: 8px; |
| 22 |
border: #808080; |
| 23 |
border-style: solid; |
| 24 |
border-width: 1px; |
| 25 |
white-space: pre; |
| 26 |
} |
| 27 |
.box { |
| 28 |
color: #000000; |
| 29 |
padding-top: 4px; |
| 30 |
padding-bottom: 4px; |
| 31 |
padding-left: 16px; |
| 32 |
padding-right: 16px; |
| 33 |
border: #808080; |
| 34 |
border-style: solid; |
| 35 |
border-width: 1px; |
| 36 |
} |
| 37 |
</style> |
| 38 |
|
| 39 |
</head> |
| 40 |
|
| 41 |
<body> |
| 42 |
|
| 43 |
<a href="../start.htm">Nyquist / XLISP 2.0</a> - |
| 44 |
<a href="../manual/contents.htm">Contents</a> | |
| 45 |
<a href="tutorials.htm">Tutorials</a> | |
| 46 |
<a href="../examples/examples.htm">Examples</a> | |
| 47 |
<a href="../reference/reference-index.htm">Reference</a> |
| 48 |
|
| 49 |
<hr> |
| 50 |
|
| 51 |
<h1>Nyquist</h1> |
| 52 |
|
| 53 |
<hr> |
| 54 |
|
| 55 |
<ul> |
| 56 |
<li><nobr><a href="#debugger-shortcuts">Debugger Shortcuts</a></nobr></li> |
| 57 |
<li><nobr><a href="#grindef">grindef</a> - print the function definition of a closure</nobr></li> |
| 58 |
<li><nobr><a href="#args">args</a> - print the argument list of a closure</nobr></li> |
| 59 |
<li><nobr><a href="#setfn">setfn</a> - define 'alias' names for functions</nobr></li> |
| 60 |
<li><nobr><a href="#display">display</a> - framework for debug messages</nobr></li> |
| 61 |
</ul> |
| 62 |
|
| 63 |
<p>This page will not save you from reading the Nyquist manual, it's a list |
| 64 |
of things I find useful but frequently have to look them up in the manuals |
| 65 |
when I haven't worked with Nyquist for a while. Many more useful tricks can |
| 66 |
be found in the 'Developing and Debugging in Nyquist' chapter in the Nyquist |
| 67 |
manual.</p> |
| 68 |
|
| 69 |
<a name="debugger-shortcuts"></a> |
| 70 |
|
| 71 |
<hr> |
| 72 |
|
| 73 |
<h2>Debugger Shortcuts</h2> |
| 74 |
|
| 75 |
<hr> |
| 76 |
|
| 77 |
<p>Some Nyquist/XLISP debugger shortcuts, defined in 'xlinit.lsp' and |
| 78 |
'misc.lsp':</p> |
| 79 |
|
| 80 |
<p><table cellpadding="0" cellspacing="0"><tbody> |
| 81 |
<tr> |
| 82 |
<td><nobr><code> </code></nobr></td> |
| 83 |
<td valign="top"> |
| 84 |
<table cellpadding="0" cellspacing="0" width="100%"><tbody> |
| 85 |
<tr valign="top"> |
| 86 |
<td class="button"><nobr><code>(bt)</code></nobr></td> |
| 87 |
</tr> |
| 88 |
</tbody></table> |
| 89 |
</td> |
| 90 |
<td><nobr> → </nobr></td> |
| 91 |
<td width="100%"><a href="../reference/baktrace.htm">baktrace</a></td> |
| 92 |
</tr> |
| 93 |
<tr> |
| 94 |
<td height="2px"></td> |
| 95 |
</tr> |
| 96 |
<tr> |
| 97 |
<td><nobr><code> </code></nobr></td> |
| 98 |
<td valign="top"> |
| 99 |
<table cellpadding="0" cellspacing="0" width="100%"><tbody> |
| 100 |
<tr valign="top"> |
| 101 |
<td class="button"><nobr><code>(co)</code></nobr></td> |
| 102 |
</tr> |
| 103 |
</tbody></table> |
| 104 |
</td> |
| 105 |
<td><nobr> → </nobr></td> |
| 106 |
<td width="100%"><a href="../reference/continue.htm">continue</a></td> |
| 107 |
</tr> |
| 108 |
<tr> |
| 109 |
<td height="2px"></td> |
| 110 |
</tr> |
| 111 |
<tr> |
| 112 |
<td><nobr><code> </code></nobr></td> |
| 113 |
<td valign="top"> |
| 114 |
<table cellpadding="0" cellspacing="0" width="100%"><tbody> |
| 115 |
<tr valign="top"> |
| 116 |
<td class="button"><nobr><code>(top)</code></nobr></td> |
| 117 |
</tr> |
| 118 |
</tbody></table> |
| 119 |
</td> |
| 120 |
<td><nobr> → </nobr></td> |
| 121 |
<td width="100%"><a href="../reference/top-level.htm">top-level</a></td> |
| 122 |
</tr> |
| 123 |
<tr> |
| 124 |
<td><nobr><font size="-2"> </font></nobr></td> |
| 125 |
</tr> |
| 126 |
<tr> |
| 127 |
<td><nobr><code> </code></nobr></td> |
| 128 |
<td valign="top"> |
| 129 |
<table cellpadding="0" cellspacing="0" width="100%"><tbody> |
| 130 |
<tr valign="top"> |
| 131 |
<td class="button"><nobr><code>(res)</code></nobr></td> |
| 132 |
</tr> |
| 133 |
</tbody></table> |
| 134 |
</td> |
| 135 |
<td><nobr> → </nobr></td> |
| 136 |
<td width="100%"><a href="../reference/clean-up.htm">clean-up</a></td> |
| 137 |
</tr> |
| 138 |
<tr> |
| 139 |
<td height="2px"></td> |
| 140 |
</tr> |
| 141 |
<tr> |
| 142 |
<td><nobr><code> </code></nobr></td> |
| 143 |
<td valign="top"> |
| 144 |
<table cellpadding="0" cellspacing="0" width="100%"><tbody> |
| 145 |
<tr valign="top"> |
| 146 |
<td class="button"><nobr><code>(up)</code></nobr></td> |
| 147 |
</tr> |
| 148 |
</tbody></table> |
| 149 |
</td> |
| 150 |
<td><nobr> → </nobr></td> |
| 151 |
<td width="100%"><a href="../reference/clean-up.htm">clean-up</a></td> |
| 152 |
</tr> |
| 153 |
</tbody></table></p> |
| 154 |
|
| 155 |
<p>The debugger commands only work if |
| 156 |
<a href="../reference/global-breakenable.htm">*breakenable*</a> |
| 157 |
is <nobr>non-<a href="../reference/nil.htm">NIL</a></nobr>:</p> |
| 158 |
|
| 159 |
<p><table cellpadding="0" cellspacing="0"><tbody> |
| 160 |
<tr> |
| 161 |
<td><nobr><code> </code></nobr></td> |
| 162 |
<td valign="top"> |
| 163 |
<table cellpadding="0" cellspacing="0" width="100%"><tbody> |
| 164 |
<tr valign="top"> |
| 165 |
<td class="button"><nobr><code>(bkon)</code></nobr></td> |
| 166 |
</tr> |
| 167 |
</tbody></table> |
| 168 |
</td> |
| 169 |
<td><nobr> → </nobr></td> |
| 170 |
<td width="100%"><nobr>(setq |
| 171 |
<a href="../reference/global-breakenable.htm">*breakenable*</a> |
| 172 |
t)</nobr></td> |
| 173 |
</tr> |
| 174 |
<tr> |
| 175 |
<td height="2px"></td> |
| 176 |
</tr> |
| 177 |
<tr> |
| 178 |
<td><nobr><code> </code></nobr></td> |
| 179 |
<td valign="top"> |
| 180 |
<table cellpadding="0" cellspacing="0" width="100%"><tbody> |
| 181 |
<tr valign="top"> |
| 182 |
<td class="button"><nobr><code>(bkoff)</code></nobr></td> |
| 183 |
</tr> |
| 184 |
</tbody></table> |
| 185 |
</td> |
| 186 |
<td><nobr> → </nobr></td> |
| 187 |
<td width="100%"><nobr>(setq |
| 188 |
<a href="../reference/global-breakenable.htm">*breakenable*</a> |
| 189 |
nil)</nobr></td> |
| 190 |
</tr> |
| 191 |
</tbody></table></p> |
| 192 |
|
| 193 |
<p>You can make your own |
| 194 |
<a href="../reference/global-tracenable.htm">*tracenable*</a> |
| 195 |
shortcuts like shown here:</p> |
| 196 |
|
| 197 |
<pre class="example"> |
| 198 |
(defun <font color="#0000CC">tron</font> () |
| 199 |
(setq <font color="#AA5500">*tracenable*</font> t)) |
| 200 |
|
| 201 |
(defun <font color="#0000CC">troff</font> () |
| 202 |
(setq <font color="#AA5500">*tracenable*</font> nil)) |
| 203 |
</pre> |
| 204 |
|
| 205 |
<p>See also:</p> |
| 206 |
|
| 207 |
<ul> |
| 208 |
<li><nobr>XLISP 2.0 Manual → <a href="../manual/xlisp.htm#break-loop">Break Loop</a></nobr></li> |
| 209 |
</ul> |
| 210 |
|
| 211 |
<p><nobr> <a href="#top">Back to top</a></nobr></p> |
| 212 |
|
| 213 |
<a name="grindef"></a> |
| 214 |
|
| 215 |
<hr> |
| 216 |
|
| 217 |
<h2>grindef</h2> |
| 218 |
|
| 219 |
<hr> |
| 220 |
|
| 221 |
<p>The 'grindef' function prints the Lisp code of a |
| 222 |
<a href="../manual/xlisp.htm#data-types">closure</a> <nobr>[user-defined</nobr> |
| 223 |
function or macro]:</p> |
| 224 |
|
| 225 |
<pre class="example"> |
| 226 |
(defun <font color="#0000CC">grindef</font> (e) |
| 227 |
(pprint (get-lambda-expression (symbol-function e)))) |
| 228 |
</pre> |
| 229 |
|
| 230 |
<p>Example:</p> |
| 231 |
|
| 232 |
<pre class="example"> |
| 233 |
> (grindef 'grindef) |
| 234 |
(LAMBDA (E) |
| 235 |
(PPRINT (GET-LAMBDA-EXPRESSION (SYMBOL-FUNCTION E)))) |
| 236 |
NIL |
| 237 |
</pre> |
| 238 |
|
| 239 |
<p><nobr> <a href="#top">Back to top</a></nobr></p> |
| 240 |
|
| 241 |
<a name="args"></a> |
| 242 |
|
| 243 |
<hr> |
| 244 |
|
| 245 |
<h2>args</h2> |
| 246 |
|
| 247 |
<hr> |
| 248 |
|
| 249 |
<p>The 'args' function prints the name and the argument variables of a |
| 250 |
<a href="../manual/xlisp.htm#data-types">closure</a> <nobr>[user-defined</nobr> |
| 251 |
function or macro]:</p> |
| 252 |
|
| 253 |
<pre class="example"> |
| 254 |
(defun <font color="#0000CC">args</font> (e) |
| 255 |
(pprint (cons e (second (get-lambda-expression (symbol-function e)))))) |
| 256 |
</pre> |
| 257 |
|
| 258 |
<p>Example:</p> |
| 259 |
|
| 260 |
<pre class="example"> |
| 261 |
> (args 'args) |
| 262 |
(ARGS E) |
| 263 |
NIL |
| 264 |
</pre> |
| 265 |
|
| 266 |
<p><nobr> <a href="#top">Back to top</a></nobr></p> |
| 267 |
|
| 268 |
<a name="setfn"></a> |
| 269 |
|
| 270 |
<hr> |
| 271 |
|
| 272 |
<h2>setfn</h2> |
| 273 |
|
| 274 |
<hr> |
| 275 |
|
| 276 |
<p>The 'setfn' macro defines 'alias' names for functions:</p> |
| 277 |
|
| 278 |
<pre class="example"> |
| 279 |
(defmacro <font color="#0000CC">setfn</font> (a b) |
| 280 |
`(setf (symbol-function ',a) (symbol-function ',b))) |
| 281 |
</pre> |
| 282 |
|
| 283 |
<p>Examples from 'xlinit.lsp':</p> |
| 284 |
|
| 285 |
<pre class="example"> |
| 286 |
(setfn co continue) |
| 287 |
(setfn top top-level) |
| 288 |
(setfn res clean-up) |
| 289 |
(setfn up clean-up) |
| 290 |
</pre> |
| 291 |
|
| 292 |
<p><nobr> <a href="#top">Back to top</a></nobr></p> |
| 293 |
|
| 294 |
<a name="display"></a> |
| 295 |
|
| 296 |
<hr> |
| 297 |
|
| 298 |
<h2>display</h2> |
| 299 |
|
| 300 |
<hr> |
| 301 |
|
| 302 |
<p>'display' is a debugging macro, defined in 'xlinit.lsp'.</p> |
| 303 |
|
| 304 |
<pre class="example"> |
| 305 |
(defmacro <font color="#0000CC">display-macro</font> (label &rest items) |
| 306 |
(let ($res$) |
| 307 |
(dolist ($item$ items) |
| 308 |
(setq $res$ (cons |
| 309 |
`(format t <font color="#880000">"~A = ~A "</font> ',$item$ ,$item$) |
| 310 |
$res$))) |
| 311 |
(append (list 'let nil `(format t <font color="#880000">"~A : "</font> ,label)) |
| 312 |
(reverse $res$) |
| 313 |
'((terpri))))) |
| 314 |
|
| 315 |
(defun <font color="#0000CC">display-on</font> () |
| 316 |
(setfn display display-macro) t) |
| 317 |
|
| 318 |
(defun <font color="#0000CC">display-off</font> () |
| 319 |
(setfn display or) nil) |
| 320 |
</pre> |
| 321 |
|
| 322 |
<p>Usage:</p> |
| 323 |
|
| 324 |
<pre class="example"> |
| 325 |
(display <font color="#880000">"heading"</font> <font color="#0000CC">var1 var2</font> ...) |
| 326 |
</pre> |
| 327 |
|
| 328 |
<p>expands into:</p> |
| 329 |
|
| 330 |
<pre class="example"> |
| 331 |
(let () |
| 332 |
(format t "~A: " <font color="#880000">"heading"</font>) |
| 333 |
(format t "~A = ~A " ',<font color="#0000CC">var1</font> ,<font color="#0000CC">var1</font>) |
| 334 |
(format t "~A = ~A " ',<font color="#0000CC">var2</font> ,<font color="#0000CC">var2</font>) |
| 335 |
... ) |
| 336 |
</pre> |
| 337 |
|
| 338 |
<p>and then prints:</p> |
| 339 |
|
| 340 |
<pre class="example"> |
| 341 |
<font color="#0000CC">heading</font> : <font color="#0000CC">VAR1</font> = <font color="#0000CC">value1 VAR2</font> = <font color="#0000CC">value2</font> ... |
| 342 |
</pre> |
| 343 |
|
| 344 |
<p>Using the 'display' macro in a function like shown here:</p> |
| 345 |
|
| 346 |
<pre class="example"> |
| 347 |
(defun <font color="#0000CC">hello</font> () |
| 348 |
(let ((local-var 'hello)) |
| 349 |
(display <font color="#880000">"debug message"</font> local-var) |
| 350 |
local-var)) <font color="#008844">; return value</font> |
| 351 |
</pre> |
| 352 |
|
| 353 |
<p>Now the '<nobr>debug message</nobr>' can be switched on and off without |
| 354 |
changing the code:</p> |
| 355 |
|
| 356 |
<pre class="example"> |
| 357 |
> (display-on) |
| 358 |
T |
| 359 |
|
| 360 |
> (hello) |
| 361 |
debug message : LOCAL-VAR = HELLO |
| 362 |
HELLO |
| 363 |
|
| 364 |
> (display-off) |
| 365 |
NIL |
| 366 |
|
| 367 |
> (hello) |
| 368 |
HELLO |
| 369 |
</pre> |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
<p><nobr> <a href="#top">Back to top</a></nobr></p> |
| 374 |
|
| 375 |
<hr> |
| 376 |
|
| 377 |
<a href="../start.htm">Nyquist / XLISP 2.0</a> - |
| 378 |
<a href="../manual/contents.htm">Contents</a> | |
| 379 |
<a href="tutorials.htm">Tutorials</a> | |
| 380 |
<a href="../examples/examples.htm">Examples</a> | |
| 381 |
<a href="../reference/reference-index.htm">Reference</a> |
| 382 |
|
| 383 |
</body></html> |