discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Cheat Sheet and generating lists

JB
Jon Bondy
Tue, Jul 29, 2025 7:39 PM

The Cheat Sheet seems to have some problems at the moment.  Click on the
List link and you end up at Program Structures

I want to generate a list like this (I only show the first 2 triplets here):

[

[a, 0, 0],

[b, 0, 0],

[c, 0, 0],

[a+1, 0, 0],

[b+1, 0, 0],

[c+1, 0, 0]

];

I tried something like this (which is ridiculously wrong)

posns =

    for (x = [1:4]) (
        [a + x-1, 0, 0],
        [b + x-1, 0, 0],
        [c + x-1, 0, 0]);

I do not want a list of list triplets, but rather a long one level list.

Without the Cheat Sheet to guide me, I am lost.

I welcome recommendations

Thanks

Jon

--
This email has been checked for viruses by AVG antivirus software.
www.avg.com

The Cheat Sheet seems to have some problems at the moment.  Click on the List link and you end up at Program Structures I want to generate a list like this (I only show the first 2 triplets here): [ [a, 0, 0], [b, 0, 0], [c, 0, 0], [a+1, 0, 0], [b+1, 0, 0], [c+1, 0, 0] ]; I tried something like this (which is ridiculously wrong) posns =     for (x = [1:4]) (         [a + x-1, 0, 0],         [b + x-1, 0, 0],         [c + x-1, 0, 0]); I do not want a list of list triplets, but rather a long one level list. Without the Cheat Sheet to guide me, I am lost. I welcome recommendations Thanks Jon -- This email has been checked for viruses by AVG antivirus software. www.avg.com
JB
Jordan Brown
Tue, Jul 29, 2025 7:59 PM

On 7/29/2025 12:39 PM, Jon Bondy via Discuss wrote:

The Cheat Sheet seems to have some problems at the moment.  Click on
the List link and you end up at Program Structures

Yeah, somebody is working on a pretty major overhaul of the manual and a
lot of things are broken at the moment.

I do not want a list of list triplets, but rather a long one level list.

Each of which is a triplet, right?

That is, you want a list of triplets, not a list of triplets, each of
which is a triplet.

I suspect that you want the "each" list comprehension operator, which
busts apart lists.

Does this do what you want?

a = 100;
b = 200;
c = 300;

posns = [
for (x = [1:4]) each [
[a + x-1, 0, 0],
[b + x-1, 0, 0],
[c + x-1, 0, 0]
]
];

echo(posns);

yields (reformatted for readability):

ECHO: [ [100, 0, 0], [200, 0, 0], [300, 0, 0], [101, 0, 0], [201, 0, 0],
[301, 0, 0], [102, 0, 0], [202, 0, 0], [302, 0, 0], [103, 0, 0], [203,
0, 0], [303, 0, 0] ]

On 7/29/2025 12:39 PM, Jon Bondy via Discuss wrote: > The Cheat Sheet seems to have some problems at the moment.  Click on > the List link and you end up at Program Structures Yeah, somebody is working on a pretty major overhaul of the manual and a lot of things are broken at the moment. > I do not want a list of list triplets, but rather a long one level list. Each of which is a triplet, right? That is, you want a list of triplets, not a list of triplets, each of which is a triplet. I suspect that you want the "each" list comprehension operator, which busts apart lists. Does this do what you want? a = 100; b = 200; c = 300; posns = [ for (x = [1:4]) each [ [a + x-1, 0, 0], [b + x-1, 0, 0], [c + x-1, 0, 0] ] ]; echo(posns); yields (reformatted for readability): ECHO: [ [100, 0, 0], [200, 0, 0], [300, 0, 0], [101, 0, 0], [201, 0, 0], [301, 0, 0], [102, 0, 0], [202, 0, 0], [302, 0, 0], [103, 0, 0], [203, 0, 0], [303, 0, 0] ]
JJ
jon jonbondy.com
Wed, Jul 30, 2025 1:44 AM

Perfect!  Thank you!

On 7/29/2025 3:59 PM, Jordan Brown wrote:
On 7/29/2025 12:39 PM, Jon Bondy via Discuss wrote:
The Cheat Sheet seems to have some problems at the moment.  Click on the List link and you end up at Program Structures

Yeah, somebody is working on a pretty major overhaul of the manual and a lot of things are broken at the moment.

I do not want a list of list triplets, but rather a long one level list.

Each of which is a triplet, right?

That is, you want a list of triplets, not a list of triplets, each of which is a triplet.

I suspect that you want the "each" list comprehension operator, which busts apart lists.

Does this do what you want?

a = 100;
b = 200;
c = 300;

posns = [
for (x = [1:4]) each [
[a + x-1, 0, 0],
[b + x-1, 0, 0],
[c + x-1, 0, 0]
]
];

echo(posns);

yields (reformatted for readability):

ECHO: [
[100, 0, 0],
[200, 0, 0],
[300, 0, 0],
[101, 0, 0],
[201, 0, 0],
[301, 0, 0],
[102, 0, 0],
[202, 0, 0],
[302, 0, 0],
[103, 0, 0],
[203, 0, 0],
[303, 0, 0]
]

Perfect! Thank you! On 7/29/2025 3:59 PM, Jordan Brown wrote: On 7/29/2025 12:39 PM, Jon Bondy via Discuss wrote: The Cheat Sheet seems to have some problems at the moment. Click on the List link and you end up at Program Structures Yeah, somebody is working on a pretty major overhaul of the manual and a lot of things are broken at the moment. I do not want a list of list triplets, but rather a long one level list. Each of which is a triplet, right? That is, you want a list of triplets, not a list of triplets, each of which is a triplet. I suspect that you want the "each" list comprehension operator, which busts apart lists. Does this do what you want? a = 100; b = 200; c = 300; posns = [ for (x = [1:4]) each [ [a + x-1, 0, 0], [b + x-1, 0, 0], [c + x-1, 0, 0] ] ]; echo(posns); yields (reformatted for readability): ECHO: [ [100, 0, 0], [200, 0, 0], [300, 0, 0], [101, 0, 0], [201, 0, 0], [301, 0, 0], [102, 0, 0], [202, 0, 0], [302, 0, 0], [103, 0, 0], [203, 0, 0], [303, 0, 0] ]
V
vulcan_@mac.com
Wed, Jul 30, 2025 4:53 PM

i will take a look at the cheat sheet now .. my work on it is in my own branch tho and i have not merged back nor done a PR

i will take a look at the cheat sheet now .. my work on it is in my own branch tho and i have not merged back nor done a PR