File: meta-syntax-test.scm

package info (click to toggle)
chicken 5.3.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,892 kB
  • sloc: ansic: 580,083; lisp: 71,987; tcl: 1,445; sh: 588; makefile: 60
file content (51 lines) | stat: -rwxr-xr-x 1,412 bytes parent folder | download | duplicates (3)
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
;;;; meta-syntax-test.scm

;;
;; A module's syntax definitions should be accessible through either of
;; the following import forms:
;;
;;   (import-syntax-for-syntax (foo)) ; meta environment
;;
;;   (begin-for-syntax                ; compiler environment
;;     (import-syntax (foo)))         ; note that `import` will not work here
;;

(module foo (bar listify)
  (import scheme chicken.syntax)
  (begin-for-syntax
   (define (baz x) 
     (list (cadr x))))
  (define-syntax bar
    (er-macro-transformer
     (lambda (x r c)
       `(,(r 'list) (baz (list 1 ,(cadr x)))))))
  (begin-for-syntax
   (define-syntax call-it-123
     (syntax-rules ()
       ((_ x)
        '(x 'x 1 2 3)))))
  (define-syntax listify
    (er-macro-transformer
     (lambda (e r c)
       (call-it-123 list)))))

(module test-import-syntax-for-syntax (test)
  (import scheme chicken.syntax)
  (import-syntax-for-syntax (prefix foo foo:))
  (define-syntax test-import-syntax-for-syntax
    (er-macro-transformer
     (lambda (x r c)
       `(,(r 'quote) ,@(foo:bar 1 2)))))
  (define (test)
    (test-import-syntax-for-syntax)))

(module test-begin-for-syntax (test)
  (import scheme chicken.syntax)
  (begin-for-syntax
    (import-syntax (prefix foo foo:)))
  (define-syntax test-begin-for-syntax
    (er-macro-transformer
     (lambda (x r c)
       `(,(r 'quote) ,@(foo:bar 1 2)))))
  (define (test)
    (test-begin-for-syntax)))