< Back to IRCAM Forum

Nested loops

Hi,

I’m trying to create a nested loop with the omloop object.

Below would be the java code for my patch. The goal is to obtain a topological space using a set of interval from 1 to 12.
In that specific case, there is 12^4(20 736) non identical chords created by intervals 1 to 12.
Idealy, I would like to keep the same output format; (1 1 1 1) (1 1 1 2) (1 1 1 3) … (12 12 12 12). Also, since i’m not yet used to common lips it would be appreciated to have your opinions in the form of a patch.

I’m kind of sorry to ask for this info and not be at the same level of the rest of the forum. I’m working on it.
In Canada, this tool(OM) is not well know and there’s a major lack of visibility. Still, this forum and the OM composer’s book helped a lot

public static void main(String[] args) {
for (int a = 1; a < 13; a++ ){
for (int b = 1; b < 13; b++){
for ( int c = 1; c < 13; c++){
for ( int d = 1; d < 13; d++){
System.out.println( “(” + a + " " + b + " " + c + " " + d + “)” );
}
}
}
}
}

Cordialement

Let’s do Lisp first (it will maybe help to understand the patch).

Your function corresponds to

(loop for a from 1 to 12 do
(loop for b from 1 to 12 do
(loop for c from 1 to 12 do
(loop for d from 1 to 12 do
(print (format nil “(~D ~D ~D ~D)” a b c d))
))))

I guess you are more interested in collecting elements in a list rather than printing, so this would convert to

(loop for a from 1 to 12 append
(loop for b from 1 to 12 append
(loop for c from 1 to 12 append
(loop for d from 1 to 12 collect (list a b c d))
)))

We can make 1 and 12 variables :

(defun collect-all-combinations (v1 v2)
(loop for a from v1 to v2 append
(loop for b from v1 to v2 append
(loop for c from v1 to 12 append
(loop for d from v1 to v2 collect (list a b c d))
)))))

=> (collect-all-combinations 1 12)

As a patch, this looks more complicated: you need to use 4 nested OMLoops, iterate from 1 to 12 using a “ForLoop” at every level and passing it as a variable (a, b, c…) to the internal loop (see attached picture).

loops.png