Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Don't worry. Life's too long. -- Vincent Sardi, Jr.


comp / comp.lang.scheme / Haskell

SubjectAuthor
* HaskellB. Pym
`- Re: HaskellKaz Kylheku

1
Subject: Haskell
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 31 Aug 2024 07:09 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Haskell
Date: Sat, 31 Aug 2024 07:09:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vaufic$u2ps$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 31 Aug 2024 09:09:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cd5bad8e55b4aa82d833cd99ecb8f893";
logging-data="985916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jEJ0NBK43BzjmiBcko8lZ"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:s4ZanRBqbqpFFoiyEuvum/Jfk6Q=
View all headers

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)

Subject: Re: Haskell
From: Kaz Kylheku
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sun, 1 Sep 2024 03:07 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Haskell
Date: Sun, 1 Sep 2024 03:07:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <20240831200512.688@kylheku.com>
References: <vaufic$u2ps$1@dont-email.me>
Injection-Date: Sun, 01 Sep 2024 05:07:57 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0e034b13bfff277bc16b176d591cb6d2";
logging-data="1441391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+p1Hm4orfS5TtbBIh7zJekhVQzhzG4WgI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:KQM2oJjtkbFL7iUyr/EpoLNI7is=
View all headers

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!
1> [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

1

rocksolid light 0.9.8
clearnet tor