p:pair   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/base/pattern.xtm

Implementation

;;@ignore
;; Matches pairs that are not lists. A cascade of p:pair's can be substituted
;; for p:list only if subpatterns have no segment variables.
(define (p:pair car-pattern cdr-pattern)
  (let ((car-proc (matcher:proc car-pattern))
        (cdr-proc (matcher:proc cdr-pattern)))
    (matcher:make
     'single
     (lambda (datum sofar success)
       (and (pair? datum)
            (car-proc (car datum)
                      sofar
                      (lambda (result)
                        (cdr-proc (cdr datum) result success)))))
     (no-dups (append (matcher:variables car-pattern)
                      (matcher:variables cdr-pattern))))))


Back to Index

Similar Entries