1 | sbool lispMatchIC_debug; |
2 | |
3 | static Map<S, Lisp> lispMatchIC(Lisp pat, Lisp nl, Collection<S> variables) { |
4 | new Map<S, Lisp> matches; |
5 | ret lispMatchIC_sub(pat, nl, variables, matches) ? matches : null; |
6 | } |
7 | |
8 | static bool lispMatchIC_sub(Lisp pat, Lisp nl, Collection<S> variables, Map<S, Lisp> m) { |
9 | if (pat == null || nl == null) ret false; |
10 | if (pat.isLeaf() && variables.contains(pat.head)) { |
11 | if (lispMatchIC_debug) print("Var: " + pat.head + " => " + nl); |
12 | ret lispMatchIC_putMatch(m, pat.head, nl); |
13 | } |
14 | |
15 | if (neqic(pat.head, nl.head)) ret false; |
16 | |
17 | // heads identical, proceed to children |
18 | int n = pat.size(); |
19 | if (n != nl.size()) ret false; |
20 | |
21 | for (int i = 0; i < n; i++) { |
22 | if (lispMatchIC_debug) print("Sub " + i + ": " + pat.get(i) + " => " + nl.get(i)); |
23 | if (!lispMatchIC_sub(pat.get(i), nl.get(i), variables, m)) |
24 | false; |
25 | } |
26 | |
27 | true; |
28 | } |
29 | |
30 | static bool lispMatchIC_putMatch(Map<S, Lisp> matches, S key, Lisp val) { |
31 | if (matches.containsKey(key)) { |
32 | if (!lispEqic(matches.get(key), val)) |
33 | false; |
34 | //fail("multi-matching not implemented"); |
35 | } else |
36 | matches.put(key, val); |
37 | true; |
38 | } |
Began life as a copy of #1007704
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: | #1007821 |
Snippet name: | lispMatchIC - ignore case |
Eternal ID of this version: | #1007821/1 |
Text MD5: | 7f437fba8554b4b737bcc7cbfb2b9226 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-04-10 12:45:25 |
Source code size: | 1172 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 529 / 556 |
Referenced in: | [show references] |