discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] Discuss Digest, Vol 65, Issue 2

NH
nop head
Mon, Apr 6, 2020 6:02 PM

I'd actually argue with even that last exception.

That was true until C style for loop were added. With those you can
increment variables and accumulate totals etc. So values do persist from
one loop iteration to the next and are mutable.

On Mon, 6 Apr 2020 at 18:09, Torsten Paul Torsten.Paul@gmx.de wrote:

On 06.04.20 19:02, Jordan Brown wrote:

On 4/5/2020 9:37 PM, Ron Wheeler wrote:

Someone suggested a way to solve my BOM problem with
echo and a script. I am working on that.

Another possibility that I think some have used is to
write a program in another language, that emits OpenSCAD
as an intermediate form.

True, and there are some use cases where it makes a lot
of sense.

I think it would be still nice to have things like BOM
covered without that. I believe the way to go is what
was already mentioned in a previous post: tagging parts
of the design with meta data.

I've collected some ideas in:
https://github.com/openscad/openscad/wiki/Meta-Data-Use-Cases

This kind of annotations is widely adopted in other
languages and is used to also control external/separate
applications or generators.

ciao,
Torsten.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

> I'd actually argue with even that last exception. That was true until C style for loop were added. With those you can increment variables and accumulate totals etc. So values do persist from one loop iteration to the next and are mutable. On Mon, 6 Apr 2020 at 18:09, Torsten Paul <Torsten.Paul@gmx.de> wrote: > On 06.04.20 19:02, Jordan Brown wrote: > > On 4/5/2020 9:37 PM, Ron Wheeler wrote: > >> Someone suggested a way to solve my BOM problem with > >> echo and a script. I am working on that. > > > > Another possibility that I think some have used is to > > write a program in another language, that emits OpenSCAD > > as an intermediate form. > > True, and there are some use cases where it makes a lot > of sense. > > I think it would be still nice to have things like BOM > covered without that. I believe the way to go is what > was already mentioned in a previous post: tagging parts > of the design with meta data. > > I've collected some ideas in: > https://github.com/openscad/openscad/wiki/Meta-Data-Use-Cases > > This kind of annotations is widely adopted in other > languages and is used to also control external/separate > applications or generators. > > ciao, > Torsten. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
RW
Ron Wheeler
Mon, Apr 6, 2020 6:44 PM

I solved my problem after getting the hint to look at the log file and
ECHO as a starting point.

I am using a tool that I have been working on for a number years that
transforms data from form to another.
Mostly used so far for loading data exported from one system into
another. Examples
--  taking exported payroll data and transforming and merging it with
other data to get it into the format with all of the data required to
load employees into a Learning Management System.
-- taking employee and course completion data from one LMS and loading
it into another.

My process for generating a BOM is:

  1. Added an ECHO to each OpenSCAD module that created and added a part
    to the project. The ECHO just says what was added (Part name with
    family) and in some cases a parameter (size) if it matters
  2. Copied and pasted the resulting log into a file. Have to clear the
    log before the run to get rid of previous entries.
                Is there some way to configure OpenSCAD to write the log to
    a new file each run?
  3. Used Linux's grep command to separate the ECHO lines from the rest of
    the log. "grep ECHO <OpenSCAD.log >BOM.csv"
  4. Used Linux's sed command to remove ECHO: to get a file with comma
    separated lines of PartName, Family, Size (optional parameter) "sed -i
    s/ECHO://g BOM.csv"
  5. Used my transformer to read in the file as a CSV file.
  6. Used my transformer's field concatenation function to create a
    specific identifier BOMId of Part Name with the Size separated by a "-".
    Family not useful in my case.
  7. Used my transformer's group and count generator to create a new table
    based on groups using the BOMId with the count of items in each group.
  8. Used my transformer's HTML report generator to make a web page with
    the a table of BOMId and count.
  9. Wrote out the BOM file as a csv in case I want to use it later. Not
    required for now.

Pretty easy in the end.

