Groups | Search | Server Info | Login | Register


Groups > comp.lang.scheme > #6519

Re: nesting for loops

From "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups comp.lang.lisp, comp.lang.scheme
Subject Re: nesting for loops
Date 2025-07-18 23:40 +0000
Organization A noiseless patient Spider
Message-ID <105em0t$2b9mj$1@dont-email.me> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


Barry Margolin wrote:

> >b) Using a nested LOOP _may_ be indicative that you didn't use LOOP
> >properly, as you can put almost infinite complexity into a single
> >LOOP.
> 
> I suppose this is possible, but I don't think it's likely.  Nested loops
> are extremely common whenever you're traversing multi-dimensional
> structures, e.g. a 2-d array with
> 
>   (loop for i upto length
>     do
>     (loop for j upto width
>       do
>       (do-something-with (aref a i j))))
> 
> or a list of lists with:
> 
>   (loop for inner in outer
>     do
>     (loop for item in inner
>       do
>       (do-something-with item)))
> 
> LOOP has quite a bit of complexity, but it doesn't actually have any way to
> do either of these easily in a single loop (well, in the first case you
> could do it with ROW-MAJOR-AREF, but that's not really a LOOP feature,
> that's a special array feature).

Gauche Scheme:

(use srfi-42)  ;; list-ec

(list-ec [:list i '(1 10 100)] [:list j '(7 8 9)] (* i j))
 ===>
(7 8 9   70 80 90   700 800 900)

-- 
[T]he problem is that lispniks are as cultish as any other devout group and
basically fall down frothing at the mouth if they see [heterodoxy].
  --- Kenny Tilton
The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham

Back to comp.lang.scheme | Previous | Next | Find similar


Thread

Re: nesting for loops "B. Pym" <Nobody447095@here-nor-there.org> - 2025-07-18 23:40 +0000

csiph-web