add macros
This commit is contained in:
parent
41a04a9d94
commit
3570252c1b
1 changed files with 40 additions and 0 deletions
40
11_extensibility.scm
Normal file
40
11_extensibility.scm
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
;; -*- geiser-scheme-implementation: guile -*-
|
||||||
|
|
||||||
|
(if (our-test)
|
||||||
|
(begin
|
||||||
|
(do-thing-1)
|
||||||
|
(do-thing-2)))
|
||||||
|
|
||||||
|
(define (when test . body)
|
||||||
|
`(if ,test
|
||||||
|
,(cons 'begin body)))
|
||||||
|
|
||||||
|
(when '(our-test)
|
||||||
|
'(do-thing-1)
|
||||||
|
'(do-thing-2))
|
||||||
|
; (if (our-test) (begin (do-thing-1) (do-thing-2)))
|
||||||
|
|
||||||
|
(define-macro (when test . body)
|
||||||
|
`(if ,test
|
||||||
|
,(cons 'begin body)))
|
||||||
|
|
||||||
|
(when (our-test)
|
||||||
|
(do-thing-1)
|
||||||
|
(do-thing-2))
|
||||||
|
|
||||||
|
(define-syntax-rule (when test body ...)
|
||||||
|
(if test
|
||||||
|
(begin body ...)))
|
||||||
|
|
||||||
|
(define-syntax-rule (for (item lst) body ...)
|
||||||
|
(for-each (lambda (item)
|
||||||
|
body ...)
|
||||||
|
lst))
|
||||||
|
|
||||||
|
(for (str '("strawberries" "bananas" "grapes"))
|
||||||
|
(display
|
||||||
|
(string-append "I just love "
|
||||||
|
(string-upcase str)
|
||||||
|
"!!!\n")))
|
||||||
|
|
||||||
|
; #<unspecified>
|
Loading…
Reference in a new issue