1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | Eval_silentpattern = ->
|
13 | Eval_pattern()
|
14 | pop()
|
15 | push_symbol(NIL)
|
16 |
|
17 | Eval_pattern = ->
|
18 |
|
19 | if !iscons(cdr(p1))
|
20 | stop("pattern needs at least a template and a transformed version")
|
21 | firstArgument = car(cdr(p1))
|
22 | secondArgument = car(cdr(cdr(p1)))
|
23 | if secondArgument == symbol(NIL)
|
24 | stop("pattern needs at least a template and a transformed version")
|
25 |
|
26 | if !iscons(cdr(cdr(p1)))
|
27 | thirdArgument = symbol(NIL)
|
28 | else
|
29 | thirdArgument = car(cdr(cdr(cdr(p1))))
|
30 |
|
31 | if equal(firstArgument, secondArgument)
|
32 | stop("recursive pattern")
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | stringKey = "template: " + print_list(firstArgument)
|
39 | stringKey += " tests: " + print_list(thirdArgument)
|
40 | if DEBUG then console.log "pattern stringkey: " + stringKey
|
41 |
|
42 | patternPosition = userSimplificationsInStringForm.indexOf stringKey
|
43 |
|
44 | if patternPosition == -1
|
45 |
|
46 | userSimplificationsInStringForm.push(stringKey)
|
47 | userSimplificationsInListForm.push(cdr(p1))
|
48 | else
|
49 | if DEBUG then console.log "pattern already exists, replacing. " + cdr(p1)
|
50 | userSimplificationsInStringForm[patternPosition] = stringKey
|
51 | userSimplificationsInListForm[patternPosition] = cdr(p1)
|
52 |
|
53 |
|
54 |
|
55 | push_symbol(PATTERN)
|
56 | push cdr(p1)
|
57 | list(2)
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | do_clearPatterns = ->
|
66 | userSimplificationsInListForm = []
|
67 | userSimplificationsInStringForm = []
|
68 |
|
69 | Eval_clearpatterns = ->
|
70 |
|
71 |
|
72 |
|
73 | do_clearPatterns()
|
74 |
|
75 |
|
76 | push_symbol(NIL)
|
77 |
|
78 |
|
79 | Eval_patternsinfo = ->
|
80 | patternsinfoToBePrinted = patternsinfo()
|
81 |
|
82 | if patternsinfoToBePrinted != ""
|
83 | new_string(patternsinfoToBePrinted)
|
84 | else
|
85 | push_symbol(NIL)
|
86 |
|
87 | patternsinfo = ->
|
88 | patternsinfoToBePrinted = ""
|
89 | for i in userSimplificationsInListForm
|
90 | patternsinfoToBePrinted += userSimplificationsInListForm + "\n"
|
91 | return patternsinfoToBePrinted
|