• Haskell

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Sat Aug 31 07:09:04 2024
    From Newsgroup: comp.lang.scheme

    Frank Buss wrote:

    Barry Margolin wrote:
    Which reminds me, where's the obligatory Haskell response?

    No problem :-)

    Assuming this is what was intended by the OP:

    (let (res)
    (dotimes (i 11 (nreverse res))
    (dotimes (j 11)
    (push (+ i j) res))))

    This is a solution in Haskell:

    [x + y | x <- [0..10], y <- [0..10]]


    It's shorter in Gauche Scheme than in Haskell.

    (use srfi-42) ; list-ec

    (list-ec (: x 11) (: y 11) (+ x y))

    Can it be done with a single "do*"?

    (do* ((r '())
    (j 0 (mod (+ j 1) 11))
    (i 0 (if (zero? j) (+ 1 i) i)))
    ((= 11 i) (reverse r))
    (push! r (+ i j)))

    (0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 2 3 4 5 6 7 8 9
    10 11 12 3 4 5 6 7 8 9 10 11 12 13 4 5 6 7 8 9 10 11 12 13 14
    5 6 7 8 9 10 11 12 13 14 15 6 7 8 9 10 11 12 13 14 15 16 7 8 9
    10 11 12 13 14 15 16 17 8 9 10 11 12 13 14 15 16 17 18 9 10 11
    12 13 14 15 16 17 18 19 10 11 12 13 14 15 16 17 18 19 20)


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Kaz Kylheku@643-408-1753@kylheku.com to comp.lang.lisp,comp.lang.scheme on Sun Sep 1 03:07:57 2024
    From Newsgroup: comp.lang.scheme

    On 2024-08-31, B. Pym <Nobody447095@here-nor-there.org> wrote:
    Frank Buss wrote:

    Barry Margolin wrote:
    Which reminds me, where's the obligatory Haskell response?

    No problem :-)

    Assuming this is what was intended by the OP:

    (let (res)
    (dotimes (i 11 (nreverse res))
    (dotimes (j 11)
    (push (+ i j) res))))

    This is a solution in Haskell:

    [x + y | x <- [0..10], y <- [0..10]]


    It's shorter in Gauche Scheme than in Haskell.

    (use srfi-42) ; list-ec

    (list-ec (: x 11) (: y 11) (+ x y))

    Can it be done with a single "do*"?

    (do* ((r '())
    (j 0 (mod (+ j 1) 11))
    (i 0 (if (zero? j) (+ 1 i) i)))
    ((= 11 i) (reverse r))
    (push! r (+ i j)))

    (0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 2 3 4 5 6 7 8 9
    10 11 12 3 4 5 6 7 8 9 10 11 12 13 4 5 6 7 8 9 10 11 12 13 14
    5 6 7 8 9 10 11 12 13 14 15 6 7 8 9 10 11 12 13 14 15 16 7 8 9
    10 11 12 13 14 15 16 17 8 9 10 11 12 13 14 15 16 17 18 9 10 11
    12 13 14 15 16 17 18 19 10 11 12 13 14 15 16 17 18 19 20)

    This is the TXR Lisp interactive listener of TXR 296.
    Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
    This could be the year of the TXR desktop; I can feel it!
    [maprod + 0..11 0..11]
    (0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 2 3 4 5 6 7 8
    9 10 11 12 3 4 5 6 7 8 9 10 11 12 13 4 5 6 7 8 9 10 11 12 13
    14 5 6 7 8 9 10 11 12 13 14 15 6 7 8 9 10 11 12 13 14 15 16 7
    8 9 10 11 12 13 14 15 16 17 8 9 10 11 12 13 14 15 16 17 18 9
    10 11 12 13 14 15 16 17 18 19 10 11 12 13 14 15 16 17 18 19 20)
    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca
    --- Synchronet 3.22a-Linux NewsLink 1.2