MATCH-BIND


Syntax

match-bind (pattern &optional binding-list)
=> list

NB: = and == tags used in the pattern are treated as literals.

Description
MATCH-BIND is a function which allows lists to be constructed using data bound to matcher variables. MATCH-BIND may be used in preference to #?var forms and in some cases removes the need to use eval.
Examples
 
> (mlet ('(?first == ?last) '(a b c d e))
                  (match-bind '(front = ?first & back = ?last)))
==> (FRONT = A & BACK = E)
 

(setf family
   '((parent-of Sarah Tom)  (parent-of Steve Joe)
     (parent-of Sally Sam)  (parent-of Ellen Sarah)
     (parent-of Emma  Bill) (parent-of Rob   Sally)
    ))

> (forevery ('((parent-of ?a ?b) (parent-of ?b ?c))
             family)
      (match-bind '(grandparent ?a ?c)))
==>  ((GRANDPARENT ELLEN TOM) (GRANDPARENT ROB SAM))
 

; this example uses optional binding-list argument
> (match-bind '(the ?subj ate the ??obj) '((subj cat)(obj (big cheese))))
==> (THE CAT ATE THE BIG CHEESE)