This repo is not current. Development has moved from Hg to Git. For the latest code use the "Source Code" tab above to go to the "Thun" git repo or navigate to:
https://osdn.net/projects/joypy/scm/git/Thun
Revisão | f3e04b7b897e41c8186d74297c3dcaa305a74d0b (tree) |
---|---|
Hora | 2020-02-01 05:01:13 |
Autor | Simon Forman <sforman@hush...> |
Commiter | Simon Forman |
Minor edits.
@@ -72,9 +72,6 @@ | ||
72 | 72 | ██║ ██║██╔══██╗██╔══██║██║╚██╔╝██║██║╚██╔╝██║██╔══██║██╔══██╗ |
73 | 73 | ╚██████╔╝██║ ██║██║ ██║██║ ╚═╝ ██║██║ ╚═╝ ██║██║ ██║██║ ██║ |
74 | 74 | ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ |
75 | - | |
76 | - | |
77 | - | |
78 | 75 | |
79 | 76 | The grammar of Joy is very simple. A Joy expression is zero or more Joy |
80 | 77 | terms separated by blanks, and terms can be either integers, Booleans, |
@@ -170,27 +167,30 @@ | ||
170 | 167 | thun(list(A), [], B, [list(A)|B]). |
171 | 168 | thun(list(C), [A|B], D, E) :- thun(A, B, [list(C)|D], E). |
172 | 169 | |
173 | -% Partial reduction for func/3 cases works. | |
170 | +% Partial reduction works for func/3 cases. | |
174 | 171 | |
175 | 172 | thun(symbol(A), [], B, C) :- func(A, B, C). |
176 | 173 | thun(symbol(A), [C|D], B, F) :- func(A, B, E), thun(C, D, E, F). |
177 | 174 | |
178 | - % Combinators look ok too. | |
179 | - | |
180 | -thun(symbol(A), D, B, C) :- combo(A, B, C, D, []). | |
181 | -thun(symbol(A), C, B, G) :- combo(A, B, F, C, [D|E]), thun(D, E, F, G). | |
175 | +% Combinators look ok too. | |
182 | 176 | |
183 | -% I think the order of these two rules should be reversed because | |
184 | -% it will be pretty rare for a combinator to result in a null | |
185 | -% expression and we don't want to process combo/5 twice just to | |
186 | -% notice that, eh? Swap the rules and add green cuts after combo/5 | |
187 | -% and that should make it more efficient. | |
177 | +% thun(symbol(A), D, B, C) :- combo(A, B, C, D, []). | |
178 | +% thun(symbol(A), C, B, G) :- combo(A, B, F, C, [D|E]), thun(D, E, F, G). | |
188 | 179 | |
189 | -% Ach! THe "green" cuts would mess up multi-rule combinators! D'oh! | |
180 | +% However, in this case, I think the original version will be more | |
181 | +% efficient. | |
190 | 182 | |
191 | -% Neither functions nor definitions can affect the expression so we | |
192 | -% don't need to do similar gardening to those rules. The unification | |
193 | -% of the head clauses will distinguish the cases for them. | |
183 | +thun(symbol(Combo), E, Si, So) :- combo(Combo, Si, S, E, Eo), thun(Eo, S, So). | |
184 | + | |
185 | +% In the reduced rules Prolog will redo all the work of the combo/5 | |
186 | +% predicate on backtracking through the second rule. It will try combo/5, | |
187 | +% which usually won't end in Eo=[] so the first rule fails, then it will | |
188 | +% try combo/5 again in the second rule. In this form, after combo/5 has | |
189 | +% completed Prolog has computed Eo and can index on it for thun/3. | |
190 | +% | |
191 | +% Neither functions nor definitions can affect the expression so this | |
192 | +% doesn't apply to those rules. The unification of the head clauses will | |
193 | +% distinguish the cases for them. | |
194 | 194 | |
195 | 195 | % Definitions don't work though (See "Partial Reducer" section below.) |
196 | 196 | % I hand-wrote the def/3 cases here. (Maybe if append/3 was reduced?) |
@@ -1104,9 +1104,9 @@ | ||
1104 | 1104 | (thun( int(I), E, Si, So) :- thun(E, [ int(I)|Si], So)), |
1105 | 1105 | (thun(bool(B), E, Si, So) :- thun(E, [bool(B)|Si], So)), |
1106 | 1106 | (thun(list(L), E, Si, So) :- thun(E, [list(L)|Si], So)), |
1107 | - (thun(symbol(Def), E, Si, So) :- def(Def, Body), append(Body, E, [T|Eo]), thun(T, Eo, Si, So)), | |
1108 | - (thun(symbol(Func), E, Si, So) :- func(Func, Si, S), thun(E, S, So)), | |
1109 | - (thun(symbol(Combo), E, Si, So) :- combo(Combo, Si, S, E, Eo), thun(Eo, S, So)) | |
1107 | + % (thun(symbol(Def), E, Si, So) :- def(Def, Body), append(Body, E, [T|Eo]), thun(T, Eo, Si, So)), | |
1108 | + (thun(symbol(Func), E, Si, So) :- func(Func, Si, S), thun(E, S, So)) | |
1109 | + % (thun(symbol(Combo), E, Si, So) :- combo(Combo, Si, S, E, Eo), thun(Eo, S, So)) | |
1110 | 1110 | ]). |
1111 | 1111 | |
1112 | 1112 | /* |