Re: [Chicken-users] generate numerical list
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 On 11/07/16 08:57 PM, John Cowan wrote: | Jeremy Steward scripsit: | |> Note that iota annoyingly does not work well with the numbers egg |> -> | | This is a general problem with the numbers egg and all other | Chicken code, whether part of the main build or an egg. If the | code is not *compiled* with the numbers egg, it will not know | anything about ratios, bignums, or complex numbers. | You are indeed correct on this. I apologize if I made it seem otherwise, as IIRC you can get many things working with the numbers egg by using the following: ~$ csc -X numbers ... | Chicken 5 will have a full numeric tower natively and won't have | this problem. And thanks to Peter for this and many other great things. - -- Jeremy Steward -BEGIN PGP SIGNATURE- Version: GnuPG v2 iQIcBAEBCAAGBQJXhF2DAAoJEKflx7ZMcbY79B8P/RXzzHoHDkABY2hopNJfazXy BFQVXko9P2MkVjS1Idl796FVPZVa9HA5quKeJLGj7pX12OZ5hYcZx9GG7jLGrMQF dq07Eo/iswfHWZXobCEcfqu/P7tOzXbHqqgDtzZS50HX+WLpTuhM4+S/QP/x30Id vBmV3tj2/JDO8U0yWol/212tySV2DZ8iLi3iHuuLCX50fPXGcGIVVS7jU1vC2Dme 2lmZEmdT92BtV4htpT4e0CtRi/eaAWTRfxCksfbdVy3TEkXaAo9yUWvhL4tFFyMF A+Il3kG9tS76w20y+nIhhIjocegMBUVWLZSPHxJrihr6gWPUA6vwmCZwEMCIFsaA LYx22yG3PLrejD2LQMLBcE/x+gTEnsxEdXsSFnU3YV97LSaEST1cbAQOpMlRdnx+ dKOmc8Ym3eZ7Vsu9K4/h3Bgg74D14aVk5XzRS9VVt5+p3S+8LkmxXabYe/7H4irT R+Y5Hf72LcRAFAZ/5lT+GooucYyVF1xbrNoWdi4Y3j0bgYg98sL2M7jgVwApiSjr bd3hcWEJfpH3SuyB95R2mMsdHSrGwjBwpANvM0e5fuuT8kS+QeHv+gIUB4BkYuF4 uTuyaHv4ic6S9ZcLlKo0JHb4e9kis86jJqpsmvIfzUWDw8XN4hKL7iMadR5VMuEg LLEOI08pb2PqQEUvvC9i =uy7o -END PGP SIGNATURE- ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] generate numerical list
Jeremy Steward scripsit: > Note that iota annoyingly does not work well with the numbers egg -> This is a general problem with the numbers egg and all other Chicken code, whether part of the main build or an egg. If the code is not *compiled* with the numbers egg, it will not know anything about ratios, bignums, or complex numbers. Chicken 5 will have a full numeric tower natively and won't have this problem. -- John Cowan http://www.ccil.org/~cowanco...@ccil.org If you have ever wondered if you are in hell, it has been said, then you are on a well-traveled road of spiritual inquiry. If you are absolutely sure you are in hell, however, then you must be on the Cross Bronx Expressway. --Alan Feuer, New York Times, 2002-09-20 ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] generate numerical list
Thank you Jeremy! Your code is very helpful. Jinsong On Mon, Jul 11, 2016 at 10:43 PM, Jeremy Stewardwrote: > -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 Chicken-users@nongnu.org > | 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 > Chicken-users@nongnu.org > https://lists.nongnu.org/mailman/listinfo/chicken-users > ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] generate numerical list
-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 Chicken-users@nongnu.org | 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 Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] generate numerical list
Exactly what I need. Thank you Evan! Jinsong On Mon, Jul 11, 2016 at 10:21 PM, Evan Hansonwrote: > Hi Jinsong, > > SRFI-1 provides `iota' -- http://api.call-cc.org/doc/srfi-1/iota > > Cheers, > > Evan > ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] generate numerical list
Hi Jinsong, SRFI-1 provides `iota' -- http://api.call-cc.org/doc/srfi-1/iota Cheers, Evan ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] generate numerical list
Hi, Is there an existing API to generate a list of numbers, given start value, end value, and step? For example, given 1, 2, and 0.5, a list of (1, 1.5, 2) is returned. Thank you! Jinsong ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users