I think that steps 5 to 7 could be done in a spreadsheet program using a
pivot table but the whole manual process would have to be done after
each OpenSCAD generation run.

My process, except for Step 2, is now a script that I can run in a
single command any time I want an updated report.

Ron

On 2020-04-06 1:16 p.m., William F. Adams via Discuss wrote:

Put me down as another person hoeing this row.

I'd like to see a better option for this sort of thing, but thus far
my best first approximation of this is:

 - model in OpenSCAD using Customizer
 - preserve preset parameters in a JSON file
 - parse JSON file and act on those numbers in a separate programming tool

Wrote up a bit on this in an article in TUGboat:

http://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf

and beginning to work through it in more detail at:

https://willadams.gitbook.io/design-into-3d/3d-project

I'd be glad of any feedback and commentary (or corrections/suggestions)

William


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Ron Wheeler
Artifact Software
438-345-3369
rwheeler@artifact-software.com

I solved my problem after getting the hint to look at the log file and ECHO as a starting point. I am using a tool that I have been working on for a number years that transforms data from form to another. Mostly used so far for loading data exported from one system into another. Examples --  taking exported payroll data and transforming and merging it with other data to get it into the format with all of the data required to load employees into a Learning Management System. -- taking employee and course completion data from one LMS and loading it into another. My process for generating a BOM is: 1) Added an ECHO to each OpenSCAD module that created and added a part to the project. The ECHO just says what was added (Part name with family) and in some cases a parameter (size) if it matters 2) Copied and pasted the resulting log into a file. Have to clear the log before the run to get rid of previous entries.             Is there some way to configure OpenSCAD to write the log to a new file each run? 3) Used Linux's grep command to separate the ECHO lines from the rest of the log. "grep ECHO <OpenSCAD.log >BOM.csv" 4) Used Linux's sed command to remove ECHO: to get a file with comma separated lines of PartName, Family, Size (optional parameter) "sed -i s/ECHO://g BOM.csv" 5) Used my transformer to read in the file as a CSV file. 6) Used my transformer's field concatenation function to create a specific identifier BOMId of Part Name with the Size separated by a "-". Family not useful in my case. 7) Used my transformer's group and count generator to create a new table based on groups using the BOMId with the count of items in each group. 8) Used my transformer's HTML report generator to make a web page with the a table of BOMId and count. 9) Wrote out the BOM file as a csv in case I want to use it later. Not required for now. Pretty easy in the end. I think that steps 5 to 7 could be done in a spreadsheet program using a pivot table but the whole manual process would have to be done after each OpenSCAD generation run. My process, except for Step 2, is now a script that I can run in a single command any time I want an updated report. Ron On 2020-04-06 1:16 p.m., William F. Adams via Discuss wrote: > Put me down as another person hoeing this row. > > I'd like to see a better option for this sort of thing, but thus far > my best first approximation of this is: > >  - model in OpenSCAD using Customizer >  - preserve preset parameters in a JSON file >  - parse JSON file and act on those numbers in a separate programming tool > > Wrote up a bit on this in an article in TUGboat: > > http://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf > > and beginning to work through it in more detail at: > > https://willadams.gitbook.io/design-into-3d/3d-project > > I'd be glad of any feedback and commentary (or corrections/suggestions) > > William > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Ron Wheeler Artifact Software 438-345-3369 rwheeler@artifact-software.com
RW
Ron Wheeler
Mon, Apr 6, 2020 6:54 PM

http://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf is very ambitious. A lot
of good work has been done so far.

Ron

On 2020-04-06 1:16 p.m., William F. Adams via Discuss wrote:

Put me down as another person hoeing this row.

I'd like to see a better option for this sort of thing, but thus far
my best first approximation of this is:

 - model in OpenSCAD using Customizer
 - preserve preset parameters in a JSON file
 - parse JSON file and act on those numbers in a separate programming tool

Wrote up a bit on this in an article in TUGboat:

http://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf

and beginning to work through it in more detail at:

https://willadams.gitbook.io/design-into-3d/3d-project

I'd be glad of any feedback and commentary (or corrections/suggestions)

