Module called too many times?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Module called too many times?

jon_bondy
I have some code where a particular Module "M()" is invoked 4 times, but
only one of those times is actually displayed, because I only put "!" in
front of one of the references; the other 3 should be ignored.  And yet
when I use echo() inside M(), it appears 4 times.  It seems that while I
have only asked for ONE of the invocations to be calculated, in fact all
four are.  One can hope that it is actually calculated only once, and
then pulled from a cache for the other 3 times, but this is not what I
expected.  That is, in the code below, I thought that modules A(), B(),
and C() would be ignored entirely.

Not sure if this is important or just a curiosity.  Not sure whether
there are performance issues lurking there.

Jon


module M() {
     cube(1);
     echo("hello");
}

module A()
     M();

module B()
     M();

module C()
     M();

A();
B();
C();

!M();


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
dpa
Reply | Threaded
Open this post in threaded view
|

Re: Module called too many times?

dpa
they are all there. You should translate them differently then you'll see them all.

Am Di., 9. Feb. 2021 um 16:19 Uhr schrieb jon <[hidden email]>:
I have some code where a particular Module "M()" is invoked 4 times, but
only one of those times is actually displayed, because I only put "!" in
front of one of the references; the other 3 should be ignored.  And yet
when I use echo() inside M(), it appears 4 times.  It seems that while I
have only asked for ONE of the invocations to be calculated, in fact all
four are.  One can hope that it is actually calculated only once, and
then pulled from a cache for the other 3 times, but this is not what I
expected.  That is, in the code below, I thought that modules A(), B(),
and C() would be ignored entirely.

Not sure if this is important or just a curiosity.  Not sure whether
there are performance issues lurking there.

Jon


module M() {
     cube(1);
     echo("hello");
}

module A()
     M();

module B()
     M();

module C()
     M();

A();
B();
C();

!M();


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Module called too many times?

tp3
No, there's only one shown due to the ! (root modifier).

The root modifier only applies to display, not to evaluation,
so all the calls are done to evaluate the full script. That's
intentional at this point.

ciao,
  Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: Module called too many times?

jon_bondy
In reply to this post by dpa
Not true:


module M() {
      cube(1);
      echo("hello");
}

module A()
      M();

module B()
      M();

module C()
      M();

translate([3, 0, 0]) A();
translate([6, 0, 0]) B();
translate([9, 0, 0]) C();

!M();

On 2/9/2021 10:47 AM, dpa wrote:

>
> module M() {
>      cube(1);
>      echo("hello");
> }
>
> module A()
>      M();
>
> module B()
>      M();
>
> module C()
>      M();
>
> A();
> B();
> C();
>
> !M();

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
dpa
Reply | Threaded
Open this post in threaded view
|

Re: Module called too many times?

dpa
In reply to this post by tp3
ah, well.. I have then probably misunderstood the question. That !M() only outputs this one M() was so clear to me that I omitted it and the other 3 are just in the same place.

Am Di., 9. Feb. 2021 um 16:51 Uhr schrieb Torsten Paul <[hidden email]>:
No, there's only one shown due to the ! (root modifier).

The root modifier only applies to display, not to evaluation,
so all the calls are done to evaluate the full script. That's
intentional at this point.

ciao,
  Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org