• .Re: concentric loops

    From Robert L.@21:1/5 to All on Fri Feb 25 16:43:23 2022
    a question about the (loop ...) mechanism.
    How can i do something like the following with loop?

    nesting loops are better done with list comprehension, for example, with COLLECT macro:

    CL-USER>
    (collect list ((+ x y))
    (in x '(1 2 3))
    (in y '(10 20 30)))
    (11 21 31 12 22 32 13 23 33)

    Gauche Scheme or Racket:

    (use srfi-42) ; list-ec for Gauche
    or
    (require srfi/42) ; list-ec for Racket

    (list-ec (:list x '(7 8 9)) (:list y '(200 300 400))
    (+ x y))

    ===>
    (207 307 407 208 308 408 209 309 409)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to Peter Seibel on Sun Jun 9 07:24:55 2024
    Peter Seibel wrote:

    ( 11 12 13 21 22 23 31 32 33)

    I know that in CL plus is replaced by +, but how can I
    handle the mapcar inside the mapcan?

    (loop for x from 10 to 30 by 10 nconcing
    (loop for y from 1 to 3 collect (+ x y)))

    Gauche Scheme

    (use srfi-42) ; list-ec

    (list-ec (:range x 10 31 10) (:range y 1 4) (+ x y))

    ===>
    (11 12 13 21 22 23 31 32 33)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)