how does print-to-codes work?
Jasper Taylor <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.bugs |
|---|---|
| Message-ID | <[email protected]> |
I have made a procedure that tidies up the printing of floats and it works OK if consulted as portray/1 for the built in print predicate. But if I use print_to_codes the result of portray/1 is still sent to the console. Here's an example... $ gprolog GNU Prolog 1.2.14 By Daniel Diaz Copyright (C) 1999-2002 Daniel Diaz | ?- print(2.92). 2.9199999999999999 yes | ?- print_to_codes(A, 2.92). A = [50,46,57,49,57,57,57,57,57,57,57,57,57,57,57,57,57,57] yes | ?- consult(nicefloat). compiling /win98/Program Files/Simile/Develop/Tests/nicefloat.pl for byte code... /win98/Program Files/Simile/Develop/Tests/nicefloat.pl compiled, 6 lines read - 1503 bytes written, 8 ms yes | ?- portray(2.92). 2.92 yes | ?- print(2.92). 2.92 yes | ?- print_to_codes(A, 2.92). 2.92 A = [] yes | ?-
nicefloat.pl
(text/x-perl, 146 B)
portray(F) :-
float(F),
format_to_codes(Fs, "~6f", [F]),
append(Ns, Os, Fs),
\+ (member(Ch, Os), \+ member(Ch, "0.")), !,
format("~s",[Ns]).