Command line $ variables

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

Command line $ variables

nophead
I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

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

Re: Command line $ variables

MichaelAtOz
Administrator

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Command line $ variables

nophead
If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

Setting it on the command line instead overrides it everywhere, not just at file scope.

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

I will try to make a small example.





On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Command line $ variables

nophead
use.scad:
------------
$bom = 0;

use <used.scad>

test();

let($bom = 0)
   test();
   
$bom = 1;

used.scad:
--------------
use <used2.scad>

module test() {
    echo("test:", $bom = $bom);
test2();
}

used2.scad:
----------------
module test2() {
    echo("test2:", $bom=$bom);
}

In the GUI this gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 0

ECHO: "test2:", $bom = 0


From the command line with -D$bom=1 it gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1







On 16 November 2017 at 22:10, nop head <[hidden email]> wrote:
If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

Setting it on the command line instead overrides it everywhere, not just at file scope.

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

I will try to make a small example.





On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Command line $ variables

MichaelAtOzTest2

What version are you using?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 09:28
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

use.scad:

------------

$bom = 0;

 

use <used.scad>

 

test();

 

let($bom = 0)

   test();

   

$bom = 1;

 

used.scad:

--------------

use <used2.scad>

 

module test() {

    echo("test:", $bom = $bom);

          test2();

}

 

used2.scad:

----------------

module test2() {

    echo("test2:", $bom=$bom);

}

 

In the GUI this gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 0

ECHO: "test2:", $bom = 0

 

From the command line with -D$bom=1 it gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

 

 

 

 

 

 

On 16 November 2017 at 22:10, nop head <[hidden email]> wrote:

If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

 

Setting it on the command line instead overrides it everywhere, not just at file scope.

 

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

 

I will try to make a small example.

 

 

 

 

 

On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Command line $ variables

MichaelAtOzTest2
In reply to this post by nophead

On the other hand (see below)

I now recall one of my “doesn’t feel right” issues was with use<>

 

use<> has always had funny scope.

 

I replaced use<> with include<> and cmd line works the same as the GUI.

 

I also added (with use<>)

 

assign($bom=2)

  test();

 

It shows the same inconsistency, ie $bom is echoed as 1 via cmd line, 2 via GUI.

 

So I suspect an issue with use<> scope and how –D is scoped.

 

 

=============I typed the below before the above===================

Looks like let()’s scope hasn’t been entirely nailed down? (edit prob. not)

I can’t think of something that would normally differ GUI v’s cmd line, perhaps there is a #ifdef confounding it?

 

 

As mentioned a few times the scope rules are not well documented and particularly the $variables.

Perhaps someone(?) needs to review the codebase to document the scope ‘as-is’ state in a high level language so it can be looked at.

Every so often I come across something which doesn’t feel right, but without the ‘what it is mean to be’ documented it is hard to know.

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 09:28
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

use.scad:

------------

$bom = 0;

 

use <used.scad>

 

test();

 

let($bom = 0)

   test();

   

$bom = 1;

 

used.scad:

--------------

use <used2.scad>

 

module test() {

    echo("test:", $bom = $bom);

          test2();

}

 

used2.scad:

----------------

module test2() {

    echo("test2:", $bom=$bom);

}

 

In the GUI this gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 0

ECHO: "test2:", $bom = 0

 

From the command line with -D$bom=1 it gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

 

 

 

 

 

 

On 16 November 2017 at 22:10, nop head <[hidden email]> wrote:

If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

 

Setting it on the command line instead overrides it everywhere, not just at file scope.

 

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

 

I will try to make a small example.

 

 

 

 

 

On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Command line $ variables

nophead
I upgraded to the latest Windows snapshot when after I noticed this problem: version 2017.11.12 (git 7cb1e93). Before that I was using a version I compiled myself. In the more distant past I think this worked as expected because I used the technique in Mendel90.

If the -D option just appends code to the  main file don't understand how it makes any difference at all with this test because I already set it at the end of the file.

