Sujet : Re: Loops (was Re: do { quit; } else { })
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 15. Apr 2025, 20:55:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250415123300.113@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-04-15, bart <
bc@freeuk.com> wrote:
On 15/04/2025 14:19, Kaz Kylheku wrote:
Common Lisp uses "for" to indicate several kinds of variable
stepping clauses inside the loop syntax, some of which are:
[4]> (loop for x in '(a b c)
for y = 1 then (1+ y)
for z = (* y 10)
with w = (* y 10)
collect (list x y z w))
((A 1 10 10) (B 2 20 10) (C 3 30 10))
>
>
I've looked in the past at CLisp and its loops. My view is that the
number of possibilities it provides is over the job. It's like somebody
was tasked with thinking up as many as possible, and making them all
available.
This is easy to because loop is a macro; you can just write code that
you can distribute as a Lisp source file. Early implementatons of loop
were distributed that way. It's happened that some applications would
"bring their own loop" to work around bugs in a Lisp vendor's.
Inspired by the Lisp loop, I made something like it for Awk
using the GNU C Preprocessor.
This was possible largely in part due to the way the
for ( ... ; ... ; ...) header syntax is. The C-style loop
gives us a target construct into which we can compile everything that we
need from all the multiple clauses.
The manual page for the macro is here:
https://www.kylheku.com/cgit/cppawk/tree/cppawk-iter.1It is part of the cppawk project:
https://www.kylheku.com/cgit/cppawk/about/There are regression/coverage test cases for it here:
https://www.kylheku.com/cgit/cppawk/tree/testcases-iter-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca