>From e3a8a14a95980f8607ada49dc78ed10b9d85410b Mon Sep 17 00:00:00 2001 From: felix Date: Sun, 12 May 2013 22:36:39 +0200 Subject: [PATCH] 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 --- NEWS | 3 +++ chicken-syntax.scm | 7 +++++++ eval.scm | 1 + expand.scm | 7 +++++++ manual/Non-standard macros and special forms | 20 ++++++++++++++++++-- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index be9d098..585ea55 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,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 9b3e91d..06570db 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 62227cd..963dd20 100644 --- a/eval.scm +++ b/eval.scm @@ -1410,6 +1410,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 b278ec0..4b69c1d 100644 --- a/expand.scm +++ b/expand.scm @@ -1372,6 +1372,13 @@ `(##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 '() (##sys#er-transformer diff --git a/manual/Non-standard macros and special forms b/manual/Non-standard macros and special forms index c686554..ee22283 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 (require-extension ID ...) @@ -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 + +(require-extension-for-syntax ID ...) + +An abbreviation for the idiom: + + +(begin-for-syntax (require-library ID ...)) ; load extension at expansion-time +(import-for-syntax ID ...) ; import extension for use in syntax-transformers + + + +==== use-for-syntax + +(use-for-syntax ID ...) + +{{use}} is just a shorter alias for {{require-extension-for-syntax}} (which is quite a mouthful). + === Binding forms for optional arguments -- 1.8.0.1