William


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Ron Wheeler
Artifact Software
438-345-3369
rwheeler@artifact-software.com

http://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf is very ambitious. A lot of good work has been done so far. Ron On 2020-04-06 1:16 p.m., William F. Adams via Discuss wrote: > Put me down as another person hoeing this row. > > I'd like to see a better option for this sort of thing, but thus far > my best first approximation of this is: > >  - model in OpenSCAD using Customizer >  - preserve preset parameters in a JSON file >  - parse JSON file and act on those numbers in a separate programming tool > > Wrote up a bit on this in an article in TUGboat: > > http://tug.org/TUGboat/tb40-2/tb125adams-3d.pdf > > and beginning to work through it in more detail at: > > https://willadams.gitbook.io/design-into-3d/3d-project > > I'd be glad of any feedback and commentary (or corrections/suggestions) > > William > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Ron Wheeler Artifact Software 438-345-3369 rwheeler@artifact-software.com
JB
Jordan Brown
Mon, Apr 6, 2020 10:28 PM

On 4/6/2020 11:44 AM, Ron Wheeler via Discuss wrote:

My process for generating a BOM is:

  1. Added an ECHO to each OpenSCAD module that created and added a part
    to the project. The ECHO just says what was added (Part name with
    family) and in some cases a parameter (size) if it matters
  2. Copied and pasted the resulting log into a file. Have to clear the
    log before the run to get rid of previous entries.
                Is there some way to configure OpenSCAD to write the log
    to a new file each run?

You might want to run OpenSCAD from the command line, which makes it
easier to collect the output into a file.  You can either let the output
go to stderr (sigh), or you can use -o with a file extension of ".echo"
to write it to a file.  I haven't used the ".echo" variant, but I
suspect that it completely avoids rendering so runs fast.

It'll be something like

openscad -o mylogfile.echo myProject.scad
  1. Used Linux's grep command to separate the ECHO lines from the rest
    of the log. "grep ECHO <OpenSCAD.log >BOM.csv"
  2. Used Linux's sed command to remove ECHO: to get a file with comma
    separated lines of PartName, Family, Size (optional parameter) "sed -i
    s/ECHO://g BOM.csv"

Suggest:

sed -n 's/ECHO://p' OpenSCAD.log > BOM.csv
On 4/6/2020 11:44 AM, Ron Wheeler via Discuss wrote: > My process for generating a BOM is: > 1) Added an ECHO to each OpenSCAD module that created and added a part > to the project. The ECHO just says what was added (Part name with > family) and in some cases a parameter (size) if it matters > 2) Copied and pasted the resulting log into a file. Have to clear the > log before the run to get rid of previous entries. >             Is there some way to configure OpenSCAD to write the log > to a new file each run? You might want to run OpenSCAD from the command line, which makes it easier to collect the output into a file.  You can either let the output go to stderr (sigh), or you can use -o with a file extension of ".echo" to write it to a file.  I haven't used the ".echo" variant, but I suspect that it completely avoids rendering so runs fast. It'll be something like openscad -o mylogfile.echo myProject.scad > 3) Used Linux's grep command to separate the ECHO lines from the rest > of the log. "grep ECHO <OpenSCAD.log >BOM.csv" > 4) Used Linux's sed command to remove ECHO: to get a file with comma > separated lines of PartName, Family, Size (optional parameter) "sed -i > s/ECHO://g BOM.csv" Suggest: sed -n 's/ECHO://p' OpenSCAD.log > BOM.csv
RP
Ronaldo Persiano
Mon, Apr 6, 2020 10:44 PM

I'd actually argue with even that last exception.

That was true until C style for loop were added. With those you can
increment variables and accumulate totals etc. So values do persist from
one loop iteration to the next and are mutable.

Would you call  this:

function f(x) = let(x = x+1) x;
echo(f(0)); // ECHO: 1

an example of mutable variable?

I don't see any difference from that and the increments in the C style for
loop. Isn't it just a matter of scope?

