You are looking at historical revision 24398 of this page. It may differ significantly from its current revision.
Implicit renaming macros
This module contains some macros to make the use of low-level implicit renaming macros easyier. Recall that those macros are implemented as a transformer routine, which is a three-parameter procedure
(lambda (form inject compare?) ...)
which has to be enclosed by an ir-macro-transformer call. The programmer's job is to destructure the macro-code, form. All symbols of the macro-expression not protected by inject are transparently renamed in the background to achieve hygiene. If no symbol is injected, the macro is automatically hygienic.
The job of destructuring the macro-code is tedious and error prone, it can be done by a tool, match from the matchable egg, for example. The other job, compare? literal symbols with those renamed behind the scene, something which is needed to use literals like else and => in the cond macro, remains to be done.
ir-macro-rules[syntax] (ir-macro-rules (inject compare? sym ...) (pat0 xpr0) (pat1 xpr1) ...)
where each sym ... will break hygiene, hence the list (sym ...) is usually empty. pat0 pat1 ... are patterns describing admissible macro-codes (the macro-name can be replaced by an underscore) and xpr0 xpr1 ... are corresponding expressions which are evaluated to generate the macro expansion.
This macro is similar to and works like syntax-rules by design. That is, the macro-code is compared to pat0 pat1 in sequence and the expression paired to the first matching pattern is executed to generate the macro expansion. Nevertheless, there are two differences. First, the unrenamed symbols (sym ...) to be used in the expressions have nothing to do with literals like else and => in the cond macro (those are handled by compare?), and second, the patterns are not paired with templates as in syntax-rules, but with expressions which generate those templates (usually in the form of quasiquoted lists which contain the symbols sym ... unquoted). This makes ir-macro-rules much more flexible than syntax-rules: The programmer has the freedom to decide what to do at compile-time and what at runtime.
macro-rules[syntax] (macro-rules (inject compare? sym ...) (pat0 xpr0) (pat1 xpr1) ...)
Alias of ir-macro-rules.
ir-macro-define[syntax] (ir-macro-define (name . args) (lambda (inject compare? sym ...) . body))
defines a macro with macro-code (name . args) by means of a transformer, which is a procedure of inject, compare? and (rarely!) sym .... This is quite similar to the old define-macro of Chicken-3, where it not for the lambda line.
macro-define[syntax] (macro-define (name . args) (lambda (inect compare? sym ...) . body))
Alias of ir-macro-define
ir-macro-let[syntax] (ir-macro-let ((code0 transformer0) ...) . body)
where code0 ... is the macro-code (name0 . args0) ... of a local macro and transformer0 ... the corresponding transformer (lambda (inject compare? sym ...) . body0) .... These macros are locally defined in parallel and in there scope body is executed.
macro-let[syntax] (macro-let ((code0 transformer0) ...) . body)
Alias of ir-macro-let
ir-macro-letrec[syntax] (ir-macro-letrec ((code0 transformer0) ...) . body)
recursive version of ir-macro-let, i.e. the local macros have access to each other.
macro-letrec[syntax] (macro-letrec ((code0 transformer0) ...) . body)
Alias of ir-macro-letrec
(import-for-syntax (only matchable match) (only ir-macros ir-macro-rules))
(define-syntax my-or ; ok (ir-macro-rules () ((_) (lambda (insert compare?) #f)) ((_ arg . args) (lambda (insert compare?) `(if ,arg ,arg (my-or ,@args))))))
Copyright (c) 2011, Juergen Lorenz All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- changed syntax of [ir-]macro-rules, thanks to Moritz Heidkamp
- added additional inject argument to all transformers
- initial import