Re: [Chicken-users] nested loop over lists

2016-07-15 Thread Jinsong Liang
Thank you Josh! I learned "unless" from your code to replace my (when (not ...)). Jinsong On Fri, Jul 15, 2016 at 7:29 PM, Josh Barrett wrote: > You can also use recursion: > (let l1 ((i '(1 2 3))) > (let l2 ((j '(4 5 6))) > (let l3 ((k '(7 8 9))) >

Re: [Chicken-users] nested loop over lists

2016-07-15 Thread Josh Barrett
You can also use recursion: (let l1 ((i '(1 2 3))) (let l2 ((j '(4 5 6))) (let l3 ((k '(7 8 9))) (print (+ (car i) (car j) (car k))) (unless (null? k) (l3 (cdr k (unless (null? j) (l2 (cdr j (unless (null? i) (l1 (cdr i))) This is generally

Re: [Chicken-users] nested loop over lists

2016-07-14 Thread Jinsong Liang
Hi Kevin, Thank you for your suggestions! It is good to know the "big 3". I will read the SRFI 1 documentation. Jinsong On Thu, Jul 14, 2016 at 1:55 PM, Kevin Wortman wrote: > > Another perspective, if you're new to Scheme, I'd recommend getting in the > habit of using

Re: [Chicken-users] nested loop over lists

2016-07-14 Thread Kevin Wortman
Another perspective, if you're new to Scheme, I'd recommend getting in the habit of using higher-order procedures before loops. The principle is that looping is an error-prone (e.g. infinite loops) low level operation, so it's best to factor that out and use an established and tested library

Re: [Chicken-users] nested loop over lists

2016-07-14 Thread Jinsong Liang
Wow, this is amazing! Thanks a lot Christian! Jinsong On Thu, Jul 14, 2016 at 3:05 AM, Christian Kellermann wrote: > * Jinsong Liang [160714 04:26]: > > Hi, > > > > I want to do nested loops over three lists like the following pseudo > code: > > >

Re: [Chicken-users] nested loop over lists

2016-07-14 Thread Christian Kellermann
* Jinsong Liang [160714 04:26]: > Hi, > > I want to do nested loops over three lists like the following pseudo code: > > for i in '(1 2 3) > for j in '(4 5 6) > for k in '(7 8 9) > //do calculation using i, j, and k. The three lists are not > related.

[Chicken-users] nested loop over lists

2016-07-13 Thread Jinsong Liang
Hi, I want to do nested loops over three lists like the following pseudo code: for i in '(1 2 3) for j in '(4 5 6) for k in '(7 8 9) //do calculation using i, j, and k. The three lists are not related. end end end What is the best way to do this in Chicken? I