Macros let you abstract control structures. For example,
with a list (a b c d) you might want to compute
(f a b),(f b c),(f c d)
Another popular pattern is
(f a b),(f b c),(f c d)(f d a)
It is natural to define macros
* (dolinks (x y '(a b c d ) 'done)(print (cons x y)))
(A . B)
(B . C)
(C . D)
DONE
* (docycle (x y '(a b c d ) 'done)(print (cons x y)))
(A . B)
(B . C)
(C . D)
(D . A)
DONE
The alternative is to come up with cliches and use them
repeatedly in ones code. I've not done too well at coming up
with cliches taught enough to bear repeated typing; best so
far:
* (loop with list = '(a b c d)
for x = (car list) then y
and y in (cdr list)
do (print (cons x y)))
(A . B)
(B . C)
(C . D)
NIL
* (loop for (x . rest) on '(a b c d)
for y = (car rest)
when (null rest) do (setf y 'a)
do (print (cons x y)))
(A . B)
(B . C)
(C . D)
(D . A)
NIL
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 08:16:31 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
2 files (6,679K bytes) |
| Messages: | 264,942 |