[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how does print-to-codes work?
From: |
Daniel Diaz |
Subject: |
Re: how does print-to-codes work? |
Date: |
Thu, 12 Sep 2002 12:17:05 +0200 |
Try to use get_print_stream/1 inside your portray predicate: like:
portray(F) :-
float(F),
format_to_codes(Fs, "~6f", [F]),
append(Ns, Os, Fs),
\+ (member(Ch, Os), \+ member(Ch, "0.")), !,
get_print_stream(Stream),
format(Stream,"~s",[Ns]).
This should work
Jasper Taylor wrote:
>
> 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
> | ?-
>
> ------------------------------------------------------------------------
> Name: nicefloat.pl
> nicefloat.pl Type: Perl Program (application/x-perl)
> Encoding: 7bit
--
Ce message a subi une analyse antivirus
par MailScanner ; il est vraisemblablement
sans danger.
- Re: how does print-to-codes work?,
Daniel Diaz <=