diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/simple-macro.html | |
new repository
Diffstat (limited to 'devdocs/elisp/simple-macro.html')
| -rw-r--r-- | devdocs/elisp/simple-macro.html | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/devdocs/elisp/simple-macro.html b/devdocs/elisp/simple-macro.html new file mode 100644 index 00000000..b2e75c46 --- /dev/null +++ b/devdocs/elisp/simple-macro.html @@ -0,0 +1,11 @@ + <h3 class="section">A Simple Example of a Macro</h3> <p>Suppose we would like to define a Lisp construct to increment a variable value, much like the <code>++</code> operator in C. We would like to write <code>(inc x)</code> and have the effect of <code>(setq x (1+ x))</code>. Here’s a macro definition that does the job: </p> <div class="example"> <pre class="example">(defmacro inc (var) + (list 'setq var (list '1+ var))) +</pre> +</div> <p>When this is called with <code>(inc x)</code>, the argument <var>var</var> is the symbol <code>x</code>—<em>not</em> the <em>value</em> of <code>x</code>, as it would be in a function. The body of the macro uses this to construct the expansion, which is <code>(setq x (1+ x))</code>. Once the macro definition returns this expansion, Lisp proceeds to evaluate it, thus incrementing <code>x</code>. </p> <dl> <dt id="macrop">Function: <strong>macrop</strong> <em>object</em> +</dt> <dd><p>This predicate tests whether its argument is a macro, and returns <code>t</code> if so, <code>nil</code> otherwise. </p></dd> +</dl><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Simple-Macro.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Simple-Macro.html</a> + </p> +</div> |
