Changeset 33077 in project


Ignore:
Timestamp:
01/11/16 19:17:59 (4 years ago)
Author:
juergen
Message:

procedural-macros 1.1 with syntax change in where clause

File:
1 edited

Legend:

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

    r32952 r33077  
    3636usual, i.e. the pattern on the left is repeated zero or more times, two
    3737dots, zero or one time, 4 dots one ore several times.
     38
    3839
    3940This form can be used instead of syntax-rules in define-syntax,
     
    144145like syntax-rules, but the templates are usually quasiquote-expressions.
    145146Moreover, the symbols sym ... are injected, if there are any.
     147Here and in the sequel, fender is an expresseion of the form
     148 (var ok?  ...)
     149checking a pattern variable, var, against a sequence of predicates.
    146150
    147151Note, that non-symbol literals are accepted in each pat and
     
    269273;; procedural version of letrec
    270274(define-macro (my-letrec var-val-pairs . body)
    271               (where ((list-of? pair?) var-val-pairs))
     275              (where (var-val-pairs (list-of? pair?)))
    272276  (let ((vars (map car var-val-pairs))
    273277        (vals (map cadr var-val-pairs))
     
    300304
    301305(macro-let (
    302      ((fir lst) (where (list? lst)) `(car ,lst))
    303      ((res lst) (where (list? lst)) `(cdr ,lst))
     306     ((fir lst) (where (lst list?)) `(car ,lst))
     307     ((res lst) (where (lst list?)) `(cdr ,lst))
    304308     )
    305309     (fir (res '(1 2 3))))
     
    311315    ((_ "foo" x) x)
    312316    ((_ #f x) x)
    313     ((_ a b) (where (string? a)) `(list ,a ,b))
    314     ((_ a b) (where (odd? a)) `(list ,a ,b))
     317    ((_ a b) (where (a string?)) `(list ,a ,b))
     318    ((_ a b) (where (a odd?)) `(list ,a ,b))
    315319    ((_ a b) a)))
    316320(foo "foo" 1)
     
    327331(define-syntax add
    328332  (macro-rules ()
    329     ((_ x y) (where (string? x) (string? y))
     333    ((_ x y) (where (x string?) (y string?))
    330334     `(string-append ,x ,y))
    331     (( _ x y) (where (integer? x) (integer? y))
     335    (( _ x y) (where (x integer?) (y integer?))
    332336     `(+ ,x ,y))))
    333337(add 1 2)
     
    339343== Last update
    340344
    341 Dec 01, 2015
     345Jan 11, 2016
    342346
    343347== Author
     
    347351== License
    348352
    349  Copyright (c) 2015, Juergen Lorenz
     353 Copyright (c) 2015-2016, Juergen Lorenz
    350354 All rights reserved.
    351355
     
    377381
    378382== Version History
     383; 1.1 : fenders now writen in the form (var ok? ...) accepting zero or many predicates 
    379384; 1.0.3 : wildcards ommitted, out of hygiene reasons
    380385; 1.0.2 : documentation procedure exported
Note: See TracChangeset for help on using the changeset viewer.