[plt-scheme] Printing
I dont know of any standard either. My module is intended to produce output
that can be read by humans. In my module, format "f4.2" produces "****" when
fed with 13.14159, indicating that the result is not in the expected range,
although others may prefer to make it produce "13.1"
((((lambda(x)((((((x x)x)x)x)x)x))
(lambda(x)(lambda(y)(x(x y)))))
(lambda(x)(write x)x))
"greetings, Jos")
----- Original Message -----
From: "Richard Cleis" <rcleis at mac.com>
To: "jos koot" <jos.koot at tiscali.nl>
Cc: "PLT-list" <plt-scheme at list.cs.brown.edu>
Sent: Friday, October 21, 2005 5:46 PM
Subject: Re: [plt-scheme] Printing
> As far as I know, there is no standard formatting function since the topic
> is such a barrel of worms. In your example, what would you like the
> formatter to do if the '1.2' is fed with 13.14159?
>
> Writing a specific formatter for a program might be simple in your case,
> but I don't know what you are trying to do. These problems have solutions
> that might use:
>
> number->string ;; plt
> string->list ;; plt
> return-list-n-beyond-decimal ;; your recursive function
> list->string ;; plt
>
> If you don't like lists, then 'string-ref' can be used to extract
> individual characters:
>
> number->string ;; plt
> return-string-n-beyond-decimal ;; your function using string-ref
>
> Other methods use mathematical techniques based on 'truncate' and 'exp',
> and then a string is appended with integers sandwiching a decimal.
>
> There may be some stuff in the SRFIs, but I haven't looked.
>
> rac
>
>
>
> On Oct 21, 2005, at 6:46 AM, jos koot wrote:
>
>> Sent: Saturday, October 15, 2005 5:59 AM
>> Subject: [plt-scheme] Printing
>>> This is a really simple question, but I can't find the answer anywhere
>>> (help-desk, google, etc.). How do you control, how many decimal places
>>> get printed with a floating pointer number.
>>>
>>> For example I want somthing like:
>>>
>>> (define PI 3.1479)
>>>
>>> (printf "~1.2a\n" PI) => 3.14
>>>
>>> or
>>>
>>> (printf "~a\n" (decimal-places PI 2)) => 3.14
>>>
>>>
>>> Thanks,
>>>
>>> Evan
>