Changeset 34878 in project


Ignore:
Timestamp:
11/07/17 16:27:00 (3 years ago)
Author:
juergen
Message:

procedural-macros 2.1 replaces dependency on bindings with basic-macros

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/procedural-macros

    r33547 r34878  
    2727This library provides the means for this to happen. Combining implicit
    2828renaming with destructuring, some macro-writing macros are defined, in
    29 particular, a hygienic procedural define-macro and a procedural version
    30 of syntax-rules, named macro-rules. The latter is almost as easy to use
    31 as syntax-rules, but much more powerfull. Here is its syntax
     29particular, a (mostly) hygienic procedural define-macro and a procedural
     30version of syntax-rules, named macro-rules. The latter is almost as easy
     31to use as syntax-rules, but much more powerfull. Here is its syntax
    3232
    3333<macro>(macro-rules sym ... (key ...) (pat (where fender ...) .. tpl) ....)</macro>
     
    3939
    4040This form can be used instead of syntax-rules in define-syntax,
    41 let-sytax and letrec-syntax, provided, you import it for-syntax.
     41let-sytax and letrec-syntax, provided, you use it for-syntax.
    4242sym ... denote the injected symbols to break hygiene (if there is none,
    4343the constructed macro is hygienic). key ... and pat .... symbols are
     
    4848And here is the syntax of define-macro
    4949
    50 <macro>(define-macro (name . args) (where fender ...) .. xpr ....))</macro>
    51 
    52 This macro does not handle injected or keyword symbols. For this use
    53 macro-rules.
     50<macro>(define-macro (name . args) (where (x . xs) ...) .. xpr ....)</macro>
    5451
    5552The implementation of these macros depends on the bind-case macro of the
    56 bindings package which does the pattern matching of macro-rules. Since
     53basic-macros package which does the pattern matching of macro-rules. Since
    5754the former can handle wildcards, non-symbol literals and fenders, so
    5855does the latter.
     
    8279pattern is not matched.
    8380
    84 macro-rules must be imported for-syntax if used in the preprocessing
     81macro-rules must be used for-syntax if used in the preprocessing
    8582phase of a macro evaluation.
    8683
    8784==== define-macro
    8885
    89 <macro>(define-macro (name . args) (where fender ...) .. xpr ....))</macro>
    90 
    91 generates a hygienic implicit-renaming macro, name.
     86<macro>(define-macro (name . args) (where (x . xs) ...) .. xpr ....))</macro>
     87
     88where xs is either a list of predicates, providing fenders,
     89or a singleton with one of the symbols keyword or injection,
     90providing keyword parameters or unhygienic macros.
     91Generates a hygienic implicit-renaming macro, name, if no injection
     92parameter is given.
    9293
    9394==== macro-let
     
    102103
    103104evaluates body ... in the context of recursive hygienic macros name ....
     105
     106=== Reexports from basic-macros
    104107
    105108==== once-only
     
    123126wrapper around er-macro-transformer.
    124127
     128==== define-er-macro
     129
     130<macro>(define-er-macro (name form rename-symbol compare?) xpr . xprs)</macro>
     131
     132defines an explicit-renaming-macro name with macro-code form renaming
     133each symbol in the body xpr . xprs starting with rename-symbol
     134automatically.
     135
     136==== define-ir-macro
     137
     138<macro>(define-ir-macro (name form inject-symbol compare?) xpr . xprs)</macro>
     139
     140defines an implicit-renaming-macro name with macro-code form injecting
     141each symbol in the body xpr . xprs starting with inject-symbol
     142automatically.
     143
    125144==== with-mapped-symbols
    126145
     
    141160=== Requirements
    142161
    143 bindings, basic-sequences
     162basic-macros
    144163
    145164=== Usage
     
    149168(use procedural-macros)
    150169
    151 (import-for-syntax
     170(use-for-syntax
    152171 (only procedural-macros macro-rules once-only
    153172                         with-mapped-symbols with-gensyms)
    154173
    155 (import-for-syntax (only procedural-macros macro-rules with-gensyms once-only))
    156174</enscript>
    157175
     
    161179
    162180(use procedural-macros)
    163 
    164 (import-for-syntax (only procedural-macros macro-rules once-only)
    165                    (only data-structures list-of?))
    166 
    167 (use procedural-macros)
    168 (import-for-syntax
    169   (only procedural-macros macro-rules with-gensyms once-only))
     181(use-for-syntax
     182  (only procedural-macros macro-rules))
     183(import-for-syntay
     184  (only data-structures list-of?))
    170185
    171186;; two anaphoric macros
     
    180195
    181196(define-macro (alambda args xpr . xprs)
    182   (inject self)
     197  (self injection)
    183198  `(letrec ((,self (lambda ,args ,xpr ,@xprs)))
    184199     ,self))
     
    233248;; procedural version of letrec
    234249(define-macro (my-letrec var-val-pairs . body)
    235               (where (var-val-pairs (list-of? pair?)))
     250  (where (var-val-pairs (list-of? pair?)))
    236251  (let ((vars (map car var-val-pairs))
    237252        (vals (map cadr var-val-pairs))
     
    303318== Last update
    304319
    305 Jul 28, 2016
     320Nov 07, 2017
    306321
    307322== Author
     
    311326== License
    312327
    313  Copyright (c) 2015-2016, Juergen Lorenz
     328 Copyright (c) 2015-2017, Juergen Lorenz
    314329 All rights reserved.
    315330
     
    341356
    342357== Version History
     358; 2.1 : dependency on basic-macros instead of bindings
    343359; 2.0 : New implementation based on bind-case from the bindings egg
    344360; 1.1 : fenders now writen in the form (var ok? ...) accepting zero or many predicates 
Note: See TracChangeset for help on using the changeset viewer.