It behaves as if it puts the command line stuff in a new scope that has super powers.


On 17 November 2017 at 01:33, Michael Marx <[hidden email]> wrote:

On the other hand (see below)

I now recall one of my “doesn’t feel right” issues was with use<>

 

use<> has always had funny scope.

 

I replaced use<> with include<> and cmd line works the same as the GUI.

 

I also added (with use<>)

 

assign($bom=2)

  test();

 

It shows the same inconsistency, ie $bom is echoed as 1 via cmd line, 2 via GUI.

 

So I suspect an issue with use<> scope and how –D is scoped.

 

 

=============I typed the below before the above===================

Looks like let()’s scope hasn’t been entirely nailed down? (edit prob. not)

I can’t think of something that would normally differ GUI v’s cmd line, perhaps there is a #ifdef confounding it?

 

 

As mentioned a few times the scope rules are not well documented and particularly the $variables.

Perhaps someone(?) needs to review the codebase to document the scope ‘as-is’ state in a high level language so it can be looked at.

Every so often I come across something which doesn’t feel right, but without the ‘what it is mean to be’ documented it is hard to know.

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 09:28
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

use.scad:

------------

$bom = 0;

 

use <used.scad>

 

test();

 

let($bom = 0)

   test();

   

$bom = 1;

 

used.scad:

--------------

use <used2.scad>

 

module test() {

    echo("test:", $bom = $bom);

          test2();

}

 

used2.scad:

----------------

module test2() {

    echo("test2:", $bom=$bom);

}

 

In the GUI this gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 0

ECHO: "test2:", $bom = 0

 

From the command line with -D$bom=1 it gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

 

 

 

 

 

 

On 16 November 2017 at 22:10, nop head <[hidden email]> wrote:

If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

 

Setting it on the command line instead overrides it everywhere, not just at file scope.

 

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

 

I will try to make a small example.

 

 

 

 

 

On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

_______________________________________________
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



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

Re: Command line $ variables

nophead
Looking at the source code it does simply concatenate the -D text on the end of the main file: https://github.com/openscad/openscad/blob/master/src/openscad.cc#L402

I am therefore baffled as to how this can go wrong.

On 17 November 2017 at 08:45, nop head <[hidden email]> wrote:
I upgraded to the latest Windows snapshot when after I noticed this problem: version 2017.11.12 (git 7cb1e93). Before that I was using a version I compiled myself. In the more distant past I think this worked as expected because I used the technique in Mendel90.

If the -D option just appends code to the  main file don't understand how it makes any difference at all with this test because I already set it at the end of the file.

It behaves as if it puts the command line stuff in a new scope that has super powers.


On 17 November 2017 at 01:33, Michael Marx <[hidden email]> wrote:

On the other hand (see below)

I now recall one of my “doesn’t feel right” issues was with use<>

 

use<> has always had funny scope.

 

I replaced use<> with include<> and cmd line works the same as the GUI.

 

I also added (with use<>)

 

assign($bom=2)

  test();

 

It shows the same inconsistency, ie $bom is echoed as 1 via cmd line, 2 via GUI.

 

So I suspect an issue with use<> scope and how –D is scoped.

 

 

=============I typed the below before the above===================

Looks like let()’s scope hasn’t been entirely nailed down? (edit prob. not)

I can’t think of something that would normally differ GUI v’s cmd line, perhaps there is a #ifdef confounding it?

 

 

As mentioned a few times the scope rules are not well documented and particularly the $variables.

Perhaps someone(?) needs to review the codebase to document the scope ‘as-is’ state in a high level language so it can be looked at.

Every so often I come across something which doesn’t feel right, but without the ‘what it is mean to be’ documented it is hard to know.

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 09:28
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

use.scad:

------------

$bom = 0;

 

use <used.scad>

 

test();

 

let($bom = 0)

   test();

   

$bom = 1;

 

used.scad:

--------------

use <used2.scad>

 

module test() {

    echo("test:", $bom = $bom);

