static boolean nlMatch(S pat, S nl, Map matches) { matches.clear(); ret nlMatch_sub(nlParse/*_cached*/(pat), nlParse(nl), matches); } static boolean nlMatch(Lisp pat, S nl, Map matches) { matches.clear(); ret nlMatch_sub(pat, nlParse(nl), matches); } static boolean nlMatch(S pat, Lisp nl, Map matches) { matches.clear(); ret nlMatch_sub(nlParse/*_cached*/(pat), nl, matches); } static boolean nlMatch(Lisp pat, Lisp nl, Map matches) { matches.clear(); ret nlMatch_sub(pat, nl, matches); } static boolean nlMatch_sub(Lisp pat, Lisp nl, Map m) { if (pat == null || nl == null) ret false; if (pat.isA("*")) ret true; if (nlIsVar(pat)) ret nlMatch_putMatch(m, pat.head, nl); if (neq(pat.head, nl.head)) ret false; // heads identical, proceed to children int n = pat.size(); if (n != nl.size()) ret false; for (int i = 0; i < n; i++) if (!nlMatch_sub(pat.get(i), nl.get(i), m)) ret false; ret true; } static boolean nlMatch_putMatch(Map matches, S key, Lisp val) { key = dropPrefix("$", key); if (matches.containsKey(key) && neq(matches.get(key), val)) fail("multi-matching not implemented"); matches.put(key, val); ret true; }