|
1857 | 1857 | last_item([Item],Item). |
1858 | 1858 |
|
1859 | 1859 | write_start(Type):- current_printer_override(P1),call(P1,'$write_start'(Type)),!. |
1860 | | -write_start(Char):- atom_length(Char, 1),write(Char),!. |
1861 | | -write_start(Type):- compound_type_s_m_e(Type,L,_,_),write(L),!. |
| 1860 | +write_start(Char):- is_str_char(Char),write_ch(Char),!. |
| 1861 | +write_start(Type):- compound_type_s_m_e(Type,L,_,_),write_ch(L),!. |
1862 | 1862 | write_middle(Type):- current_printer_override(P1),call(P1,'$write_middle'(Type)),!. |
1863 | | -write_middle(Char):- atom_length(Char, 1),write(Char),!. |
1864 | | -write_middle(Type):- compound_type_s_m_e(Type,_,M,_),write(M),!. |
| 1863 | +write_middle(Char):- is_str_char(Char),write_ch(Char),!. |
| 1864 | +write_middle(Type):- compound_type_s_m_e(Type,_,M,_), write_ch(M),!. |
1865 | 1865 | write_end(Type):- current_printer_override(P1),call(P1,'$write_end'(Type)),!. |
1866 | | -write_end(Char):- atom_length(Char, 1),write(Char),!. |
1867 | | -write_end(Type):- compound_type_s_m_e(Type,_,_,R),write(R),!. |
| 1866 | +write_end(Char):- is_str_char(Char),write_ch(Char),!. |
| 1867 | +write_end(Type):- compound_type_s_m_e(Type,_,_,R),write_ch(R),!. |
| 1868 | + |
| 1869 | +is_str_char( L ):- compound(L),arg(1,L,C),!,is_str_char(C). |
| 1870 | +is_str_char(Char):- atomic(Char), atom_length(Char, 1),!. |
| 1871 | + |
| 1872 | +write_ch(L):- compound(L),arg(1,L,C),!,write_ch(C). |
| 1873 | +write_ch(L):- assertion(L\==cmpd),write(L). |
1868 | 1874 |
|
1869 | 1875 | print_compound_type(Indent, Type, [H|T] ):- |
1870 | 1876 | last_item([H|T],Last), |
|
1880 | 1886 |
|
1881 | 1887 |
|
1882 | 1888 | compound_type_s_m_e(list,'(','.',')'). |
1883 | | -compound_type_s_m_e(cmpd,S,E,M):- prolog_term_start(S),compound_type_s_m_e(ocmpd,S,E,M),!. |
| 1889 | +compound_type_s_m_e(cmpd,S,E,M):- !, prolog_term_start(S),compound_type_s_m_e(ocmpd,S,E,M),!. |
1884 | 1890 | compound_type_s_m_e(ocmpd,'#(','.',')'). |
1885 | 1891 | compound_type_s_m_e(ocmpd,'[','|',']'). |
1886 | 1892 | compound_type_s_m_e(ocmpd,'{','|','}'). |
|
1895 | 1901 |
|
1896 | 1902 | % Print the rest of the elements in the list, ensuring spacing |
1897 | 1903 | print_rest_elements(_,T, _) :- T==[], !. |
1898 | | -print_rest_elements(M, T, Indent) :- \+ is_lcons(T), !, write(' '), write(M), write(' '), print_sexpr(T, Indent). |
1899 | | -print_rest_elements(M, [H|T], Indent) :- |
| 1904 | +print_rest_elements(Type, T, Indent) :- \+ is_lcons(T), !, write(' '), write_middle(Type), write(' '), print_sexpr(T, Indent). |
| 1905 | +print_rest_elements(Type, [H|T], Indent) :- |
1900 | 1906 | write(' '), % Space before each element after the first |
1901 | 1907 | print_sexpr(H, Indent), |
1902 | 1908 | (is_lcons(H) -> NextIndent is Indent + 0 ; NextIndent is Indent + 0), |
1903 | | - print_rest_elements(M, T, NextIndent). |
| 1909 | + print_rest_elements(Type, T, NextIndent). |
1904 | 1910 |
|
1905 | 1911 | % Helper predicate to print indentation spaces |
1906 | 1912 |
|
|
0 commit comments