Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

46
LINES

< > BotCompany Repo | #1002721 // snlMatch

JavaX fragment (include)

static boolean snlMatch(S pat, S snl, Map<S, Lisp> matches) {
  matches.clear();
  ret snlMatch_sub(snlToTree_cached(pat), snlToTree(snl), matches);
}

static boolean snlMatch(Lisp pat, S snl, Map<S, Lisp> matches) {
  matches.clear();
  ret snlMatch_sub(pat, snlToTree(snl), matches);
}

static boolean snlMatch(S pat, Lisp snl, Map<S, Lisp> matches) {
  matches.clear();
  ret snlMatch_sub(snlToTree_cached(pat), snl, matches);
}

static boolean snlMatch(Lisp pat, Lisp snl, Map<S, Lisp> matches) {
  matches.clear();
  ret snlMatch_sub(pat, snl, matches);
}

static boolean snlMatch_sub(Lisp pat, Lisp snl, Map<S, Lisp> 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<S, Lisp> 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;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002721
Snippet name: snlMatch
Eternal ID of this version: #1002721/1
Text MD5: 55b771ac4547b91a9ae76c074dde1f48
Author: stefan
Category: eleu / nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-19 21:25:10
Source code size: 1322 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 586 / 625
Referenced in: [show references]