Here's something I'm using for now:
> (table (xy-data sin 10 0 0.1) 3)
0.0 0.0
0.1 0.1
0.2 0.199
0.3 0.296
0.4 0.389
0.5 0.479
0.6 0.565
0.7 0.644
0.8 0.717
0.9 0.783
> (table (xy-data sin 11 -0.5 0.1) 3)
-0.5 -0.479
-0.4 -0.389
-0.3 -0.296
-0.2 -0.199
-0.1 -0.1
0.0 0.0
0.1 0.1
0.2 0.199
0.3 0.296
0.4 0.389
0.5 0.479
>
Where 'table' and 'xy-data' are:
(define (round-to n)
(lambda (x)
(/ (round (* x (expt 10 n)))
(expt 10 n))))
(define (table data decimal-places)
(let ((rounder (round-to decimal-places)))
(fmt #t
nl
(join (lambda (entry)
(cat (dsp (rounder (list-ref entry 0)))
(space-to 10)
(dsp (rounder (list-ref entry 1)))))
data
nl)
nl)))
(define (xy-data f n start step)
(map (lambda (x)
(list x (f x)))
(iota n start step)))
Now the only trick is to align the decimal places.
I decided not to use the 'num' formatters support for precision. I
wanted it to print as above, i.e. 0.1 instead of 0.100 for example. The
precision parameter seems to always cause the numbers to have the
specified number of decimal places.
Also, there should probably be a more intelligent spacer, as opposed to
the hardcoded '(space-to 10)'.
Suggestions from fmt experts welcome! :-)
Ed