~ chicken-core (chicken-5) 0bdfbe1e04238aaf5f4f670838e8aa34e9b466a4


commit 0bdfbe1e04238aaf5f4f670838e8aa34e9b466a4
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Sun May 12 22:36:39 2013 +0200
Commit:     Christian Kellermann <ckeen@pestilenz.org>
CommitDate: Sat Jun 29 20:50:17 2013 +0200

    Add "require-extension-for-syntax"
    
    A more intuitive form of the often occurring idiom
    
      (begin-for-syntax (require-library ...))
      (import-for-syntax ...)
    
    For consistency and as a slightly shorter variant, "use-for-syntax"
    is also provided as an alias.
    
    Signed-off-by: Peter Bex <peter.bex@xs4all.nl>
    Signed-off-by: Christian Kellermann <ckeen@pestilenz.org>

diff --git a/NEWS b/NEWS
index 09f65b41..d92b5cb0 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,9 @@
     inlining could lead to non-termination of the compiler (thanks to
     Andrei Barbu).
 
+- Syntax expander
+  - added "require-extension-for-syntax" and "use-for-syntax".
+
 - Core libraries
   - read-line no longer returns trailing CRs in rare cases on TCP ports (#568)
   - write and pp now correctly use escape sequences for control characters
diff --git a/chicken-syntax.scm b/chicken-syntax.scm
index 9b3e91d8..06570db5 100644
--- a/chicken-syntax.scm
+++ b/chicken-syntax.scm
@@ -1082,6 +1082,13 @@
     (##sys#check-syntax 'use x '(_ . #(_ 0)))
     `(##core#require-extension ,(cdr x) #t))))
 
+(##sys#extend-macro-environment
+ 'use-for-syntax '()
+ (##sys#er-transformer
+  (lambda (x r c)
+    (##sys#check-syntax 'use-for-syntax x '(_ . #(_ 0)))
+    `(,(r 'require-extension-for-syntax) ,@(cdr x)))))
+
 
 ;;; compiler syntax
 
diff --git a/eval.scm b/eval.scm
index caf069d3..3d571a9b 100644
--- a/eval.scm
+++ b/eval.scm
@@ -1413,6 +1413,7 @@
        (if (memq (car s)
 		 '(import 
 		    require-extension 
+		    require-extension-for-syntax
 		    require-library 
 		    begin-for-syntax
 		    export 
diff --git a/expand.scm b/expand.scm
index ea53d6b3..d5f3652f 100644
--- a/expand.scm
+++ b/expand.scm
@@ -1379,6 +1379,13 @@
     (let ((ids (cdr x)))
       `(##core#require-extension ,ids #t) ) ) ) )
 
+(##sys#extend-macro-environment
+ 'require-extension-for-syntax
+ '()
+ (##sys#er-transformer
+  (lambda (x r c)
+    `(,(r 'begin-for-syntax) (,(r 'require-extension) ,@(cdr x))))))
+
 (##sys#extend-macro-environment
  'module
  '()
diff --git a/manual/Non-standard macros and special forms b/manual/Non-standard macros and special forms
index c6865547..ee222838 100644
--- a/manual/Non-standard macros and special forms	
+++ b/manual/Non-standard macros and special forms	
@@ -43,8 +43,6 @@ defined:
 * {{(srfi NUMBER ...)}} is required for SRFI-55 compatibility and is fully implemented
 * {{(version ID NUMBER)}} is equivalent to {{ID}}, but checks at compile-time whether the extension named {{ID}} is installed and whether its version is equal or higher than {{NUMBER}}. {{NUMBER}} may be a string or a number, the comparison is done lexicographically (using {{string>=?}}).
 
-See also: {{set-extension-specifier!}}
-
 ==== require-extension
 
 <macro>(require-extension ID ...)</macro>
@@ -62,6 +60,24 @@ This implementation of {{require-extension}} is compliant with [[http://srfi.sch
 
 {{use}} is just a shorter alias for {{require-extension}}.
 
+==== require-extension-for-syntax
+
+<macro>(require-extension-for-syntax ID ...)</macro>
+
+An abbreviation for the idiom:
+
+<enscript highlight=scheme>
+(begin-for-syntax (require-library ID ...))  ; load extension at expansion-time
+(import-for-syntax ID ...)                   ; import extension for use in syntax-transformers
+</enscript>
+
+
+==== use-for-syntax
+
+<macro>(use-for-syntax ID ...)</macro>
+
+{{use}} is just a shorter alias for {{require-extension-for-syntax}} (which is quite a mouthful).
+
 
 === Binding forms for optional arguments
 
Trap