fix #273
This commit is contained in:
parent
e2ad39074b
commit
324445f483
|
@ -1,7 +1,10 @@
|
||||||
(import (scheme base)
|
(import (scheme base)
|
||||||
(picrin macro))
|
(picrin macro)
|
||||||
|
(picrin test))
|
||||||
|
|
||||||
(define-syntax aif
|
(test-begin)
|
||||||
|
|
||||||
|
(define-macro aif
|
||||||
(ir-macro-transformer
|
(ir-macro-transformer
|
||||||
(lambda (form inject cmp)
|
(lambda (form inject cmp)
|
||||||
(let ((it (inject 'it))
|
(let ((it (inject 'it))
|
||||||
|
@ -11,11 +14,12 @@
|
||||||
`(let ((,it ,expr))
|
`(let ((,it ,expr))
|
||||||
(if ,it ,then ,else))))))
|
(if ,it ,then ,else))))))
|
||||||
|
|
||||||
(aif (member 'b '(a b c)) (car it) #f)
|
(test 'b
|
||||||
|
(aif (member 'b '(a b c)) (car it) #f))
|
||||||
|
|
||||||
;;; test hygiene begin
|
;;; test hygiene begin
|
||||||
|
|
||||||
(define-syntax mif
|
(define-macro mif
|
||||||
(ir-macro-transformer
|
(ir-macro-transformer
|
||||||
(lambda (form inject cmp)
|
(lambda (form inject cmp)
|
||||||
(let ((expr (car (cdr form)))
|
(let ((expr (car (cdr form)))
|
||||||
|
@ -24,12 +28,14 @@
|
||||||
`(let ((it ,expr))
|
`(let ((it ,expr))
|
||||||
(if it ,then ,else))))))
|
(if it ,then ,else))))))
|
||||||
|
|
||||||
(let ((if 42))
|
(test 2
|
||||||
(mif 1 2 3))
|
(let ((if 42))
|
||||||
|
(mif 1 2 3)))
|
||||||
; => 2
|
; => 2
|
||||||
|
|
||||||
(let ((it 42))
|
(test 42
|
||||||
(mif 1 it 2))
|
(let ((it 42))
|
||||||
|
(mif 1 it 2)))
|
||||||
; => 42
|
; => 42
|
||||||
|
|
||||||
;;; end
|
;;; end
|
||||||
|
@ -38,10 +44,10 @@
|
||||||
|
|
||||||
;;; test core syntax begin
|
;;; test core syntax begin
|
||||||
|
|
||||||
(mif 'a 'b 'c)
|
(test 'b (mif 'a 'b 'c))
|
||||||
; => b
|
; => b
|
||||||
|
|
||||||
(define-syntax loop
|
(define-macro loop
|
||||||
(ir-macro-transformer
|
(ir-macro-transformer
|
||||||
(lambda (expr inject cmp)
|
(lambda (expr inject cmp)
|
||||||
(let ((body (cdr expr)))
|
(let ((body (cdr expr)))
|
||||||
|
@ -51,14 +57,16 @@
|
||||||
,@body (f))))))))
|
,@body (f))))))))
|
||||||
|
|
||||||
(define a 1)
|
(define a 1)
|
||||||
(loop
|
(test #f
|
||||||
(if (= a 2) (exit #f))
|
(loop
|
||||||
(set! a 2))
|
(if (= a 2) (exit #f))
|
||||||
|
(set! a 2)))
|
||||||
; => #f
|
; => #f
|
||||||
|
|
||||||
(loop
|
(test #f
|
||||||
(define a 1)
|
(loop
|
||||||
(if (= a 1) (exit #f)))
|
(define a 1)
|
||||||
|
(if (= a 1) (exit #f))))
|
||||||
; => #f
|
; => #f
|
||||||
|
|
||||||
;;; end
|
(test-end)
|
||||||
|
|
Loading…
Reference in New Issue