chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] generate numerical list


From: Jinsong Liang
Subject: Re: [Chicken-users] generate numerical list
Date: Mon, 11 Jul 2016 22:52:50 -0400

Thank you Jeremy! Your code is very helpful.

Jinsong

On Mon, Jul 11, 2016 at 10:43 PM, Jeremy Steward <address@hidden> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Note that iota annoyingly does not work well with the numbers egg ->
it cannot figure out what an exact rational should be. So:

~     (use srfi-1 numbers)
~     (iota 1 10 (/ 3 2))

outputs:

~     Error: (iota) bad argument type - not a number: 3/2

Instead, you could define your own `iota` procedure after importing
the numbers egg using `unfold`, or you could define something like
MATLAB's `linspace`:

~     (define (my-iota count #!optional (start 0) (step 1))
~       (unfold (lambda (x) (>= (/ (- x start) step) count))
~               (lambda (x) x)
~               (lambda (x) (+ x step))
~               start))

~     (define (linspace base limit n)
~       (unfold (lambda (x) (> x limit))
~               (lambda (x) x)
~               (lambda (x) (+ x (/ (- limit base)
~                                   (- n 1))))
~               base))

~     (linspace 1 10 10) ;=> (1 2 3 4 5 6 7 8 9 10)
~     (linspace 0 50 5)  ;=> (0 25/2 25 75/2 50)

I'm sure I'm omitting some error checking in the above (for sequences
that would end up infinite), but it should get you on the right track
if you do find that SRFI-1 does not suffice when using exact rationals.

Regards,


On 11/07/16 08:21 PM, Evan Hanson wrote:
| Hi Jinsong,
|
| SRFI-1 provides `iota' -- http://api.call-cc.org/doc/srfi-1/iota
|
| Cheers,
|
| Evan
|
| _______________________________________________ Chicken-users
| mailing list address@hidden
| https://lists.nongnu.org/mailman/listinfo/chicken-users
|

- -- Jeremy Steward


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJXhFlbAAoJEKflx7ZMcbY7zIoQAJnzUGexanBT0TbCv+si8ikG
jUdQUstCMWXK/IJNMRYuaavm/c76bYxtOlrsjgv6HfXoQ8z0+mj/lwduS3GkNdvG
bL6QEWL5sgXIPmlbPWdATeslb/G+5zOVp2HygLhXoP92L5b2w+5Io5iWfBeJ9yUG
Xn6J5uxGBjyS5TQoYDQeNaTyuIqebPPxhsgCeEdKBKBr6D1kbfrZHc9MmiGXhDhh
jMpL/lQ7Wq3BcxUZYQe1MR4vn2sdm1p5tHtnAgI4xRylIyvRliSZiljMW8kwsB5S
6/TaLJSjJeo5TVTWtzdgI8LUbWPnYm1i021DKQPbqQzI0sSwTfFrbZgzFiIQzmL/
P4geRABA49TliHvwpUpf77DgC9U04O9bpoSM1Lzg3CTrQyANOOz5qj+S2MKLGcKU
irJgGPI+rrbHqBBuUGUOV4Lgi/+QSycyZ/JxuJZMONyWf0MjjCl4TkqB34atLHzP
xxrqe+hcronSYmz561xFNoUO3aaDtVo2gyG6eN9uEo/uH64N5Ob3B3Tw6fmQqNO2
bz1U6waurp3QDuUBYdGT1zGL0bm7MSAAGrGEi+ZBTvPRENLlh1zw8H3bSYT9uO6S
LAQNs2GzvmREr7VuGqrceQ6C8K16B41gifo6rJGVByrr+JGlCfjFtGs5k6z0dbSo
Ug6m2Fx3aWaOpnXjlmmI
=36Ss
-----END PGP SIGNATURE-----

_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users


reply via email to

[Prev in Thread] Current Thread [Next in Thread]