match-list   scheme


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

Implementation

;; where 
;; e = expression
;; em = match-expression
(define match-list
  (lambda (e em)
    ;; (println 'match-list e 'em em)
    (if (null? e) 
        (if (and (not (null? em)) 
                 (not (member #t (map is-match-multi? (map variable-constructor em)))))
            MATCH-FAILED
            '())
        (if (or (not (list? em)) (null? em)) 
            MATCH-FAILED
            (let ((var (variable-constructor (car em))))
              (if (string=? (cadddr var) "literal")
                  (cond 
                    ((list? (car e)) 
                    (list (match-list (car e) (car em))
                          (match-list (cdr e) (cdr em))))
                    ((pair? (car e)) 
                    (list (match-pair (car e) (car em))
                          (match-list (cdr e) (cdr em))))
                    ((equal? (car e) (car var)) 
                    (match-list (cdr e) (cdr em)))                     
                    (else MATCH-FAILED))
                  (process-multi-variable e em var)))))))


Back to Index