static boolean snlMatch(S pat, S snl, Map matches) { matches.clear(); ret snlMatch_sub(snlToTree_cached(pat), snlToTree(snl), matches); } static boolean snlMatch(Lisp pat, S snl, Map matches) { matches.clear(); ret snlMatch_sub(pat, snlToTree(snl), matches); } static boolean snlMatch(S pat, Lisp snl, Map matches) { matches.clear(); ret snlMatch_sub(snlToTree_cached(pat), snl, matches); } static boolean snlMatch(Lisp pat, Lisp snl, Map matches) { matches.clear(); ret snlMatch_sub(pat, snl, matches); } static boolean snlMatch_sub(Lisp pat, Lisp snl, Map m) { if (pat == null || snl == null) ret false; if (pat.isA("*")) ret true; if (startsWithUpperCase(pat.head)) ret snlMatch_putMatch(m, pat.head, snl); if (neq(pat.head, snl.head)) ret false; // heads identical, proceed to children int n = pat.size(); if (n != snl.size()) ret false; for (int i = 0; i < n; i++) if (!snlMatch_sub(pat.get(i), snl.get(i), m)) ret false; ret true; } static boolean snlMatch_putMatch(Map matches, S key, Lisp val) { if (matches.containsKey(key) && neq(matches.get(key), val)) fail("multi-matching not implemented"); matches.put(key, val); ret true; }