aboutsummaryrefslogtreecommitdiffstats
path: root/macrotst.scm
blob: b5b50460240e0ad66a4d4ac56e34f026de9a2470 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;;;"macrotst.scm" Test for R4RS Macros
;;; From Revised^4 Report on the Algorithmic Language Scheme
;;; Editors: William Clinger and Jonathon Rees
;
; We intend this report to belong to the entire Scheme community, and so
; we grant permission to copy it in whole or in part without fee.  In
; particular, we encourage implementors of Scheme to use this report as
; a starting point for manuals and other documentation, modifying it as
; necessary.

;;; To run this code type
;;; (require 'macro)
;;; (macro:load "macrotst.scm")

(write "this code should print now, outer, and 7") (newline)

(write
 (let-syntax ((when (syntax-rules ()
				  ((when test stmt1 stmt2 ...)
				   (if test
				       (begin stmt1
					      stmt2 ...))))))
   (let ((if #t))
     (when if (set! if 'now))
     if)))
(newline)
;;;			==> now

(write
 (let ((x 'outer))
   (let-syntax ((m (syntax-rules () ((m) x))))
     (let ((x 'inner))
       (m)))))
(newline)
;;;			==> outer
(write
 (letrec-syntax
  ((or (syntax-rules ()
	 ((or) #f)
	 ((or e) e)
	 ((or e1 e2 ...)
	  (let ((temp e1))
	    (if temp temp (or e2 ...)))))))
  (let ((x #f)
	(y 7)
	(temp 8)
	(let odd?)
	(if even?))
    (or x
	(let temp)
	(if y)
	y))))
(newline)
;;;			==> 7