          test2();

}

 

used2.scad:

----------------

module test2() {

    echo("test2:", $bom=$bom);

}

 

In the GUI this gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 0

ECHO: "test2:", $bom = 0

 

From the command line with -D$bom=1 it gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

 

 

 

 

 

 

On 16 November 2017 at 22:10, nop head <[hidden email]> wrote:

If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

 

Setting it on the command line instead overrides it everywhere, not just at file scope.

 

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

 

I will try to make a small example.

 

 

 

 

 

On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

_______________________________________________
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




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

Re: Command line $ variables

MichaelAtOzTest2

I have recollection of a few Git issues re special variable. So searching…

 

I need to reread this* without the red wine, but I think it is relevant with my rose glasses…

 

* https://github.com/openscad/openscad/issues/1968

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 20:06
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

Looking at the source code it does simply concatenate the -D text on the end of the main file: https://github.com/openscad/openscad/blob/master/src/openscad.cc#L402

 

I am therefore baffled as to how this can go wrong.

 

On 17 November 2017 at 08:45, nop head <[hidden email]> wrote:

I upgraded to the latest Windows snapshot when after I noticed this problem: version 2017.11.12 (git 7cb1e93). Before that I was using a version I compiled myself. In the more distant past I think this worked as expected because I used the technique in Mendel90.

 

If the -D option just appends code to the  main file don't understand how it makes any difference at all with this test because I already set it at the end of the file.

 

It behaves as if it puts the command line stuff in a new scope that has super powers.

 

 

On 17 November 2017 at 01:33, Michael Marx <[hidden email]> wrote:

On the other hand (see below)

I now recall one of my “doesn’t feel right” issues was with use<>

 

use<> has always had funny scope.

 

I replaced use<> with include<> and cmd line works the same as the GUI.

 

I also added (with use<>)

 

assign($bom=2)

  test();

 

It shows the same inconsistency, ie $bom is echoed as 1 via cmd line, 2 via GUI.

 

So I suspect an issue with use<> scope and how –D is scoped.

 

 

=============I typed the below before the above===================

Looks like let()’s scope hasn’t been entirely nailed down? (edit prob. not)

I can’t think of something that would normally differ GUI v’s cmd line, perhaps there is a #ifdef confounding it?

 

 

As mentioned a few times the scope rules are not well documented and particularly the $variables.

Perhaps someone(?) needs to review the codebase to document the scope ‘as-is’ state in a high level language so it can be looked at.

Every so often I come across something which doesn’t feel right, but without the ‘what it is mean to be’ documented it is hard to know.

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 09:28
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

use.scad:

------------

$bom = 0;

 

use <used.scad>

 

test();

 

let($bom = 0)

   test();

   

$bom = 1;

 

used.scad:

--------------

use <used2.scad>

 

module test() {

    echo("test:", $bom = $bom);

          test2();

}

 

used2.scad:

----------------

module test2() {

    echo("test2:", $bom=$bom);

}

 

In the GUI this gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 0

ECHO: "test2:", $bom = 0

 

From the command line with -D$bom=1 it gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

 

 

 

 

 

 

On 16 November 2017 at 22:10, nop head <[hidden email]> wrote:

If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

 

Setting it on the command line instead overrides it everywhere, not just at file scope.

 

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

 

I will try to make a small example.

 

 

 

 

 

On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

_______________________________________________
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

 

 


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

Re: Command line $ variables

nophead
I think this is a different bug. Namely setting a special variable with -D has a different effect to setting the same variable at the end of the main file. Since -D just adds to the end of the main file the effect should be identical.

I have looked at the code and can't explain how this happens.

On 17 November 2017 at 12:40, Michael Marx <[hidden email]> wrote:

I have recollection of a few Git issues re special variable. So searching…

 

I need to reread this* without the red wine, but I think it is relevant with my rose glasses…

 

* https://github.com/openscad/openscad/issues/1968

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 20:06


To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

