Changeset 32951 in project


Ignore:
Timestamp:
12/01/15 17:03:24 (5 years ago)
Author:
juergen
Message:

procedural-macros 1.0.3 without wildcards

Location:
release/4/procedural-macros
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • release/4/procedural-macros/tags/1.0.3/procedural-macros.scm

    r32942 r32951  
    9191procedures above, without a detour over bind and friends and sequences
    9292of the bindings library. Indeed, for macro-writing macros lists are
    93 sufficient. But off course, I have to provide some extensions to Graham's code,
    94 length checks, wildcards, non-symbol literals, as in the bindings egg.
    95 wildcards and nonsymbol literals bind nothing, the former matching
    96 anything, the latter only expressions evaluating to themselfs.
     93sufficient. But off course, I have to provide some extensions to
     94Graham's code, length checks and non-symbol literals, as in the bindings
     95egg.  Nonsymbol literals bind nothing, but match only to themselfs.
     96Wildcards are not supplied, because they break hygiene.
    9797
    9898The last feature missing is fenders, which is important in particular
    9999for macro-rules and can easily be implemented with a where clause: A
    100 pattern matches successfully if only each pattern variable can be bound
    101 and the where clause is satisfied. If the where clause doesn't pass the
    102 next pattern is tried.
     100pattern matches successfully if only each pattern variable can be bound,
     101the length checks pass, the literals match themselfs and the where
     102clause is satisfied. If any of those conditions is hurt, the next
     103pattern is tried.
    103104
    104105]|#
     
    158159                   (cond
    159160                     ((symbol? p)
    160                       (if (c? p '_)
    161                         ;; skip
    162                         recu
    163                         `((,p (list-ref ,seq ,n)) ,@recu)))
     161                      ;(if (c? p '_) ; wildcard
     162                      ;  ;; skip
     163                      ;  recu
     164                        `((,p (list-ref ,seq ,n)) ,@recu));)
    164165                     ((pair? p)
    165166                      (let ((g (gensym)))
     
    203204          (let ((syms (car f*))
    204205                (keys (cadr f*))
     206                ;; remove leading underscore and
    205207                ;; insert empty where clause into each rule without one
    206208                ;; to simplify matters via standardization
     
    209211                                    (if (and (pair? second)
    210212                                             (c? (car second) 'where))
    211                                       rule
    212                                       `(,(car rule) (where #t) ,@(cdr rule)))))
     213                                      ;rule
     214                                      `(,(cdar rule) ,@(cdr rule))
     215                                      ;`(,(car rule) (where #t) ,@(cdr rule)))))
     216                                      `(,(cdar rule) (where #t) ,@(cdr rule)))))
    213217                                (cddr f*)))
    214218                (gform 'form))
     
    225229                                'in
    226230                                ',(map (lambda (rule)
    227                                          `(,(car rule) ; pattern
     231                                         ;`(,(car rule) ; pattern
     232                                         `(,(cons '_ (car rule)) ; pattern
    228233                                           ,(cadr rule))) ; where clause
    229234                                       all-rules))
     
    231236                          `(condition-case
    232237                             ,(dbind-ex
    233                                 (condition-case (destruc (car rule) gform)
     238                                (condition-case (destruc (car rule); gform)
     239                                                         `(cdr ,gform))
    234240                                  ((exn) (loop (cdr rules))))
    235241                                (let* ((pat (car rule))
  • release/4/procedural-macros/tags/1.0.3/procedural-macros.setup

    r32942 r32951  
    77 'procedural-macros
    88 '("procedural-macros.so" "procedural-macros.import.so")
    9  '((version "1.0.2")))
     9 '((version "1.0.3")))
  • release/4/procedural-macros/trunk/procedural-macros.scm

    r32942 r32951  
    9191procedures above, without a detour over bind and friends and sequences
    9292of the bindings library. Indeed, for macro-writing macros lists are
    93 sufficient. But off course, I have to provide some extensions to Graham's code,
    94 length checks, wildcards, non-symbol literals, as in the bindings egg.
    95 wildcards and nonsymbol literals bind nothing, the former matching
    96 anything, the latter only expressions evaluating to themselfs.
     93sufficient. But off course, I have to provide some extensions to
     94Graham's code, length checks and non-symbol literals, as in the bindings
     95egg.  Nonsymbol literals bind nothing, but match only to themselfs.
     96Wildcards are not supplied, because they break hygiene.
    9797
    9898The last feature missing is fenders, which is important in particular
    9999for macro-rules and can easily be implemented with a where clause: A
    100 pattern matches successfully if only each pattern variable can be bound
    101 and the where clause is satisfied. If the where clause doesn't pass the
    102 next pattern is tried.
     100pattern matches successfully if only each pattern variable can be bound,
     101the length checks pass, the literals match themselfs and the where
     102clause is satisfied. If any of those conditions is hurt, the next
     103pattern is tried.
    103104
    104105]|#
     
    158159                   (cond
    159160                     ((symbol? p)
    160                       (if (c? p '_)
    161                         ;; skip
    162                         recu
    163                         `((,p (list-ref ,seq ,n)) ,@recu)))
     161                      ;(if (c? p '_) ; wildcard
     162                      ;  ;; skip
     163                      ;  recu
     164                        `((,p (list-ref ,seq ,n)) ,@recu));)
    164165                     ((pair? p)
    165166                      (let ((g (gensym)))
     
    203204          (let ((syms (car f*))
    204205                (keys (cadr f*))
     206                ;; remove leading underscore and
    205207                ;; insert empty where clause into each rule without one
    206208                ;; to simplify matters via standardization
     
    209211                                    (if (and (pair? second)
    210212                                             (c? (car second) 'where))
    211                                       rule
    212                                       `(,(car rule) (where #t) ,@(cdr rule)))))
     213                                      ;rule
     214                                      `(,(cdar rule) ,@(cdr rule))
     215                                      ;`(,(car rule) (where #t) ,@(cdr rule)))))
     216                                      `(,(cdar rule) (where #t) ,@(cdr rule)))))
    213217                                (cddr f*)))
    214218                (gform 'form))
     
    225229                                'in
    226230                                ',(map (lambda (rule)
    227                                          `(,(car rule) ; pattern
     231                                         ;`(,(car rule) ; pattern
     232                                         `(,(cons '_ (car rule)) ; pattern
    228233                                           ,(cadr rule))) ; where clause
    229234                                       all-rules))
     
    231236                          `(condition-case
    232237                             ,(dbind-ex
    233                                 (condition-case (destruc (car rule) gform)
     238                                (condition-case (destruc (car rule); gform)
     239                                                         `(cdr ,gform))
    234240                                  ((exn) (loop (cdr rules))))
    235241                                (let* ((pat (car rule))
  • release/4/procedural-macros/trunk/procedural-macros.setup

    r32942 r32951  
    77 'procedural-macros
    88 '("procedural-macros.so" "procedural-macros.import.so")
    9  '((version "1.0.2")))
     9 '((version "1.0.3")))
Note: See TracChangeset for help on using the changeset viewer.