~ chicken-core (chicken-5) 76c628545d3c903790ad831c3c836db4940d53c9
commit 76c628545d3c903790ad831c3c836db4940d53c9
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Mon May 24 23:11:42 2010 +0200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Mon May 24 23:11:42 2010 +0200
better check for redef of def. form
diff --git a/expand.scm b/expand.scm
index 043a6f3a..e5f9874a 100644
--- a/expand.scm
+++ b/expand.scm
@@ -1072,7 +1072,7 @@
(cond ((not (pair? head))
(##sys#check-syntax 'define form '(_ symbol . #(_ 0 1)))
(##sys#register-export head (##sys#current-module))
- (when (eq? (car x) head)
+ (when (c (r 'define) head)
(##sys#defjam-error x))
`(##core#set!
,head
@@ -1095,7 +1095,7 @@
(##sys#check-syntax 'define-syntax head 'symbol)
(##sys#check-syntax 'define-syntax body '#(_ 1))
(##sys#register-export head (##sys#current-module))
- (when (eq? (car form) head)
+ (when (c (r 'define-syntax) head)
(##sys#defjam-error form))
`(##core#define-syntax ,head ,(car body)))
(else
diff --git a/manual/Non-standard macros and special forms b/manual/Non-standard macros and special forms
index 1f774065..22458309 100644
--- a/manual/Non-standard macros and special forms
+++ b/manual/Non-standard macros and special forms
@@ -307,6 +307,7 @@ Defines what is usually called a ''compiler macro'' in Lisp: {{NAME}} should be
name of a globally or locally bound procedure. Any direct call to this procedure
will be transformed before compilation, which allows arbitrary rewritings
of function calls.
+
{{TRANSFORMER}} can be a {{syntax-rules}} expression or an explicit-renaming transforme
procedure. Returning the original form in an explicit-renaming macro or simply
"falling trough" all patterns in a {{syntax-rules}} form will keep the original
@@ -315,7 +316,8 @@ expression and compile it normally.
In the interpreter this form does nothing and returns an unspecified value.
Compiler-syntax is always local to the current compilation unit and can not be
-exported.
+exported. Compiler-syntax defined inside a module is not visible outside of that
+module.
{{define-compiler-syntax}} should only be used at top-level. Local compiler-syntax
can be defined with {{let-compiler-syntax}}.
diff --git a/tests/compiler-syntax-tests.scm b/tests/compiler-syntax-tests.scm
index c22640c9..77f31ca2 100644
--- a/tests/compiler-syntax-tests.scm
+++ b/tests/compiler-syntax-tests.scm
@@ -73,3 +73,15 @@
(assert (eq? 'zzz (pif)))
(print (xxx))
(assert (eq? 'zzz (xxx))))
+
+;;; local to module
+
+(define (f1 x) x)
+
+(module m3 ()
+(import scheme chicken)
+(define-compiler-syntax f1
+ (syntax-rules () ((_ x) (list x))))
+)
+
+(assert (= 2 (f1 2)))
diff --git a/tests/syntax-tests.scm b/tests/syntax-tests.scm
index 19097481..a052a619 100644
--- a/tests/syntax-tests.scm
+++ b/tests/syntax-tests.scm
@@ -433,3 +433,17 @@
(assert (= 3 (f1)))
(assert (= 9 v1))
(assert (= 10 v2))
+
+
+;;; redefining definition forms (disabled, since we can not catch this error easily)
+
+#|
+(module m0a () (import chicken) (reexport (only scheme define)))
+(module m0b () (import chicken) (reexport (only scheme define-syntax)))
+
+(module m1 ()
+(import (prefix scheme s:) (prefix m0b m:))
+;(s:define m:define 1)
+(s:define-syntax s:define-syntax (syntax-rules ()))
+)
+|#
Trap