changeset b9f4b2453b12 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=b9f4b2453b12 user: Simon Forman <sform****@hushm*****> date: Sun Aug 11 15:12:56 2019 -0700 description: Don't shadow funcs and combos. changeset 27d6936bbc54 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=27d6936bbc54 user: Simon Forman <sform****@hushm*****> date: Sun Aug 11 17:00:38 2019 -0700 description: Clean up REPL formatting. diffstat: thun/gnu-prolog/defs.pl | 4 ---- thun/gnu-prolog/main.pl | 8 ++++++-- thun/gnu-prolog/meta-defs.pl | 9 ++++++++- thun/gnu-prolog/parser.pl | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) diffs (126 lines): diff -r 3d02093c3fe9 -r 27d6936bbc54 thun/gnu-prolog/defs.pl --- a/thun/gnu-prolog/defs.pl Sun Aug 11 14:56:20 2019 -0700 +++ b/thun/gnu-prolog/defs.pl Sun Aug 11 17:00:38 2019 -0700 @@ -17,11 +17,9 @@ def(disenstacken,[?,[uncons,?],loop,pop]). def(down_to_zero,[[0,>],[dup,--],while]). def(drop,[[rest],times]). -def(dupd,[[dup],dip]). def(dupdd,[[dup],dipd]). def(dupdipd,[dup,dipd]). def(enstacken,[stack,[clear],dip]). -def(flatten,[[],swap,[concat],step]). def(fork,[[i],app2]). def(fourth,[rest,third]). def(gcd,[true,[tuck,mod,dup,0,>],loop,pop]). @@ -52,7 +50,6 @@ def(rrest,[rest,rest]). def(run,[[],swap,infra]). def(second,[rest,first]). -def(shift,[uncons,[swons],dip]). def(shunt,[[swons],step]). def(size,[0,swap,[pop,++],step]). def(split_at,[[drop],[take],clop]). @@ -64,7 +61,6 @@ def(ternary,[binary,popd]). def(third,[rest,second]). def(unary,[nullary,popd]). -def(unit,[[],cons]). def(unquoted,[[i],dip]). def(unswons,[uncons,swap]). def(while,[swap,[nullary],cons,dup,dipd,concat,loop]). diff -r 3d02093c3fe9 -r 27d6936bbc54 thun/gnu-prolog/main.pl --- a/thun/gnu-prolog/main.pl Sun Aug 11 14:56:20 2019 -0700 +++ b/thun/gnu-prolog/main.pl Sun Aug 11 17:00:38 2019 -0700 @@ -22,12 +22,13 @@ :- initialization(loop). -loop :- line(Line), loop(Line, [], _Out). +loop :- prompt, line(Line), loop(Line, [], _Out). loop([eof], S, S) :- !. loop( Line, In, Out) :- do_line(Line, In, S), - write(S), nl, + show_stack(S), + prompt, line(NextLine), !, loop(NextLine, S, Out). @@ -35,3 +36,6 @@ do_line(Line, In, Out) :- phrase(joy_parse(E), Line), thun(E, In, Out). do_line(_Line, S, S) :- write('Err'), nl. +prompt :- write(`joy? `). +show_stack(S) :- nl, print_stack(S), write(` <-top`), nl, nl. + diff -r 3d02093c3fe9 -r 27d6936bbc54 thun/gnu-prolog/meta-defs.pl --- a/thun/gnu-prolog/meta-defs.pl Sun Aug 11 14:56:20 2019 -0700 +++ b/thun/gnu-prolog/meta-defs.pl Sun Aug 11 17:00:38 2019 -0700 @@ -6,9 +6,12 @@ joy_def(def(Def, Body)) --> symbol(Def), blanks, "==", joy_parse(Body). -joy_defs --> blanks, joy_def(Def), {assert_def(Def)}, blanks, joy_defs. +joy_def --> joy_def(Def), {ignore(assert_def(Def))}. + +joy_defs --> blanks, joy_def, blanks, joy_defs. joy_defs --> []. + assert_defs(DefsFile) :- read_file_to_codes(DefsFile, Codes, []), phrase(joy_defs, Codes). @@ -42,3 +45,7 @@ print_def(Stream, Def) :- write(Stream, Def), write(Stream, `.`), nl(Stream). + +ignore(Goal) :- Goal, !. +ignore(_). + diff -r 3d02093c3fe9 -r 27d6936bbc54 thun/gnu-prolog/parser.pl --- a/thun/gnu-prolog/parser.pl Sun Aug 11 14:56:20 2019 -0700 +++ b/thun/gnu-prolog/parser.pl Sun Aug 11 17:00:38 2019 -0700 @@ -68,3 +68,40 @@ digit(C) --> [C], { nonvar(C), C =< 57, C >= 48 }. + +/* + +Print state. + +*/ + +format_state(Stack, Expression, Codes) :- + reverse(Stack, RStack), + phrase(format_joy(RStack), RStackCodes), + phrase(format_joy(Expression), ExpressionCodes), + append(RStackCodes, [32, 46, 32|ExpressionCodes], Codes). + + +frump(Stack, Expression) :- + format_state(Stack, Expression, Codes), + maplist(put_code, Codes), nl. + +print_stack(Stack) :- + reverse(Stack, RStack), + phrase(format_joy(RStack), Codes), + maplist(put_code, Codes). + + + +% Print Joy expressions as text. + +format_joy(Tail) --> {var(Tail)}, !, [46, 46, 46]. +format_joy([T]) --> format_term(T), !. +format_joy([T|S]) --> format_term(T), " ", format_joy(S). +format_joy([]) --> []. + +format_term(N) --> {number(N), number_codes(N, Codes)}, Codes. +format_term(A) --> { atom(A), atom_codes(A, Codes)}, Codes. +format_term([A|As]) --> "[", format_joy([A|As]), "]". + +