Looking at the source code it does simply concatenate the -D text on the end of the main file: https://github.com/openscad/openscad/blob/master/src/openscad.cc#L402

 

I am therefore baffled as to how this can go wrong.

 

On 17 November 2017 at 08:45, nop head <[hidden email]> wrote:

I upgraded to the latest Windows snapshot when after I noticed this problem: version 2017.11.12 (git 7cb1e93). Before that I was using a version I compiled myself. In the more distant past I think this worked as expected because I used the technique in Mendel90.

 

If the -D option just appends code to the  main file don't understand how it makes any difference at all with this test because I already set it at the end of the file.

 

It behaves as if it puts the command line stuff in a new scope that has super powers.

 

 

On 17 November 2017 at 01:33, Michael Marx <[hidden email]> wrote:

On the other hand (see below)

I now recall one of my “doesn’t feel right” issues was with use<>

 

use<> has always had funny scope.

 

I replaced use<> with include<> and cmd line works the same as the GUI.

 

I also added (with use<>)

 

assign($bom=2)

  test();

 

It shows the same inconsistency, ie $bom is echoed as 1 via cmd line, 2 via GUI.

 

So I suspect an issue with use<> scope and how –D is scoped.

 

 

=============I typed the below before the above===================

Looks like let()’s scope hasn’t been entirely nailed down? (edit prob. not)

I can’t think of something that would normally differ GUI v’s cmd line, perhaps there is a #ifdef confounding it?

 

 

As mentioned a few times the scope rules are not well documented and particularly the $variables.

Perhaps someone(?) needs to review the codebase to document the scope ‘as-is’ state in a high level language so it can be looked at.

Every so often I come across something which doesn’t feel right, but without the ‘what it is mean to be’ documented it is hard to know.

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 09:28
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Command line $ variables

 

use.scad:

------------

$bom = 0;

 

use <used.scad>

 

test();

 

let($bom = 0)

   test();

   

$bom = 1;

 

used.scad:

--------------

use <used2.scad>

 

module test() {

    echo("test:", $bom = $bom);

          test2();

}

 

used2.scad:

----------------

module test2() {

    echo("test2:", $bom=$bom);

}

 

In the GUI this gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 0

ECHO: "test2:", $bom = 0

 

From the command line with -D$bom=1 it gives:

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

ECHO: "test:", $bom = 1

ECHO: "test2:", $bom = 1

 

 

 

 

 

 

On 16 November 2017 at 22:10, nop head <[hidden email]> wrote:

If I add a definition at the end of my main file it works as expected in the GUI. It sets the variable at file scope but it can be overridden at module scope and that is passed down the tree to other modules that can be in other files.

 

Setting it on the command line instead overrides it everywhere, not just at file scope.

 

Module scope should always trump file scope and I think it worked in the past but it doesn't work with recent versions.

 

I will try to make a small example.

 

 

 

 

 

On 16 November 2017 at 21:28, OzAtMichael <[hidden email]> wrote:

> so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

You’ll need to show an example of where in the scope levels this is happening. ie what is ‘adding the vitamins’ & where is the $bom=0 override?

As you know, the –D variables are just added to the tail of the source, what happens if you do it likewise in the GUI?

 


From: Discuss [mailto:[hidden email]] On Behalf Of nop head
Sent: Fri, 17 Nov 2017 01:40
To: OpenSCAD general discussion
Subject: [OpenSCAD] Command line $ variables

 

I use a dynamic variable to turn on and off BOM generation, which is just echo statements.

 

When I use the GUI $bom = 0 so I don't have screen clutter. When I generated a bom I set $bom on the command line and capture the echos. All works fine.

 

Occasionally I have vitamins like nuts and washers that come as part of something else, for example a toggle switch. In that case I don't want the parts that come with it on the bom so I override $bom to 0 before adding the vitamins. This works from the GUI but doesn't seem to work on the command line. The command line override seems to beat the dynamic scope override. Is this a bug? 

 

_______________________________________________
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

 

 


_______________________________________________
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