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

40
LINES

< > BotCompany Repo | #1008096 // lispMatchIC_xyzVars - ignore case, assume X Y Z vars

JavaX fragment (include)

1  
sbool lispMatchIC_xyzVars_debug;
2  
3  
static Map<S, Lisp> lispMatchIC_xyzVars(Lisp pat, Lisp nl) {
4  
  new Map<S, Lisp> matches;
5  
  ret lispMatchIC_xyzVars_sub(pat, nl, matches) ? matches : null;
6  
}
7  
8  
// put additional vars in m with value = null
9  
static bool lispMatchIC_xyzVars_sub(Lisp pat, Lisp nl, Map<S, Lisp> m) {
10  
  if (pat == null || nl == null) ret false;
11  
  if (pat.isLeaf() && (isXYZVar(pat.head) || m.containsKey(pat.head))) {
12  
    if (lispMatchIC_xyzVars_debug) print("Var: " + pat.head + " => " + nl);
13  
    ret lispMatchIC_xyzVars_putMatch(m, pat.head, nl);
14  
  }
15  
    
16  
  if (neqic(pat.head, nl.head)) ret false;
17  
  
18  
  // heads identical, proceed to children
19  
  int n = pat.size();
20  
  if (n != nl.size()) ret false;
21  
  
22  
  for (int i = 0; i < n; i++) {
23  
    if (lispMatchIC_xyzVars_debug) print("Sub " + i + ": " + pat.get(i) + " => " + nl.get(i));
24  
    if (!lispMatchIC_xyzVars_sub(pat.get(i), nl.get(i), m))
25  
      false;
26  
  }
27  
      
28  
  true;
29  
}
30  
31  
static bool lispMatchIC_xyzVars_putMatch(Map<S, Lisp> matches, S key, Lisp val) {
32  
  Lisp oldValue = matches.get(key);
33  
  if (oldValue != null) {
34  
    if (!lispEqic(oldValue, val))
35  
      false;
36  
      //fail("multi-matching not implemented");
37  
  } else
38  
    matches.put(key, val);
39  
  true;
40  
}

Author comment

Began life as a copy of #1007821

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: #1008096
Snippet name: lispMatchIC_xyzVars - ignore case, assume X Y Z vars
Eternal ID of this version: #1008096/3
Text MD5: b709781c7adcba8561588096c05d062e
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-07 00:22:11
Source code size: 1259 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 465 / 483
Version history: 2 change(s)
Referenced in: [show references]