> > I'd actually argue with even that last exception. > > That was true until C style for loop were added. With those you can > increment variables and accumulate totals etc. So values do persist from > one loop iteration to the next and are mutable. > Would you call this: function f(x) = let(x = x+1) x; echo(f(0)); // ECHO: 1 an example of mutable variable? I don't see any difference from that and the increments in the C style for loop. Isn't it just a matter of scope?
NH
nop head
Mon, Apr 6, 2020 11:13 PM

Do you get a new set of variables each time round the loop or the same ones
mutated? Might be a philosophical question.

In C you get the same ones mutated, so I assume a C style loop does the
same.

On Mon, 6 Apr 2020 at 23:45, Ronaldo Persiano rcmpersiano@gmail.com wrote:

I'd actually argue with even that last exception.

That was true until C style for loop were added. With those you can
increment variables and accumulate totals etc. So values do persist from
one loop iteration to the next and are mutable.

Would you call  this:

function f(x) = let(x = x+1) x;
echo(f(0)); // ECHO: 1

an example of mutable variable?

I don't see any difference from that and the increments in the C style for
loop. Isn't it just a matter of scope?


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Do you get a new set of variables each time round the loop or the same ones mutated? Might be a philosophical question. In C you get the same ones mutated, so I assume a C style loop does the same. On Mon, 6 Apr 2020 at 23:45, Ronaldo Persiano <rcmpersiano@gmail.com> wrote: > > > I'd actually argue with even that last exception. >> >> That was true until C style for loop were added. With those you can >> increment variables and accumulate totals etc. So values do persist from >> one loop iteration to the next and are mutable. >> > > Would you call this: > > function f(x) = let(x = x+1) x; > echo(f(0)); // ECHO: 1 > > > an example of mutable variable? > > I don't see any difference from that and the increments in the C style for > loop. Isn't it just a matter of scope? > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
A
adrianv
Mon, Apr 6, 2020 11:27 PM

Ronaldo wrote

I'd actually argue with even that last exception.

That was true until C style for loop were added. With those you can
increment variables and accumulate totals etc. So values do persist from
one loop iteration to the next and are mutable.

Would you call  this:

function f(x) = let(x = x+1) x;
echo(f(0)); // ECHO: 1

an example of mutable variable?

I don't see any difference from that and the increments in the C style for
loop. Isn't it just a matter of scope?

I think really none of these are mutable variables.  The example above
looks like a mutable variable, but it's not because OpenSCAD has a different
namespace for arguments than for variables, and the variable namespace is
checked first.  So

function f(x) = let(x=x+1)

is creating a new x(variable) in the variable namespace and assigning it to
the value of x(parameter) + 1.  You'll note that it doesn't work to write

function f(x) = let(x=x+1, x=x*x)

That's because x (variable) is now in existence and cannot be changed.

In C style loops the scoping gives you access to the previous and current
iteration values, with the current value hiding the previous, so if you
write x=x+1 in a C style loop it's really x(current) = x(prev) + 1.  Again,
if you issue two assignments, you get an error, so

example = [for(x=0;
x<10;
x=x+1,
x=x+1)
x];

fails because of the double assignment.  The C style loops do let you
accumulate values (the same as recursion) but they don't really let you have
truly mutable variables.  (They also, in my testing, appear to run slower
than recursion, slower even than non-tail recursion, so use with care.)

--
Sent from: http://forum.openscad.org/

