-
Notifications
You must be signed in to change notification settings - Fork 0
/
if-then-else.scm
38 lines (31 loc) · 900 Bytes
/
if-then-else.scm
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
34
35
36
37
;; useful macros
;; author: Damien Mattei
;; "if" "then" without "else"
;; (if-t (= 1 1) 'good) -> 'good
;; (if-t (= 1 1) 'good 'bad) -> 'bad
;; (if-t (= 1 1) 'good 'bad 'bof) -> 'bof
;; > (if-t (= 1 1) (display-nl 'good) (display-nl 'bad) (display-nl 'bof))
;; good
;; bad
;; bof
;; > (if-t (= 1 0) (display-nl 'good) (display-nl 'bad) (display-nl 'bof)) -> '()
(define-syntax if-t
(syntax-rules ()
((_ tst ev) (if tst ev '()))
((_ tst ev ...) (if tst (begin ev ...) '()))))
;; then and else do as begin-ners ;-)
;; (if-t #t (then "hello" "bye"))
;; "bye"
(define-syntax then
(syntax-rules ()
((_ ev) ev)
((_ ev ...) (begin ev ...))))
;; then and else do as BEGINners ;-)
(define-syntax then-block
(syntax-rules ()
((_ ev) ev)
((_ ev ...) (begin ev ...))))
(define-syntax else-block
(syntax-rules ()
((_ ev) ev)
((_ ev ...) (begin ev ...))))