Created
October 11, 2018 23:14
-
-
Save hsk/7dde20d18a306fa3f62743f2a9cc5a18 to your computer and use it in GitHub Desktop.
pprint.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| spaceN(N,R2):-findall(' ',between(1,N,_),R),concat_atom(R,R2). | |
| pprint(FP,T) :- tell(FP),pprint(T),tell(user_output). | |
| pprint(T) :- pprint1(0,T),writeln(.). | |
| pprint1(_,T) :- atomic(T),print(T). | |
| pprint1(N,T) :- format(atom(V),'~p',[T]),atom_length(V,N1),N2 is N1+N,N2 < 80,write(V). | |
| pprint1(N,T) :- is_list(T), writeln('['),N1 is N+1,pplist(N1,T),printSpace(N),write(']'). | |
| pprint1(N,A:B) :- writeq(A),write(:),pprint1(N,B). | |
| pprint1(N,A) :- A =..[P|Ps], write(P),write('('),ppparams(N,Ps),write(')'). | |
| ppparams(_,[]). | |
| ppparams(N,[A]):-pprint1(N,A). | |
| ppparams(N,[A|As]) :- pprint1(N,A),write(,),ppparams(N,As). | |
| printSpace(N) :- spaceN(N,R),write(R). | |
| pplist(_,[]). | |
| pplist(N,[A]):- printSpace(N),pprint1(N,A),nl. | |
| pplist(N,[A|As]) :- printSpace(N),pprint1(N,A),writeln(,),pplist(N,As). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment