-
Notifications
You must be signed in to change notification settings - Fork 5
/
if.l
33 lines (32 loc) · 1.15 KB
/
if.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;--- super if macro
; This macro allow the following forms:
; (if a then b) ==> (cond (a b))
; (if a thenret) ==> (cond (a))
; (if a then b else c) ==> (cond (a b) (t c))
; (if a then b b2 ==> (cond (a b b2) (c d d2) (t e))
; elseif c then d d2
; else e)
;
;
(defun if macro (lis)
(prog (majlis minlis revl)
(do ((revl (reverse lis) (cdr revl)))
((null revl))
(cond ((eq (car revl) 'else)
(setq majlis `((t ,@minlis) ,@majlis)
minlis nil))
((or (eq (car revl) 'then) (eq (car revl) 'thenret))
(setq revl (cdr revl)
majlis `((,(car revl) ,@minlis) ,@majlis)
minlis nil))
((eq (car revl) 'elseif))
((eq (car revl) 'if)
(setq majlis `(cond ,@majlis)))
(t (setq minlis `( ,(car revl) ,@minlis)))))
; we displace the previous macro, that is we actually replace
; the if list structure with the corresponding cond, meaning
; that the expansion is done only once
(rplaca lis (car majlis))
(rplacd lis (cdr majlis))
(return majlis)))
;--- msg : print a message consisting of strings and values