diff --git a/thun/gnu-prolog/Makefile b/thun/gnu-prolog/Makefile index d8b9db4..3c702ce 100644 --- a/thun/gnu-prolog/Makefile +++ b/thun/gnu-prolog/Makefile @@ -1,5 +1,6 @@ #GPLC_OPTIONS=--min-size GPLC_OPTIONS=--no-top-level +#GPLC_OPTIONS= thun: thun.pl parser.pl defs.pl main.pl math.pl Makefile gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl defs.pl main.pl math.pl diff --git a/thun/gnu-prolog/main.pl b/thun/gnu-prolog/main.pl index 5f5856a..fa4718c 100644 --- a/thun/gnu-prolog/main.pl +++ b/thun/gnu-prolog/main.pl @@ -20,6 +20,9 @@ Main Loop */ +% :- debug. +% :- spy(thun). + :- initialization(loop). loop :- prompt, line(Line), loop(Line, [], _Out). @@ -32,9 +35,8 @@ loop( Line, In, Out) :- line(NextLine), !, loop(NextLine, S, Out). - do_line(Line, In, Out) :- - phrase(joy_parse(E), Line), + phrase(joy_parse(E), Line), !, thun(E, In, Out). do_line(_Line, S, S) :- write('Err'), nl. diff --git a/thun/gnu-prolog/thun.pl b/thun/gnu-prolog/thun.pl index dacef59..55672a1 100644 --- a/thun/gnu-prolog/thun.pl +++ b/thun/gnu-prolog/thun.pl @@ -36,7 +36,7 @@ thun([Combo|E], Si, So) :- combo(Combo, Si, S, E, Eo), thun(Eo, S, So). thun([Unknown|E], Si, So) :- damned_thing(Unknown), - write(`wtf? `), + write(`huh? `), write(Unknown), nl, So = [[Unknown|E]|Si]. @@ -82,7 +82,8 @@ func(cons, [A, B|S], [[B|A]|S]). func(swap, [A, B|S], [B, A|S]). func(dup, [A|S], [A, A|S]). func(pop, [_|S], S ). -func(sqrt, [A|S], [sqrt(A)|S]). + +func(sqrt, [A|S], [B|S]) :- B is sqrt(A). func(concat, [A, B|S], [C|S]) :- append(B, A, C). func(flatten, [A|S], [B|S]) :- flatten(A, B).