summaryrefslogtreecommitdiff
path: root/doc/ref/api-macros.texi
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-09-02 11:42:44 +0200
committerAndy Wingo <wingo@pobox.com>2011-09-02 11:42:44 +0200
commitcd4171d012f0ef2291274b5a9b26854c0223921b (patch)
tree780e7aa3259fd621d314f02275782f1e6f9a060e /doc/ref/api-macros.texi
parent0c65f52c6d45f60e197fad7162d05c0fce89e817 (diff)
downloadguile-cd4171d012f0ef2291274b5a9b26854c0223921b.tar.gz
document define-syntax-rule
* doc/ref/api-macros.texi (Syntax Rules): Add define-syntax-rule.
Diffstat (limited to 'doc/ref/api-macros.texi')
-rw-r--r--doc/ref/api-macros.texi19
1 files changed, 18 insertions, 1 deletions
diff --git a/doc/ref/api-macros.texi b/doc/ref/api-macros.texi
index f0eeb6e7e..1167650a2 100644
--- a/doc/ref/api-macros.texi
+++ b/doc/ref/api-macros.texi
@@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
-@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010
+@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010, 2011
@c Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@@ -336,6 +336,23 @@ This discussion is mostly relevant in the context of traditional Lisp macros
(@pxref{Defmacros}), which do not preserve referential transparency. Hygiene
adds to the expressive power of Scheme.
+@subsubsection Shorthands
+
+One often ends up writing simple one-clause @code{syntax-rules} macros.
+There is a convenient shorthand for this idiom, in the form of
+@code{define-syntax-rule}.
+
+@deffn {Syntax} define-syntax-rule (keyword . pattern) [docstring] template
+Define @var{keyword} as a new @code{syntax-rules} macro with one clause.
+@end deffn
+
+Cast into this form, our @code{when} example is significantly shorter:
+
+@example
+(define-syntax-rule (when c e ...)
+ (if c (begin e ...)))
+@end example
+
@subsubsection Further Information
For a formal definition of @code{syntax-rules} and its pattern language, see