Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"The Street finds its own uses for technology." -- William Gibson


devel / comp.lang.lisp / ( for... break... else ) in Common Lisp and Scheme ?

SubjectAuthor
* ( for... break... else ) in Common Lisp and Scheme ?Hen Hanna
+* Re: ( for... break... else ) in Common Lisp and Scheme ?Madhu
|+* Re: ( for... break... else ) in Common Lisp and Scheme ?Alan Bawden
||+- Re: ( for... break... else ) in Common Lisp and Scheme ?Tom Russ
||+- Re: ( for... break... else ) in Common Lisp and Scheme ?Alan Bawden
||`* Re: ( for... break... else ) in Common Lisp and Scheme ?Madhu
|| `- Re: ( for... break... else ) in Common Lisp and Scheme ?Madhu
|`* Re: ( for... break... else ) in Common Lisp and Scheme ?Hen Hanna
| `* Re: ( for... break... else ) in Common Lisp and Scheme ?Jay Freeman
|  `- Re: ( for... break... else ) in Common Lisp and Scheme ?Jay Freeman
+* Re: ( for... break... else ) in Common Lisp and Scheme ?Spiros Bousbouras
|`- Re: ( for... break... else ) in Common Lisp and Scheme ?Hen Hanna
`- Re: ( for... break... else ) in Common Lisp and Scheme ?Hen Hanna

1
( for... break... else ) in Common Lisp and Scheme ?

<d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17321&group=comp.lang.lisp#17321

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ac8:1e98:0:b0:3bd:134f:6490 with SMTP id c24-20020ac81e98000000b003bd134f6490mr2824415qtm.9.1678079013081;
Sun, 05 Mar 2023 21:03:33 -0800 (PST)
X-Received: by 2002:a05:6902:524:b0:8e2:6b58:5fe8 with SMTP id
y4-20020a056902052400b008e26b585fe8mr5757712ybs.10.1678079012670; Sun, 05 Mar
2023 21:03:32 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Sun, 5 Mar 2023 21:03:32 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=2601:648:8600:b8a0:ccbe:510c:e3fe:cc8c;
posting-account=YjTkGAoAAAA4_fbAISfvtIqrYbghMeBx
NNTP-Posting-Host: 2601:648:8600:b8a0:ccbe:510c:e3fe:cc8c
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
Subject: ( for... break... else ) in Common Lisp and Scheme ?
From: henhanna@gmail.com (Hen Hanna)
Injection-Date: Mon, 06 Mar 2023 05:03:33 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1696
 by: Hen Hanna - Mon, 6 Mar 2023 05:03 UTC

in CL (Common Lisp) , i'd use catch/throw ?

in Scheme , i'd have to use Call/cc ?

https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops

for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
# loop fell through without finding a factor
print(n, 'is a prime number')

2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3

the keyword ELSE doesn't quite sound right.

Re: ( for... break... else ) in Common Lisp and Scheme ?

<m3pm9m9pri.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17323&group=comp.lang.lisp#17323

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
Date: Mon, 06 Mar 2023 15:15:53 +0530
Organization: Motzarella
Lines: 45
Message-ID: <m3pm9m9pri.fsf@leonis4.robolove.meer.net>
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="a57bb8277d17777aa658eb9a4f8d6479";
logging-data="1749273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ogHY/ptcuztiYH9q0UNz7eKRCq42F04M="
Cancel-Lock: sha1:SkFp307tbGxtqtrZNPzNna+qWvw=
sha1:OcZS8QstSbf+t8T77cHZ1c4V7r0=
 by: Madhu - Mon, 6 Mar 2023 09:45 UTC

* Hen Hanna <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com> :
Wrote on Sun, 5 Mar 2023 21:03:32 -0800 (PST):

> in CL (Common Lisp) , i'd use catch/throw ?

I think to implement the control structure indicated in python one would
require co-routines at the language level. Common Lisp does have
co-routines, and so cannot adequately implement the pattern.

I haven't come across or used a call/cc implementation in CL which lets
me express this (with the semantics as the python generator), I think in
principe it shouldn't be possible but I haven't all all call/cc
packages. if you find one do let me know. (The closest thing I've seen
of something that's capable of implementing this is probably the
co-operative multithreading MP package in cmucl)

> in Scheme , i'd have to use Call/cc ?
>
> https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
>
> for n in range(2, 10):
> for x in range(2, n):
> if n % x == 0:
> print(n, 'equals', x, '*', n//x)
> break
> else:
> # loop fell through without finding a factor
> print(n, 'is a prime number')
>
>
> 2 is a prime number
> 3 is a prime number
> 4 equals 2 * 2
> 5 is a prime number
> 6 equals 2 * 3
> 7 is a prime number
> 8 equals 2 * 4
> 9 equals 3 * 3
>
>
> the keyword ELSE doesn't quite sound right.

the else: matches the if: and should probably be aligned to it.

Re: ( for... break... else ) in Common Lisp and Scheme ?

<IWmvFYEomkeiBdQ=Z@bongo-ra.co>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17324&group=comp.lang.lisp#17324

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.cyber23.de!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
Date: Mon, 6 Mar 2023 12:26:29 -0000 (UTC)
Organization: Cyber23 news
Message-ID: <IWmvFYEomkeiBdQ=Z@bongo-ra.co>
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 6 Mar 2023 12:26:29 -0000 (UTC)
Injection-Info: news.cyber23.de;
logging-data="64200"; mail-complaints-to="abuse@cyber23.de"
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
In-Reply-To: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
 by: Spiros Bousbouras - Mon, 6 Mar 2023 12:26 UTC

On Sun, 5 Mar 2023 21:03:32 -0800 (PST)
Hen Hanna <henhanna@gmail.com> wrote:
> in CL (Common Lisp) , i'd use catch/throw ?

You could do it with CATCH and THROW but for this kind of thing RETURN
is more natural.

> in Scheme , i'd have to use Call/cc ?

You'd be better off asking this on comp.lang.scheme .

> https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
>
> for n in range(2, 10):
> for x in range(2, n):
> if n % x == 0:
> print(n, 'equals', x, '*', n//x)
> break
> else:
> # loop fell through without finding a factor
> print(n, 'is a prime number')
>
>
> 2 is a prime number
> 3 is a prime number
> 4 equals 2 * 2
> 5 is a prime number
> 6 equals 2 * 3
> 7 is a prime number
> 8 equals 2 * 4
> 9 equals 3 * 3

(do ((n 2 (+ 1 n)))
((eql n 10))
(do ((x 2 (+ 1 x)))
((eql x n) (format t "~A is a prime number~%" n))
(when (eql 0 (mod n x))
(format t "~A equals ~A * ~A~%" n x (/ n x))
(return))))

Or , to avoid doing the division of n / x twice ,

(do ((n 2 (+ 1 n)))
((eql n 10))
(do ((x 2 (+ 1 x)))
((eql x n) (format t "~A is a prime number~%" n))
(multiple-value-bind (quot rem) (floor n x)
(when (eql 0 rem)
(format t "~A equals ~A * ~A~%" n x quot)
(return)))))

> the keyword ELSE doesn't quite sound right.

For this kind of construct it doesn't sound right to me either. Perhaps
something like loop_ended would better express what's happening.

--
vlaho.ninja/prog

Re: ( for... break... else ) in Common Lisp and Scheme ?

<86edq1wz9h.fsf@williamsburg.bawden.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17325&group=comp.lang.lisp#17325

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: alan@csail.mit.edu (Alan Bawden)
Newsgroups: comp.lang.lisp
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
Date: Mon, 06 Mar 2023 12:44:26 -0500
Organization: ITS Preservation Society
Lines: 28
Message-ID: <86edq1wz9h.fsf@williamsburg.bawden.org>
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
<m3pm9m9pri.fsf@leonis4.robolove.meer.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="4d1526e8d44a73b1f5771660cdd060a6";
logging-data="18351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wWT6YjBJfnhA9TeGz8LOp"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock: sha1:/HAB2+iWOK5gwH3+Elg9WcKBN+A=
sha1:rNsyldiWWJLL5Gj4QZPAniokNVM=
 by: Alan Bawden - Mon, 6 Mar 2023 17:44 UTC

Madhu <enometh@meer.net> writes:
>
> https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
>
> for n in range(2, 10):
> for x in range(2, n):
> if n % x == 0:
> print(n, 'equals', x, '*', n//x)
> break
> else:
> # loop fell through without finding a factor
> print(n, 'is a prime number')

the else: matches the if: and should probably be aligned to it.

No, it really does match the 'for x'. This use of 'else' is a
(controversial) feature of Python. The code above is quoted directly
from the Python tutorial at the given URL, which nicely explains how it
works.

It's controversial, not because there is something wrong with the
feature itself, but because many people find naming it 'else' to be
confusing.

There is probably a LOOP clause that means the same thing, but I'm too
lazy to look that up (since I never use LOOP).

- Alan

Re: ( for... break... else ) in Common Lisp and Scheme ?

<cc68c6bc-c9fb-4380-8650-b32b884ef484n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17326&group=comp.lang.lisp#17326

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ad4:5a08:0:b0:56e:a203:5d1f with SMTP id ei8-20020ad45a08000000b0056ea2035d1fmr3079551qvb.5.1678126028275;
Mon, 06 Mar 2023 10:07:08 -0800 (PST)
X-Received: by 2002:a81:b71c:0:b0:536:7529:55b4 with SMTP id
v28-20020a81b71c000000b00536752955b4mr7357117ywh.3.1678126027874; Mon, 06 Mar
2023 10:07:07 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 6 Mar 2023 10:07:07 -0800 (PST)
In-Reply-To: <86edq1wz9h.fsf@williamsburg.bawden.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8000:7603:1703:e809:195b:47b3:36b6;
posting-account=05zmAwoAAAAJZM-3jv1hCWLHGZQceqwA
NNTP-Posting-Host: 2603:8000:7603:1703:e809:195b:47b3:36b6
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
<m3pm9m9pri.fsf@leonis4.robolove.meer.net> <86edq1wz9h.fsf@williamsburg.bawden.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cc68c6bc-c9fb-4380-8650-b32b884ef484n@googlegroups.com>
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
From: taruss@google.com (Tom Russ)
Injection-Date: Mon, 06 Mar 2023 18:07:08 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Tom Russ - Mon, 6 Mar 2023 18:07 UTC

On Monday, March 6, 2023 at 9:44:33 AM UTC-8, Alan Bawden wrote:
> Madhu <eno...@meer.net> writes:
> >
> > https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
> >
> > for n in range(2, 10):
> > for x in range(2, n):
> > if n % x == 0:
> > print(n, 'equals', x, '*', n//x)
> > break
> > else:
> > # loop fell through without finding a factor
> > print(n, 'is a prime number')
> the else: matches the if: and should probably be aligned to it.
> No, it really does match the 'for x'. This use of 'else' is a
> (controversial) feature of Python. The code above is quoted directly
> from the Python tutorial at the given URL, which nicely explains how it
> works.
>
> It's controversial, not because there is something wrong with the
> feature itself, but because many people find naming it 'else' to be
> confusing.
>
> There is probably a LOOP clause that means the same thing, but I'm too
> lazy to look that up (since I never use LOOP).

Since you insist :)

(loop for n from 2 below 10
do (loop for x from 2 below n
when (zerop (mod n x))
do (format t "~d equals ~d * ~d~%" n x (/ n x))
and return nil
finally (format t "~d is a prime number.~%" n)))

Re: ( for... break... else ) in Common Lisp and Scheme ?

<867cvtwy14.fsf@williamsburg.bawden.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17327&group=comp.lang.lisp#17327

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: alan@csail.mit.edu (Alan Bawden)
Newsgroups: comp.lang.lisp
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
Date: Mon, 06 Mar 2023 13:11:03 -0500
Organization: ITS Preservation Society
Lines: 13
Message-ID: <867cvtwy14.fsf@williamsburg.bawden.org>
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
<m3pm9m9pri.fsf@leonis4.robolove.meer.net>
<86edq1wz9h.fsf@williamsburg.bawden.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="4d1526e8d44a73b1f5771660cdd060a6";
logging-data="27255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2irYMRM2p/26HmekM2fLH"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock: sha1:5lci+uCHqnu9hMAWoqoHWBMgoAE=
sha1:edkaxnbVr8UfFsmuFe69ULrMU+U=
 by: Alan Bawden - Mon, 6 Mar 2023 18:11 UTC

Alan Bawden <alan@csail.mit.edu> writes:

There is probably a LOOP clause that means the same thing, but I'm too
lazy to look that up....

And let me add before somebody else points it out: it's also the same
as the "result-form" in a DO loop. I didn't think of that at first
because DO doesn't have keywords that introduce clauses...

In any case there is no need to reach for anything like CATCH/THROW for
this.

- Alan

Re: ( for... break... else ) in Common Lisp and Scheme ?

<m3ilfdaft1.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17328&group=comp.lang.lisp#17328

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
Date: Tue, 07 Mar 2023 00:05:38 +0530
Organization: Motzarella
Lines: 45
Message-ID: <m3ilfdaft1.fsf@leonis4.robolove.meer.net>
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
<m3pm9m9pri.fsf@leonis4.robolove.meer.net>
<86edq1wz9h.fsf@williamsburg.bawden.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="ca499635c9255ca4f7a84df487373f54";
logging-data="31670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eh2nKoBWPZRZ0d2rSrIvcizGsvC1OuvI="
Cancel-Lock: sha1:7Zj2b+1HyMDV/Qz4wfaOd72650I=
sha1:+ApZjvaJ9NIuoXIN9iAQqTriTjI=
 by: Madhu - Mon, 6 Mar 2023 18:35 UTC

* Alan Bawden <86edq1wz9h.fsf@williamsburg.bawden.org> :
Wrote on Mon, 06 Mar 2023 12:44:26 -0500:

> Madhu <enometh@meer.net> writes:
> >
> > https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
> the else: matches the if: and should probably be aligned to it.
>
> No, it really does match the 'for x'. This use of 'else' is a
> (controversial) feature of Python. The code above is quoted directly
> from the Python tutorial at the given URL, which nicely explains how it
> works.

Thanks for pointing it out. ("My blushes if it were possible]")

> It's controversial, not because there is something wrong with the
> feature itself, but because many people find naming it 'else' to be
> confusing.
>
> There is probably a LOOP clause that means the same thing, but I'm too
> lazy to look that up (since I never use LOOP).

LOOP doesn't have Continue. Breaking is by means of RETURN (or
RETURN-FROM a named loop) at any point. and the FINALLY block is
executed when the loop completes normally.

> >
> > for n in range(2, 10):
> > for x in range(2, n):
> > if n % x == 0:
> > print(n, 'equals', x, '*', n//x)
> > break
> > else:
> > # loop fell through without finding a factor
> > print(n, 'is a prime number')

so maybe

(loop for n from 2 below 10 do
(loop for x from 2 below n
if (zerop (mod n x))
do (return (print (list n '= x '* (/ n x))))
finally (print (list n 'isprime))))

Re: ( for... break... else ) in Common Lisp and Scheme ?

<54e2236b-f930-46b1-8428-5c0bcf58dfa4n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17329&group=comp.lang.lisp#17329

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ac8:20b:0:b0:3bf:c315:44df with SMTP id k11-20020ac8020b000000b003bfc31544dfmr3687015qtg.12.1678133165166;
Mon, 06 Mar 2023 12:06:05 -0800 (PST)
X-Received: by 2002:a5b:c11:0:b0:acc:533b:9451 with SMTP id
f17-20020a5b0c11000000b00acc533b9451mr7235355ybq.0.1678133164703; Mon, 06 Mar
2023 12:06:04 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 6 Mar 2023 12:06:04 -0800 (PST)
In-Reply-To: <IWmvFYEomkeiBdQ=Z@bongo-ra.co>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:648:8600:860:70a7:60e9:9bbc:ba3d;
posting-account=YjTkGAoAAAA4_fbAISfvtIqrYbghMeBx
NNTP-Posting-Host: 2601:648:8600:860:70a7:60e9:9bbc:ba3d
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com> <IWmvFYEomkeiBdQ=Z@bongo-ra.co>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <54e2236b-f930-46b1-8428-5c0bcf58dfa4n@googlegroups.com>
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
From: henhanna@gmail.com (Hen Hanna)
Injection-Date: Mon, 06 Mar 2023 20:06:05 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3664
 by: Hen Hanna - Mon, 6 Mar 2023 20:06 UTC

On Monday, March 6, 2023 at 4:26:34 AM UTC-8, Spiros Bousbouras wrote:
> On Sun, 5 Mar 2023 21:03:32 -0800 (PST)
> Hen Hanna <henh...@gmail.com> wrote:
> > in CL (Common Lisp) , i'd use catch/throw ?
> You could do it with CATCH and THROW but for this kind of thing RETURN
> is more natural.
> > in Scheme , i'd have to use Call/cc ?
> You'd be better off asking this on comp.lang.scheme .
> > https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
> >
> > for n in range(2, 10):
> > for x in range(2, n):
> > if n % x == 0:
> > print(n, 'equals', x, '*', n//x)
> > break
> > else:
> > # loop fell through without finding a factor
> > print(n, 'is a prime number')
> >
> >
> > 2 is a prime number
> > 3 is a prime number
> > 4 equals 2 * 2
> > 5 is a prime number
> > 6 equals 2 * 3
> > 7 is a prime number
> > 8 equals 2 * 4
> > 9 equals 3 * 3
> (do ((n 2 (+ 1 n)))
> ((eql n 10))
> (do ((x 2 (+ 1 x)))
> ((eql x n) (format t "~A is a prime number~%" n))
> (when (eql 0 (mod n x))
> (format t "~A equals ~A * ~A~%" n x (/ n x))
> (return))))
>
> Or , to avoid doing the division of n / x twice ,
>
> (do ((n 2 (+ 1 n)))
> ((eql n 10))
> (do ((x 2 (+ 1 x)))
> ((eql x n) (format t "~A is a prime number~%" n))
> (multiple-value-bind (quot rem) (floor n x)
> (when (eql 0 rem)
> (format t "~A equals ~A * ~A~%" n x quot)
> (return)))))

> > the keyword ELSE doesn't quite sound right.

> For this kind of construct it doesn't sound right to me either. Perhaps
> something like loop_ended would better express what's happening.

thanks so much!!!

other candidates are:
for_loop_end: for_nomalend: for_end: ..........

At first, the REuse of the keyword ELSE seemed clever, but
it doesn't quite sound right, and another name that clarifies the matching-pair aspect would be better.

gosh> (+ a b) *** ERROR: operation + is not defined between "12" and "345"

Python's semantic overloading of + is a big win, but not for ELSE

I wonder... if elsewhere in Python , Lisp, or Scheme... there's similar misguided semantic overloading (?)

Re: ( for... break... else ) in Common Lisp and Scheme ?

<be6eff4a-c35e-40e3-96bf-48d3a7635d69n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17331&group=comp.lang.lisp#17331

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ad4:4a72:0:b0:56f:52da:1d2c with SMTP id cn18-20020ad44a72000000b0056f52da1d2cmr3593721qvb.7.1678156253250;
Mon, 06 Mar 2023 18:30:53 -0800 (PST)
X-Received: by 2002:a81:b286:0:b0:533:9185:fc2c with SMTP id
q128-20020a81b286000000b005339185fc2cmr8334268ywh.7.1678156252836; Mon, 06
Mar 2023 18:30:52 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 6 Mar 2023 18:30:52 -0800 (PST)
In-Reply-To: <m3pm9m9pri.fsf@leonis4.robolove.meer.net>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:648:8600:860:70a7:60e9:9bbc:ba3d;
posting-account=YjTkGAoAAAA4_fbAISfvtIqrYbghMeBx
NNTP-Posting-Host: 2601:648:8600:860:70a7:60e9:9bbc:ba3d
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com> <m3pm9m9pri.fsf@leonis4.robolove.meer.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <be6eff4a-c35e-40e3-96bf-48d3a7635d69n@googlegroups.com>
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
From: henhanna@gmail.com (Hen Hanna)
Injection-Date: Tue, 07 Mar 2023 02:30:53 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3173
 by: Hen Hanna - Tue, 7 Mar 2023 02:30 UTC

On Monday, March 6, 2023 at 1:45:59 AM UTC-8, Madhu wrote:
> * Hen Hanna <d568b860-a810-4506...@googlegroups.com> :
> Wrote on Sun, 5 Mar 2023 21:03:32 -0800 (PST):

> > in CL (Common Lisp) , i'd use catch/throw ?

> I think to implement the control structure indicated in python one would
> require co-routines at the language level. Common Lisp does have
> co-routines, and so cannot adequately implement the pattern.
>
> I haven't come across or used a call/cc implementation in CL which lets
> me express this (with the semantics as the python generator), I think in
> principe it shouldn't be possible but I haven't all all call/cc
> packages. if you find one do let me know. (The closest thing I've seen
> of something that's capable of implementing this is probably the
> co-operative multithreading MP package in cmucl)
> > in Scheme , i'd have to use Call/cc ?
> >
> > https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
> >
> > for n in range(2, 10):
> > for x in range(2, n):
> > if n % x == 0:
> > print(n, 'equals', x, '*', n//x)
> > break
> > else:
> > # loop fell through without finding a factor
> > print(n, 'is a prime number')
> >
> >
> > 2 is a prime number
> > 3 is a prime number
> > 4 equals 2 * 2
> > 5 is a prime number
> > 6 equals 2 * 3
> > 7 is a prime number
> > 8 equals 2 * 4
> > 9 equals 3 * 3
> >

thanks (all) for the great comments !!!

i think.... that These range objects get used right away, so there is no element of [lazy evaluation] or coroutines here.

>>>> The range() is a built-in function that returns a range object that consists (of? a) series of integer numbers, which we can iterate using a for loop.

Re: ( for... break... else ) in Common Lisp and Scheme ?

<acb2c1cd-07de-4c5d-a957-e4178c7a452dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17332&group=comp.lang.lisp#17332

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ac8:1e08:0:b0:3bf:a99f:474e with SMTP id n8-20020ac81e08000000b003bfa99f474emr3589902qtl.0.1678275095868;
Wed, 08 Mar 2023 03:31:35 -0800 (PST)
X-Received: by 2002:a81:af4e:0:b0:521:db3f:9e27 with SMTP id
x14-20020a81af4e000000b00521db3f9e27mr11559458ywj.2.1678275095596; Wed, 08
Mar 2023 03:31:35 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Wed, 8 Mar 2023 03:31:35 -0800 (PST)
In-Reply-To: <be6eff4a-c35e-40e3-96bf-48d3a7635d69n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8001:7500:8a00:293c:2971:c7c6:eb6a;
posting-account=hHHYJQoAAAAhruWGG4mu3XanedOuZgK3
NNTP-Posting-Host: 2603:8001:7500:8a00:293c:2971:c7c6:eb6a
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
<m3pm9m9pri.fsf@leonis4.robolove.meer.net> <be6eff4a-c35e-40e3-96bf-48d3a7635d69n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <acb2c1cd-07de-4c5d-a957-e4178c7a452dn@googlegroups.com>
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
From: Jay_Reynolds_Freeman@mac.com (Jay Freeman)
Injection-Date: Wed, 08 Mar 2023 11:31:35 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4179
 by: Jay Freeman - Wed, 8 Mar 2023 11:31 UTC

In Scheme, a solution using tail-recursion is straightforward:

(define (find-primes-up-through n)
;; We will call an auxiliary that starts at 1 and tail-recurses till it gets to n
(find-primes-up-through-aux n 1))

(define (find-primes-up-through-aux n x)
(if (> x n)
;; If x is greater than n, we are done.
#t
;; Otherwise, test x to see if it is a prime,
;; then increase x by 1 and tail-recurse.
(begin
(is-prime x)
(find-primes-up-through-aux n (+ x 1)))))

(define (is-prime n)
;; We will call an auxiliary that tests to see if 2 divides n, then tail
;; recurses on larger values of the proposed divisor.
(is-prime-aux n 2))

(define (is-prime-aux n x)
(if (> x (sqrt n))
;; If the divisor is bigger than (sqrt x), we are done testing n
;; and it is prime.
(begin (display n) (display " is a prime number") (newline))
;; If not then test to see if x divides n.
(if (= (modulo n x) 0)
;; If so, describe the division and return -- we are done testing n.
(begin
(display n) (display " equals ") (display x) (display " * ") (display (/ n x)) (newline))
;; If not, increase x by 1 and tail-recurse.
(is-prime-aux n (+ x 1)))))

(find-primes-up-through 10)
1 is a prime number
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3
10 equals 2 * 5
#t

Re: ( for... break... else ) in Common Lisp and Scheme ?

<e65b01a7-6247-4fe5-8ca7-c0d651a9440dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17333&group=comp.lang.lisp#17333

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ae9:c116:0:b0:742:4d08:a8bd with SMTP id z22-20020ae9c116000000b007424d08a8bdmr5012805qki.4.1678275504949;
Wed, 08 Mar 2023 03:38:24 -0800 (PST)
X-Received: by 2002:a25:9d06:0:b0:a58:7139:cf85 with SMTP id
i6-20020a259d06000000b00a587139cf85mr10878863ybp.13.1678275504677; Wed, 08
Mar 2023 03:38:24 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Wed, 8 Mar 2023 03:38:24 -0800 (PST)
In-Reply-To: <acb2c1cd-07de-4c5d-a957-e4178c7a452dn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8001:7500:8a00:293c:2971:c7c6:eb6a;
posting-account=hHHYJQoAAAAhruWGG4mu3XanedOuZgK3
NNTP-Posting-Host: 2603:8001:7500:8a00:293c:2971:c7c6:eb6a
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
<m3pm9m9pri.fsf@leonis4.robolove.meer.net> <be6eff4a-c35e-40e3-96bf-48d3a7635d69n@googlegroups.com>
<acb2c1cd-07de-4c5d-a957-e4178c7a452dn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e65b01a7-6247-4fe5-8ca7-c0d651a9440dn@googlegroups.com>
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
From: Jay_Reynolds_Freeman@mac.com (Jay Freeman)
Injection-Date: Wed, 08 Mar 2023 11:38:24 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1461
 by: Jay Freeman - Wed, 8 Mar 2023 11:38 UTC

Oops, make that comment:
;; If the divisor is bigger than (sqrt n), we are done testing n ...

Re: ( for... break... else ) in Common Lisp and Scheme ?

<d7ed0070-c448-4639-ba1e-8d0656d6449an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17334&group=comp.lang.lisp#17334

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a37:a94f:0:b0:741:5749:283c with SMTP id s76-20020a37a94f000000b007415749283cmr4274701qke.10.1678296462090;
Wed, 08 Mar 2023 09:27:42 -0800 (PST)
X-Received: by 2002:a81:b61a:0:b0:52e:c79a:cda with SMTP id
u26-20020a81b61a000000b0052ec79a0cdamr12260541ywh.10.1678296461774; Wed, 08
Mar 2023 09:27:41 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Wed, 8 Mar 2023 09:27:41 -0800 (PST)
In-Reply-To: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:648:8600:1890:cc3a:a73d:fbdb:5f7d;
posting-account=YjTkGAoAAAA4_fbAISfvtIqrYbghMeBx
NNTP-Posting-Host: 2601:648:8600:1890:cc3a:a73d:fbdb:5f7d
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d7ed0070-c448-4639-ba1e-8d0656d6449an@googlegroups.com>
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
From: henhanna@gmail.com (Hen Hanna)
Injection-Date: Wed, 08 Mar 2023 17:27:42 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2820
 by: Hen Hanna - Wed, 8 Mar 2023 17:27 UTC

On Sunday, March 5, 2023 at 9:03:35 PM UTC-8, Hen Hanna wrote:
> in CL (Common Lisp) , i'd use catch/throw ?
>
> in Scheme , i'd have to use Call/cc ?
>
> https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
>
> for n in range(2, 10):
> for x in range(2, n):
> if n % x == 0:
> print(n, 'equals', x, '*', n//x)
> break
> else:
> # loop fell through without finding a factor
> print(n, 'is a prime number')
>
>
> 2 is a prime number
> 3 is a prime number
> 4 equals 2 * 2
> 5 is a prime number
> 6 equals 2 * 3
> 7 is a prime number
> 8 equals 2 * 4
> 9 equals 3 * 3
>
>
> the keyword ELSE doesn't quite sound right.

i think this matching For-Else is kind-of neat and
(pls correct me if i'm mistaken)
the whole point of it is... i can avoid writing a Helping-Function, as ....

def getDivisor( n ):
for x in range(2, n):
if n % x == 0: return(x)
return(False)

for n in range(2, 10):
Div= getDivisor( n )
if Div: print('\t', n, '=', Div, '*', n//Div)
else: print(n, 'is Prime')

______________________
i don't know if i like :=

for n in range(2, 10):
if Div:= getDivisor( n ) : print('\t', n, '=', Div, '*', n//Div)
else: print(n, 'is Prime')

Re: ( for... break... else ) in Common Lisp and Scheme ?

<m3pm8jynvx.fsf@leonis4.robolove.meer.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17339&group=comp.lang.lisp#17339

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: ( for... break... else ) in Common Lisp and Scheme ?
Date: Wed, 05 Apr 2023 09:35:38 +0530
Organization: Motzarella
Lines: 49
Message-ID: <m3pm8jynvx.fsf@leonis4.robolove.meer.net>
References: <d568b860-a810-4506-8807-cc1d4c4ad74an@googlegroups.com>
<m3pm9m9pri.fsf@leonis4.robolove.meer.net>
<86edq1wz9h.fsf@williamsburg.bawden.org>
<m3ilfdaft1.fsf@leonis4.robolove.meer.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="3378baaf3f9b20ba63ee3cd0fef6f1bf";
logging-data="3960324"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fAo47gL8ISutr65euxLiCsayAdGA6SNs="
Cancel-Lock: sha1:o3Xw7c2zatr5CWmdB13eYPQdbtU=
sha1:O7x6wxprROM+YCFLPBnWZOJuJtI=
 by: Madhu - Wed, 5 Apr 2023 04:05 UTC

* Madhu <m3ilfdaft1.fsf @leonis4.robolove.meer.net> :
Wrote on Tue, 07 Mar 2023 00:05:38 +0530:
> * Alan Bawden <86edq1wz9h.fsf @williamsburg.bawden.org> :
> Wrote on Mon, 06 Mar 2023 12:44:26 -0500:
>> No, it really does match the 'for x'. This use of 'else' is a
>> (controversial) feature of Python. The code above is quoted directly
>> from the Python tutorial at the given URL, which nicely explains how
>> it works.
> Thanks for pointing it out. ("My blushes if it were possible]")

I had a chance to revisit this, and suggest to myself that the for-else
feature is another not-really-elegant quirk of the python designers'
minds --- if the idea is to offer control-flow

I want to modify some python code with a for loop:
```
for x in [XXX]:
DO-THINGS
```
to skip DO-THINGS if x was in another set [YYY], i.e. the desired
control flow is

```
for x in [XXX]:
for y in [YYY]:
if x == y:
CONTINUE-OUTER-LOOP
DO-THINGS
```

Python of course doesn't have CONTINUE-OUTER-LOOP. The for-else
construct suggests I can expect python to continue evaluation of the
outer loop when breaking out of the inner loop. However it doesn't cover
that. I have to explicitly do, in the inner loop
```
skip = false
for y in [YYY]:
if x == y:
skip = true
break
else:
pass # else is of no help here
if skip continue # the outer loop
```
and the control flow is as clunky as it can be.

>> It's controversial, not because there is something wrong with the
>> feature itself, but because many people find naming it 'else' to be
>> confusing.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor