• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revision8d4026862f43fe4eadc6ca90f1a9da57999bd288 (tree)
Time2019-08-11 12:12:41
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Bring in funcs and combos.

Change Summary

Incremental Difference

diff -r a71525e87b9b -r 8d4026862f43 thun/gnu-prolog/thun.pl
--- a/thun/gnu-prolog/thun.pl Sat Aug 10 20:06:12 2019 -0700
+++ b/thun/gnu-prolog/thun.pl Sat Aug 10 20:12:41 2019 -0700
@@ -17,8 +17,9 @@
1717 along with Thun. If not see <http://www.gnu.org/licenses/>.
1818
1919 */
20-:- dynamic(func/3).
21-:- discontiguous(func/3).
20+% :- dynamic(func/3).
21+% :- discontiguous(func/3).
22+
2223
2324 :- initialization(loop).
2425
@@ -84,6 +85,35 @@
8485 func(swap, [A, B|S], [B, A|S]).
8586 func(dup, [A|S], [A, A|S]).
8687 func(pop, [_|S], S ).
88+func(sqrt, [A|S], [sqrt(A)|S]).
89+
90+func(concat, [A, B|S], [C|S]) :- append(B, A, C).
91+func(flatten, [A|S], [B|S]) :- flatten(A, B).
92+func(swaack, [R|S], [S|R]).
93+func(stack, S , [S|S]).
94+func(clear, _ , []).
95+func(first, [[X|_]|S], [X|S]).
96+func(rest, [[_|X]|S], [X|S]).
97+func(unit, [X|S], [[X]|S]).
98+
99+func(rolldown, [A, B, C|S], [B, C, A|S]).
100+func(dupd, [A, B|S], [A, B, B|S]).
101+func(over, [A, B|S], [B, A, B|S]).
102+func(tuck, [A, B|S], [A, B, A|S]).
103+
104+func(shift, [[B|A], C|D], [A, [B|C]|D]).
105+
106+func(rollup, Si, So) :- func(rolldown, So, Si).
107+func(uncons, Si, So) :- func(cons, So, Si).
108+
109+func(bool, [ 0|S], [false|S]) :- !.
110+func(bool, [ 0.0|S], [false|S]) :- !.
111+func(bool, [ []|S], [false|S]) :- !.
112+func(bool, [ ""|S], [false|S]) :- !.
113+func(bool, [false|S], [false|S]) :- !.
114+
115+func(bool, [_|S], [true|S]).
116+
87117
88118
89119 /*
@@ -95,6 +125,48 @@
95125 combo(dipd, [P, X, Y|S], S, Ei, Eo) :- append(P, [Y, X|Ei], Eo).
96126
97127 combo(dupdip, [P, X|S], [X|S], Ei, Eo) :- append(P, [X|Ei], Eo).
128+combo(dupdip, [P, X|S], [X|S], Ei, Eo) :- append(P, [X|Ei], Eo).
129+
130+combo(branch, [T, _, true|S], S, Ei, Eo) :- append(T, Ei, Eo).
131+combo(branch, [_, F, false|S], S, Ei, Eo) :- append(F, Ei, Eo).
132+combo(branch, [T, F, Expr|S], S, Ei, Eo) :-
133+ \+ Expr = true, \+ Expr = false,
134+ catch( % Try Expr and do one or the other,
135+ (Expr -> append(T, Ei, Eo) ; append(F, Ei, Eo)),
136+ _, % If Expr don't grok, try both branches.
137+ (append(T, Ei, Eo) ; append(F, Ei, Eo))
138+ ).
139+
140+combo(loop, [_, false|S], S, E, E ).
141+combo(loop, [B, true|S], S, Ei, Eo) :- append(B, [B, loop|Ei], Eo).
142+combo(loop, [B, Expr|S], S, Ei, Eo) :-
143+ \+ Expr = true, \+ Expr = false,
144+ catch( % Try Expr and do one or the other,
145+ (Expr -> append(B, [B, loop|Ei], Eo) ; Ei=Eo),
146+ _, % If Expr don't grok, try both branches.
147+ (Ei=Eo ; append(B, [B, loop|Ei], Eo))
148+ ).
149+
150+combo(step, [_, []|S], S, E, E ).
151+combo(step, [P, [X]|S], [X|S], Ei, Eo) :- !, append(P, Ei, Eo).
152+combo(step, [P, [X|Z]|S], [X|S], Ei, Eo) :- append(P, [Z, P, step|Ei], Eo).
153+
154+combo(times, [_, 0|S], S, E, E ).
155+combo(times, [P, 1|S], S, Ei, Eo) :- append(P, Ei, Eo).
156+combo(times, [P, N|S], S, Ei, Eo) :- N #>= 2, M #= N - 1, append(P, [M, P, times|Ei], Eo).
157+combo(times, [_, N|S], S, _, _ ) :- N #< 0, fail.
158+
159+combo(genrec, [R1, R0, Then, If|S],
160+ [ Else, Then, If|S], E, [ifte|E]) :-
161+ Quoted = [If, Then, R0, R1, genrec],
162+ append(R0, [Quoted|R1], Else).
163+
164+
165+
166+
167+
168+
169+
98170
99171
100172
Show on old repository browser