1 | // snlMatchX keeps existing matches |
2 | |
3 | static boolean snlMatchX(S pat, S snl, Map<S, Lisp> matches) { |
4 | ret snlMatchX_sub(snlToTree_cached(pat), snlToTree(snl), matches); |
5 | } |
6 | |
7 | static boolean snlMatchX(Lisp pat, S snl, Map<S, Lisp> matches) { |
8 | ret snlMatchX_sub(pat, snlToTree(snl), matches); |
9 | } |
10 | |
11 | static boolean snlMatchX(S pat, Lisp snl, Map<S, Lisp> matches) { |
12 | ret snlMatchX_sub(snlToTree_cached(pat), snl, matches); |
13 | } |
14 | |
15 | static boolean snlMatchX(Lisp pat, Lisp snl, Map<S, Lisp> matches) { |
16 | ret snlMatchX_sub(pat, snl, matches); |
17 | } |
18 | |
19 | static boolean snlMatchX_sub(Lisp pat, Lisp snl, Map<S, Lisp> m) { |
20 | if (pat == null || snl == null) ret false; |
21 | if (pat.isA("*")) |
22 | ret true; |
23 | if (startsWithUpperCase(pat.head)) |
24 | ret snlMatchX_putMatch(m, pat.head, snl); |
25 | |
26 | if (neq(pat.head, snl.head)) ret false; |
27 | |
28 | // heads identical, proceed to children |
29 | int n = pat.size(); |
30 | if (n != snl.size()) ret false; |
31 | |
32 | for (int i = 0; i < n; i++) |
33 | if (!snlMatchX_sub(pat.get(i), snl.get(i), m)) |
34 | ret false; |
35 | |
36 | ret true; |
37 | } |
38 | |
39 | static boolean snlMatchX_putMatch(Map<S, Lisp> matches, S key, Lisp val) { |
40 | if (matches.containsKey(key) && neq(matches.get(key), val)) |
41 | fail("multi-matching not implemented"); |
42 | matches.put(key, val); |
43 | ret true; |
44 | } |
Began life as a copy of #1002721
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: | #1002728 |
Snippet name: | snlMatchX |
Eternal ID of this version: | #1002728/1 |
Text MD5: | f0c213549bcdf5a64aa3214c9689b1bd |
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:43:36 |
Source code size: | 1293 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 650 / 664 |
Referenced in: | [show references] |