discuss@lists.openscad.org

OpenSCAD general discussion

View all threads

Re: How does concat() actually work ?

JB
Jordan Brown
Sun, May 29, 2022 10:47 PM

To answer the question you asked:  concat() accepts N arrays,
concatenates them, and returns the result.

Nophead gave you the solution to your problem:  list comprehension or
recursion.

But to respond to some of the behaviors that you asked about:

Concat does not assign or reassign anything.  It is a pure function:  it
accepts inputs, and returns an output.

In OpenSCAD, it is not possible to assign a new value to an existing
name.  There are a few cases that look sort of like you're doing that,
but you're not - you're assigning a new value to a new name, and when
that new name goes out of scope the old name and its value will reappear.

x = concat(x, y);

probably does not do what  you want, but that has nothing to do with
concat.  It is that you cannot assign a new value to the existing name. 
This is exactly the same case as:

x = x + 1;

and is a close variation on this:

x = 1;
if (something) {
    x = 2;
}

To answer the question you asked:  concat() accepts N arrays, concatenates them, and returns the result. Nophead gave you the solution to your problem:  list comprehension or recursion. But to respond to some of the behaviors that you asked about: Concat does not assign or reassign anything.  It is a pure function:  it accepts inputs, and returns an output. In OpenSCAD, it is not possible to assign a new value to an existing name.  There are a few cases that look sort of like you're doing that, but you're not - you're assigning a new value to a new name, and when that new name goes out of scope the old name and its value will reappear. x = concat(x, y); probably does not do what  you want, but that has nothing to do with concat.  It is that you cannot assign a new value to the existing name.  This is exactly the same case as: x = x + 1; and is a close variation on this: x = 1; if (something) {     x = 2; }