Here is a very simple macro example which shows some of the features: destructuring, substituting into a template to produce a form,
using (gensym) to invent a needed symbol. The purpose of this macro
is to introduce a very simple language feature; a loop construct
which executes a sequence of forms N times, where N is a parameter.
We implement our new kind of loop, which we will call ``ntimes''
in terms of the Common LISP ``dotimes' loop:
(defmacro ntimes (count . forms) (let ((counter (gensym)))
`(dotimes
(,counter ,count) ,@forms)))
(define-syntax ntimes
(syntax-rules ()
[(_ count forms ...)
(do ((n 0 (+ n 1)))
((= n count))
forms ...)]))
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 418 |
Nodes: | 16 (2 / 14) |
Uptime: | 46:33:33 |
Calls: | 8,810 |
Calls today: | 6 |
Files: | 13,307 |
Messages: | 5,972,669 |