Ronaldo wrote >> > I'd actually argue with even that last exception. >> >> That was true until C style for loop were added. With those you can >> increment variables and accumulate totals etc. So values do persist from >> one loop iteration to the next and are mutable. >> > > Would you call this: > > function f(x) = let(x = x+1) x; > echo(f(0)); // ECHO: 1 > > > an example of mutable variable? > > I don't see any difference from that and the increments in the C style for > loop. Isn't it just a matter of scope? I think really none of these are mutable variables. The example above looks like a mutable variable, but it's not because OpenSCAD has a different namespace for arguments than for variables, and the variable namespace is checked first. So function f(x) = let(x=x+1) is creating a new x(variable) in the variable namespace and assigning it to the value of x(parameter) + 1. You'll note that it doesn't work to write function f(x) = let(x=x+1, x=x*x) That's because x (variable) is now in existence and cannot be changed. In C style loops the scoping gives you access to the previous and current iteration values, with the current value hiding the previous, so if you write x=x+1 in a C style loop it's really x(current) = x(prev) + 1. Again, if you issue two assignments, you get an error, so example = [for(x=0; x<10; x=x+1, x=x+1) x]; fails because of the double assignment. The C style loops do let you accumulate values (the same as recursion) but they don't really let you have truly mutable variables. (They also, in my testing, appear to run slower than recursion, slower even than non-tail recursion, so use with care.) -- Sent from: http://forum.openscad.org/
JB
Jordan Brown
Mon, Apr 6, 2020 11:29 PM

On 4/6/2020 11:02 AM, nop head wrote:

I'd actually argue with even that last exception. 

That was true until C style for loop were added. With those you can
increment variables and accumulate totals etc. So values do persist
from one loop iteration to the next and are mutable.

(Is there a module form of C-for, or there only the list comprehension
form?  I can only find the list comprehension form.)

It's a bit existential, but how can you tell?  It's not like you can use
a C "&" operator to get the address of the variable.

x = [ for (i = 0; i < 10; i = i + 1) i ];

could really be roughly equivalent to

function f(i) = i < 10 ? concat([i], f(i+1)) : [];

where it's clearly creating a new instance of "i" in each recursion.

In the for loop,  "i = i + 1" would mean "(new)i = (old)i + 1".

Note that you cannot set the same variable twice.

x = [ for (i=0; i<10; i=i+1, i=i+1 ) i ];

but that order matters:

x = [ for (i=0, a=0, b=0; i<10; a=i, i=i+1, b=i) [a,i,b] ];

prints:

ECHO: [[0, 0, 0], [0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 9, 9]]

That's actually pretty much the same behavior that you get on entering a
new scope:

i = 1;

module foo() {
    a = i;
    i = i + 1;
    b = i;
    echo(a, i, b);
}

foo();

which prints:

ECHO: 1, 2, 2

What I expect is happening is that "a" gets the value of the only "i"
that's visible, the one from the global scope, then a new foo-scope "i"
gets the value of the global-scope "i" plus one, then "b" gets the value
of the foo-scope "i".

If that model is correct, then the rule is that an assignment always
creates a variable, and that you're not allowed to create a variable if
it already exists in the current block.

In this model, a C-for "for(A; B; C)" unrolls sort of like

