changeset a93b3f3743c4 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=a93b3f3743c4 user: Simon Forman <sform****@hushm*****> date: Tue Jul 16 08:41:28 2019 -0700 description: Add bool function to mimic Python semantics. changeset e36e5c99c757 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=e36e5c99c757 user: Simon Forman <sform****@hushm*****> date: Tue Jul 16 08:42:45 2019 -0700 description: Opps! Here's the implementation of bool. changeset 27f9aa8c4be8 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=27f9aa8c4be8 user: Simon Forman <sform****@hushm*****> date: Tue Jul 16 08:59:24 2019 -0700 description: Clear out CLP(FD) functions. I like them but then you are constrained (pun intended) to only using integers. I'll probably bring them back at some point, either as an alternate implementation or their own commands. changeset 624006d47b18 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=624006d47b18 user: Simon Forman <sform****@hushm*****> date: Tue Jul 16 09:46:55 2019 -0700 description: A little helper function to see compiled expressions. Example from ordered binary tree notebook: ?- sjc(tree_add_Ee, `pop swap rolldown rrest ccons`). func(tree_add_Ee, [_, [_, _|C], A, B|D], [[A, B|C]|D]). true . changeset 74a2447c4fe8 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=74a2447c4fe8 user: Simon Forman <sform****@hushm*****> date: Tue Jul 16 09:53:48 2019 -0700 description: More readable genrec. Explicit quoting is slightly more overhead but worth it I think to show what's going on more clearly. diffstat: joy/library.py | 1 - thun/defs.txt | 1 + thun/thun.pl | 32 +++++++++++++------------------- 3 files changed, 14 insertions(+), 20 deletions(-) diffs (100 lines): diff -r 15eb946b7887 -r 74a2447c4fe8 joy/library.py --- a/joy/library.py Mon Jul 15 23:02:08 2019 -0700 +++ b/joy/library.py Tue Jul 16 09:53:48 2019 -0700 @@ -908,7 +908,6 @@ S_step = Symbol('step') S_times = Symbol('times') S_swaack = Symbol('swaack') -S_truthy = Symbol('truthy') @inscribe diff -r 15eb946b7887 -r 74a2447c4fe8 thun/defs.txt --- a/thun/defs.txt Mon Jul 15 23:02:08 2019 -0700 +++ b/thun/defs.txt Tue Jul 16 09:53:48 2019 -0700 @@ -1,5 +1,6 @@ -- == 1 - ++ == 1 + +? == dup bool anamorphism == [pop []] swap [dip swons] genrec app1 == grba infrst app2 == [grba swap grba swap] dip [infrst] cons ii diff -r 15eb946b7887 -r 74a2447c4fe8 thun/thun.pl --- a/thun/thun.pl Mon Jul 15 23:02:08 2019 -0700 +++ b/thun/thun.pl Tue Jul 16 09:53:48 2019 -0700 @@ -91,10 +91,6 @@ func(swap, [A, B|S], [B, A|S]). func(dup, [A|S], [A, A|S]). func(pop, [_|S], S ). -% func(+, [A, B|S], [C|S]) :- C #= A + B. -% func(-, [A, B|S], [C|S]) :- C #= B - A. -% func(*, [A, B|S], [C|S]) :- C #= A * B. -% func(/, [A, B|S], [C|S]) :- C #= B div A. % Symbolic math. Compute the answer, or derivative, or whatever, later. func(+, [A, B|S], [B + A|S]). @@ -102,12 +98,9 @@ func(*, [A, B|S], [B * A|S]). func(/, [A, B|S], [B / A|S]). +% Attempt to calculate the value of a symbolic math expression. func(calc, [A|S], [B|S]) :- B is A. -% func(pm, [A, B|S], [C, D|S]) :- C #= A + B, D #= B - A. -% func(pm, [A, B|S], [B + A, B - A|S]). - -% func(sqrt, [A|S], [B|S]) :- B^2 #= A. func(sqrt, [A|S], [sqrt(A)|S]). func(concat, [A, B|S], [C|S]) :- append(B, A, C). @@ -127,6 +120,14 @@ func(rollup, Si, So) :- func(rolldown, So, Si). func(uncons, Si, So) :- func(cons, So, Si). +func(bool, [ 0|S], [false|S]) :- !. +func(bool, [ 0.0|S], [false|S]) :- !. +func(bool, [ []|S], [false|S]) :- !. +func(bool, [ ""|S], [false|S]) :- !. +func(bool, [false|S], [false|S]) :- !. + +func(bool, [_|S], [true|S]). + func(>, [A, B|S], [ true|S]) :- B > A. func(>, [A, B|S], [false|S]) :- \+ B > A. func(<, [A, B|S], [ true|S]) :- B < A. @@ -140,16 +141,6 @@ func(<>, [A, B|S], [ true|S]) :- B =\= A. func(<>, [A, B|S], [false|S]) :- B =:= A. -% func(>, [A, B|S], [T|S]) :- B #> A #<==> R, r_truth(R, T). -% func(<, [A, B|S], [T|S]) :- B #< A #<==> R, r_truth(R, T). -% func(=, [A, B|S], [T|S]) :- B #= A #<==> R, r_truth(R, T). -% func(>=, [A, B|S], [T|S]) :- B #>= A #<==> R, r_truth(R, T). -% func(<=, [A, B|S], [T|S]) :- B #=< A #<==> R, r_truth(R, T). -% func(<>, [A, B|S], [T|S]) :- B #\= A #<==> R, r_truth(R, T). - -r_truth(0, false). -r_truth(1, true). - /* Definitions @@ -200,7 +191,8 @@ combo(genrec, [R1, R0, Then, If|S], [ Else, Then, If|S], E, [ifte|E]) :- - append(R0, [[If, Then, R0, R1, genrec]|R1], Else). + Quoted = [If, Then, R0, R1, genrec], + append(R0, [Quoted|R1], Else). /* @@ -220,6 +212,8 @@ rule(Head, [], Head ). rule(Head, [A|B], Head :- maplist(call, [A|B])). +sjc(Name, InputString) :- phrase(joy_parse(E), InputString), show_joy_compile(Name, E). + % Simple DCGs to expand/contract definitions.