{
    A
    if (B) {
        { body }
        C
        if (B) {
            { body }
            C
            ...

Anyhow, C-for makes the variables look more variable than other contexts
do, but I don't think they are real variables even there.

(With of course the caveat that we don't have a good word for these
named-data-items-that-do-not-vary, other than the awkward "named constant".)

BTW, another random interesting tidbit:  formal parameters seem to get
their own scope, distinct from the body:

module foo(x) {
    x = x + 1;
    echo(x);
}

foo(1);

prints 2.

On 4/6/2020 11:02 AM, nop head wrote: > > I'd actually argue with even that last exception.  > > That was true until C style for loop were added. With those you can > increment variables and accumulate totals etc. So values do persist > from one loop iteration to the next and are mutable. > (Is there a module form of C-for, or there only the list comprehension form?  I can only find the list comprehension form.) It's a bit existential, but how can you tell?  It's not like you can use a C "&" operator to get the address of the variable. x = [ for (i = 0; i < 10; i = i + 1) i ]; could really be roughly equivalent to function f(i) = i < 10 ? concat([i], f(i+1)) : []; where it's clearly creating a new instance of "i" in each recursion. In the for loop,  "i = i + 1" would mean "(new)i = (old)i + 1". Note that you cannot set the same variable twice. x = [ for (i=0; i<10; i=i+1, i=i+1 ) i ]; but that order matters: x = [ for (i=0, a=0, b=0; i<10; a=i, i=i+1, b=i) [a,i,b] ]; prints: ECHO: [[0, 0, 0], [0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 9, 9]] That's actually pretty much the same behavior that you get on entering a new scope: i = 1; module foo() { a = i; i = i + 1; b = i; echo(a, i, b); } foo(); which prints: ECHO: 1, 2, 2 What I expect is happening is that "a" gets the value of the only "i" that's visible, the one from the global scope, then a new foo-scope "i" gets the value of the global-scope "i" plus one, then "b" gets the value of the foo-scope "i". If that model is correct, then the rule is that an assignment always creates a variable, and that you're not allowed to create a variable if it already exists in the current block. In this model, a C-for "for(A; B; C)" unrolls sort of like { A if (B) { { body } C if (B) { { body } C ... Anyhow, C-for makes the variables look more variable than other contexts do, but I don't think they are real variables even there. (With of course the caveat that we don't have a good word for these named-data-items-that-do-not-vary, other than the awkward "named constant".) BTW, another random interesting tidbit:  formal parameters seem to get their own scope, distinct from the body: module foo(x) { x = x + 1; echo(x); } foo(1); prints 2.
RW
Ron Wheeler
Tue, Apr 7, 2020 12:32 AM

Thanks.
Ron

On 2020-04-06 6:28 p.m., Jordan Brown wrote:

On 4/6/2020 11:44 AM, Ron Wheeler via Discuss wrote:

My process for generating a BOM is:

  1. Added an ECHO to each OpenSCAD module that created and added a
    part to the project. The ECHO just says what was added (Part name
    with family) and in some cases a parameter (size) if it matters
  2. Copied and pasted the resulting log into a file. Have to clear the
    log before the run to get rid of previous entries.
                Is there some way to configure OpenSCAD to write the log
    to a new file each run?

You might want to run OpenSCAD from the command line, which makes it
easier to collect the output into a file.  You can either let the
output go to stderr (sigh), or you can use -o with a file extension of
".echo" to write it to a file.  I haven't used the ".echo" variant,
but I suspect that it completely avoids rendering so runs fast.

It'll be something like

 openscad -o mylogfile.echo myProject.scad
  1. Used Linux's grep command to separate the ECHO lines from the rest
    of the log. "grep ECHO <OpenSCAD.log >BOM.csv"
  2. Used Linux's sed command to remove ECHO: to get a file with comma
    separated lines of PartName, Family, Size (optional parameter) "sed
    -i s/ECHO://g BOM.csv"

Suggest:

 sed -n 's/ECHO://p' OpenSCAD.log > BOM.csv

--
Ron Wheeler
Artifact Software
438-345-3369
rwheeler@artifact-software.com

Thanks. Ron On 2020-04-06 6:28 p.m., Jordan Brown wrote: > On 4/6/2020 11:44 AM, Ron Wheeler via Discuss wrote: >> My process for generating a BOM is: >> 1) Added an ECHO to each OpenSCAD module that created and added a >> part to the project. The ECHO just says what was added (Part name >> with family) and in some cases a parameter (size) if it matters >> 2) Copied and pasted the resulting log into a file. Have to clear the >> log before the run to get rid of previous entries. >>             Is there some way to configure OpenSCAD to write the log >> to a new file each run? > > You might want to run OpenSCAD from the command line, which makes it > easier to collect the output into a file.  You can either let the > output go to stderr (sigh), or you can use -o with a file extension of > ".echo" to write it to a file.  I haven't used the ".echo" variant, > but I suspect that it completely avoids rendering so runs fast. > > It'll be something like > > openscad -o mylogfile.echo myProject.scad > > >> 3) Used Linux's grep command to separate the ECHO lines from the rest >> of the log. "grep ECHO <OpenSCAD.log >BOM.csv" >> 4) Used Linux's sed command to remove ECHO: to get a file with comma >> separated lines of PartName, Family, Size (optional parameter) "sed >> -i s/ECHO://g BOM.csv" > Suggest: > > sed -n 's/ECHO://p' OpenSCAD.log > BOM.csv > > -- Ron Wheeler Artifact Software 438-345-3369 rwheeler@artifact-software.com
RW
Ron Wheeler
Tue, Apr 7, 2020 1:03 AM

Not yet convinced that a clever developer can not solve the problem of
dynamic variables.
The arguments so far seem to be based on "It has not been already done."
or "It would violate some unstated philosophical belief."

Software is usually very mutable once you decide that something has to
be done.
There may be a range of trade-offs between cost(effort), functionality
and delivery time.

Ron

On 2020-04-06 7:27 p.m., adrianv wrote:

Ronaldo wrote

I'd actually argue with even that last exception.

That was true until C style for loop were added. With those you can
increment variables and accumulate totals etc. So values do persist from
one loop iteration to the next and are mutable.

Would you call  this:

function f(x) = let(x = x+1) x;
echo(f(0)); // ECHO: 1

an example of mutable variable?

I don't see any difference from that and the increments in the C style for
loop. Isn't it just a matter of scope?

I think really none of these are mutable variables.  The example above
looks like a mutable variable, but it's not because OpenSCAD has a different
namespace for arguments than for variables, and the variable namespace is
checked first.  So

function f(x) = let(x=x+1)

is creating a new x(variable) in the variable namespace and assigning it to
the value of x(parameter) + 1.  You'll note that it doesn't work to write

function f(x) = let(x=x+1, x=x*x)

That's because x (variable) is now in existence and cannot be changed.

In C style loops the scoping gives you access to the previous and current
iteration values, with the current value hiding the previous, so if you
write x=x+1 in a C style loop it's really x(current) = x(prev) + 1.  Again,
if you issue two assignments, you get an error, so

example = [for(x=0;
x<10;
x=x+1,
x=x+1)
x];

fails because of the double assignment.  The C style loops do let you
accumulate values (the same as recursion) but they don't really let you have
truly mutable variables.  (They also, in my testing, appear to run slower
than recursion, slower even than non-tail recursion, so use with care.)

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Ron Wheeler
Artifact Software
438-345-3369
rwheeler@artifact-software.com

Not yet convinced that a clever developer can not solve the problem of dynamic variables. The arguments so far seem to be based on "It has not been already done." or "It would violate some unstated philosophical belief." Software is usually very mutable once you decide that something has to be done. There may be a range of trade-offs between cost(effort), functionality and delivery time. Ron On 2020-04-06 7:27 p.m., adrianv wrote: > Ronaldo wrote >>>> I'd actually argue with even that last exception. >>> That was true until C style for loop were added. With those you can >>> increment variables and accumulate totals etc. So values do persist from >>> one loop iteration to the next and are mutable. >>> >> Would you call this: >> >> function f(x) = let(x = x+1) x; >> echo(f(0)); // ECHO: 1 >> >> >> an example of mutable variable? >> >> I don't see any difference from that and the increments in the C style for >> loop. Isn't it just a matter of scope? > I think really none of these are mutable variables. The example above > looks like a mutable variable, but it's not because OpenSCAD has a different > namespace for arguments than for variables, and the variable namespace is > checked first. So > > function f(x) = let(x=x+1) > > is creating a new x(variable) in the variable namespace and assigning it to > the value of x(parameter) + 1. You'll note that it doesn't work to write > > function f(x) = let(x=x+1, x=x*x) > > That's because x (variable) is now in existence and cannot be changed. > > In C style loops the scoping gives you access to the previous and current > iteration values, with the current value hiding the previous, so if you > write x=x+1 in a C style loop it's really x(current) = x(prev) + 1. Again, > if you issue two assignments, you get an error, so > > example = [for(x=0; > x<10; > x=x+1, > x=x+1) > x]; > > fails because of the double assignment. The C style loops do let you > accumulate values (the same as recursion) but they don't really let you have > truly mutable variables. (They also, in my testing, appear to run slower > than recursion, slower even than non-tail recursion, so use with care.) > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Ron Wheeler Artifact Software 438-345-3369 rwheeler@artifact-software.com