discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

What to call "variables"

DB
don bright
Sun, Sep 4, 2016 5:39 PM

I just had a great idea for a name.

Zarfog the Destroyer

Zarfog Destroys all before him, lays waste to the values of previously
declared Zarfogs. None are left in his path.

--
don bright
hmbright@fastmail.com

On Tue, Aug 30, 2016, at 07:09 AM, L Boyd wrote:

I see multiple question from those new to OpenSCAD about what we call
variables. They are confused because they are different from the
variables
used in many programming languages. They don't understand why the can't
do
a=a+1.

They are not really constants either, because they can be overridden
locally
within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to read the
definition for how to use them.

I don't have any suggestions, but we need to discuss this before changing
the manual.


Larry

View this message in context:
http://forum.openscad.org/What-to-call-variables-tp18260.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


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

I just had a great idea for a name. Zarfog the Destroyer Zarfog Destroys all before him, lays waste to the values of previously declared Zarfogs. None are left in his path. -- don bright hmbright@fastmail.com On Tue, Aug 30, 2016, at 07:09 AM, L Boyd wrote: > I see multiple question from those new to OpenSCAD about what we call > variables. They are confused because they are different from the > variables > used in many programming languages. They don't understand why the can't > do > a=a+1. > > They are not really constants either, because they can be overridden > locally > within inner scopes. > > Perhaps we should use an unfamiliar name, so that they have to read the > definition for how to use them. > > I don't have any suggestions, but we need to discuss this before changing > the manual. > > > > ----- > Larry > -- > View this message in context: > http://forum.openscad.org/What-to-call-variables-tp18260.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
RP
Ronaldo Persiano
Sun, Sep 4, 2016 6:27 PM

Great idea, indeed! It distinguish it from
Joker-you-will-never-know-who-I-am, AKA variables.

2016-09-04 14:39 GMT-03:00 don bright hmbright@fastmail.com:

I just had a great idea for a name.

Zarfog the Destroyer

Zarfog Destroys all before him, lays waste to the values of previously
declared Zarfogs. None are left in his path.

--
don bright
hmbright@fastmail.com

On Tue, Aug 30, 2016, at 07:09 AM, L Boyd wrote:

I see multiple question from those new to OpenSCAD about what we call
variables. They are confused because they are different from the
variables
used in many programming languages. They don't understand why the can't
do
a=a+1.

They are not really constants either, because they can be overridden
locally
within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to read the
definition for how to use them.

I don't have any suggestions, but we need to discuss this before changing
the manual.


Larry

View this message in context:
http://forum.openscad.org/What-to-call-variables-tp18260.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


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

Great idea, indeed! It distinguish it from Joker-you-will-never-know-who-I-am, AKA variables. 2016-09-04 14:39 GMT-03:00 don bright <hmbright@fastmail.com>: > I just had a great idea for a name. > > Zarfog the Destroyer > > Zarfog Destroys all before him, lays waste to the values of previously > declared Zarfogs. None are left in his path. > > > -- > don bright > hmbright@fastmail.com > > On Tue, Aug 30, 2016, at 07:09 AM, L Boyd wrote: > > I see multiple question from those new to OpenSCAD about what we call > > variables. They are confused because they are different from the > > variables > > used in many programming languages. They don't understand why the can't > > do > > a=a+1. > > > > They are not really constants either, because they can be overridden > > locally > > within inner scopes. > > > > Perhaps we should use an unfamiliar name, so that they have to read the > > definition for how to use them. > > > > I don't have any suggestions, but we need to discuss this before changing > > the manual. > > > > > > > > ----- > > Larry > > -- > > View this message in context: > > http://forum.openscad.org/What-to-call-variables-tp18260.html > > Sent from the OpenSCAD mailing list archive at Nabble.com. > > > > _______________________________________________ > > OpenSCAD mailing list > > Discuss@lists.openscad.org > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
RW
Rob Ward
Tue, Sep 6, 2016 10:47 AM

It seems to me that "Varonstants" would be a good name. That should
alert the people who are quick to make assumptions about languages from
their own reference points, that is, hey! this is something you've
probably not come across before?

Would I be churlish to suggest that it appears that openSCAD was a 3-D
solids tool that began as a quick way into defining solids, required
nice curves, endpoints and ranges, so adopted the mathematics, but never
quite got the programming side of it right, and that the present way
that varonstants are treated is sort of an oversight because openSCAD is
just a "solids defining tool", and not a strictly and ideal programming
language at all?? In other words the refinement of the programming
aspects of the language has been a compromise from the early days when
to render a shape was cool and the ramifications of the script behind it
was just accepted, warts and all.  After all a statement that says
cube([1,2,3]) that does not resemble a cube is somewhat of a giveaway.

On the other hand... I am really pleased with openSCAD mainly because I
am happy with simple stuff and have no desires to push the boundaries
and happy to live within its present limitations. I have completed many
productive projects through to 3D Printed objects as a result. A
fantastic tool.  I just don't think that people have a right to
seriously admonish the work of so many that have created this tool with
too many high minded criticisms.  I admire the work of people who have
volunteered to contribute to this project, and especially to those who
recognise its origins and strive to move us all onwards.

On 05/09/16 04:27, Ronaldo Persiano wrote:

Great idea, indeed! It distinguish it from
Joker-you-will-never-know-who-I-am, AKA variables.

2016-09-04 14:39 GMT-03:00 don bright <hmbright@fastmail.com
mailto:hmbright@fastmail.com>:

 I just had a great idea for a name.

 Zarfog the Destroyer

 Zarfog Destroys all before him, lays waste to the values of previously
 declared Zarfogs. None are left in his path.


 --
   don bright
 hmbright@fastmail.com <mailto:hmbright@fastmail.com>

 On Tue, Aug 30, 2016, at 07:09 AM, L Boyd wrote:

I see multiple question from those new to OpenSCAD about what we

 call

variables. They are confused because they are different from the
variables
used in many programming languages. They don't understand why

 the can't

do
a=a+1.

They are not really constants either, because they can be overridden
locally
within inner scopes.

Perhaps we should use an unfamiliar name, so that they have to

 read the

definition for how to use them.

I don't have any suggestions, but we need to discuss this before

 changing

the manual.


Larry

View this message in context:
http://forum.openscad.org/What-to-call-variables-tp18260.html

 <http://forum.openscad.org/What-to-call-variables-tp18260.html>

Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org mailto:Discuss@lists.openscad.org

 http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
 <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org>

 _______________________________________________
 OpenSCAD mailing list
 Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org>
 http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
 <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org>

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

--

Rob Ward
Lake Tyers Beach, 3909
Lake Tyers Beach Website http://www.laketyersbeach.net.au
XP to XUbuntu http://www.laketyersbeach.net.au/XP2XU.html

It seems to me that "Varonstants" would be a good name. That should alert the people who are quick to make assumptions about languages from their own reference points, that is, hey! this is something you've probably not come across before? Would I be churlish to suggest that it appears that openSCAD was a 3-D solids tool that began as a quick way into defining solids, required nice curves, endpoints and ranges, so adopted the mathematics, but never quite got the programming side of it right, and that the present way that varonstants are treated is sort of an oversight because openSCAD is just a "solids defining tool", and not a strictly and ideal programming language at all?? In other words the refinement of the programming aspects of the language has been a compromise from the early days when to render a shape was cool and the ramifications of the script behind it was just accepted, warts and all. After all a statement that says cube([1,2,3]) that does not resemble a cube is somewhat of a giveaway. On the other hand... I am really pleased with openSCAD mainly because I am happy with simple stuff and have no desires to push the boundaries and happy to live within its present limitations. I have completed many productive projects through to 3D Printed objects as a result. A fantastic tool. I just don't think that people have a right to seriously admonish the work of so many that have created this tool with too many high minded criticisms. I admire the work of people who have volunteered to contribute to this project, and especially to those who recognise its origins and strive to move us all onwards. On 05/09/16 04:27, Ronaldo Persiano wrote: > Great idea, indeed! It distinguish it from > Joker-you-will-never-know-who-I-am, AKA variables. > > 2016-09-04 14:39 GMT-03:00 don bright <hmbright@fastmail.com > <mailto:hmbright@fastmail.com>>: > > I just had a great idea for a name. > > Zarfog the Destroyer > > Zarfog Destroys all before him, lays waste to the values of previously > declared Zarfogs. None are left in his path. > > > -- > don bright > hmbright@fastmail.com <mailto:hmbright@fastmail.com> > > On Tue, Aug 30, 2016, at 07:09 AM, L Boyd wrote: > > I see multiple question from those new to OpenSCAD about what we > call > > variables. They are confused because they are different from the > > variables > > used in many programming languages. They don't understand why > the can't > > do > > a=a+1. > > > > They are not really constants either, because they can be overridden > > locally > > within inner scopes. > > > > Perhaps we should use an unfamiliar name, so that they have to > read the > > definition for how to use them. > > > > I don't have any suggestions, but we need to discuss this before > changing > > the manual. > > > > > > > > ----- > > Larry > > -- > > View this message in context: > > http://forum.openscad.org/What-to-call-variables-tp18260.html > <http://forum.openscad.org/What-to-call-variables-tp18260.html> > > Sent from the OpenSCAD mailing list archive at Nabble.com. > > > > _______________________________________________ > > OpenSCAD mailing list > > Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org> > > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org> > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- *Rob Ward* Lake Tyers Beach, 3909 Lake Tyers Beach Website <http://www.laketyersbeach.net.au> XP to XUbuntu <http://www.laketyersbeach.net.au/XP2XU.html>
D
dmcnutt
Tue, Sep 6, 2016 9:18 PM

"It seems to me that "Varonstants" would be a good name."

Sure.  Anything but a term that is well defined in the subject of
mathematics.

I have been working with a solid representation of a circular circuit
board that will use traces to conduct current and generate torque at
slower than "normal" electric motors. openSCAD has been very helpful.

I have been creating Gerber files to represent the current carrying
conductors on the circuit board. Because Gerber doesn't support rotation
other than in 90 degree increments I have been using perl as a
programming compiler and it works like a charm once you learn the wide
use of special symbols in its commands.

The math is no joke involving computations that involve cross products
of real three dimension vectors consisting of 3 "variables" that are the
elements of electric and magnetic field vectors in three dimensional space.

What I need are designs for parts that will provide for mounting
bearings on the circuit board that will allow it to spin while holding
it all down to planet earth with other parts that will be needed to hold
everything down but rotateable. If the number of magnets changes I need
to calculate new coordinates for the location of mounting holes.

openSCAD is a bit like perl. They both expect programming lines in ASCII
text but perl does define its variables in the way that allows vector
components to be a "variable" in the mathematical sense. Your code can
change the values at will. perl provides the commands "our" and "my"
that are used to define variables as they are required. The "my" version
defines a variable that is forgotten about after the end of the { } pair
that defines a programming section. I have no trouble using it to make a
subroutine use the letters x, y, and z as vector parts and then use the
same text in another subroutine.

The lady of the house once worked for a data-base oriented company and
was not surprised by the idea that a word was defined it was always the
same and wondered why I had a hard time with openSCAD.  I reminded her
that I first programmed a Control Data 1604 with an assembler before
FORTRAN became the language of choice for a physicist. Fortran was the
earliest treatment of variables and it said anything that doesn't start
with IJKLM or N was a floating point variable. Others are integers
mostly for controlling loops. First use defines a name. If you want data
to be sent to subroutines without passing values in a call you had the
COMMON statement to define variables that would be available anywhere.
COMMON is almost the same as OUR which can also apply to strings of
text.  I don't really like it but perhaps starting with an upper case
letter could define one of your "variable only once" items.

In any case I need to prepare drawings for the parts I will need for a
variety of outside diameters. Hopefully openSCAD will help me to create
parts that will work over a whole array of outside diameters. I just
have to figure where to put them as I change the requirements. That's a
whole bunch of variables that must change.

I have been considering a programming exercise that would create an
openSCAD text file that makes it all work together when it's executed.

But. . .  I REALLY like the ability to reset the view of the finished
project by sliding a mouse around. Perl can't do that. I do wish I could
read the dimension scales after saying I want them on the front.

And one more.  I have used Vectorworks because I have a copy.  It's an
older version that can export to *.dxf but reading that when you have to
have the right year assigned or *.dxf is not well understood by anyone.
Sigh...

And. . . .  I really like the work you're doing. A big THANK YOU !!!

"It seems to me that "Varonstants" would be a good name." Sure. Anything but a term that is well defined in the subject of mathematics. I have been working with a solid representation of a circular circuit board that will use traces to conduct current and generate torque at slower than "normal" electric motors. openSCAD has been very helpful. I have been creating Gerber files to represent the current carrying conductors on the circuit board. Because Gerber doesn't support rotation other than in 90 degree increments I have been using perl as a programming compiler and it works like a charm once you learn the wide use of special symbols in its commands. The math is no joke involving computations that involve cross products of real three dimension vectors consisting of 3 "variables" that are the elements of electric and magnetic field vectors in three dimensional space. What I need are designs for parts that will provide for mounting bearings on the circuit board that will allow it to spin while holding it all down to planet earth with other parts that will be needed to hold everything down but rotateable. If the number of magnets changes I need to calculate new coordinates for the location of mounting holes. openSCAD is a bit like perl. They both expect programming lines in ASCII text but perl does define its variables in the way that allows vector components to be a "variable" in the mathematical sense. Your code can change the values at will. perl provides the commands "our" and "my" that are used to define variables as they are required. The "my" version defines a variable that is forgotten about after the end of the { } pair that defines a programming section. I have no trouble using it to make a subroutine use the letters x, y, and z as vector parts and then use the same text in another subroutine. The lady of the house once worked for a data-base oriented company and was not surprised by the idea that a word was defined it was always the same and wondered why I had a hard time with openSCAD. I reminded her that I first programmed a Control Data 1604 with an assembler before FORTRAN became the language of choice for a physicist. Fortran was the earliest treatment of variables and it said anything that doesn't start with IJKLM or N was a floating point variable. Others are integers mostly for controlling loops. First use defines a name. If you want data to be sent to subroutines without passing values in a call you had the COMMON statement to define variables that would be available anywhere. COMMON is almost the same as OUR which can also apply to strings of text. I don't really like it but perhaps starting with an upper case letter could define one of your "variable only once" items. In any case I need to prepare drawings for the parts I will need for a variety of outside diameters. Hopefully openSCAD will help me to create parts that will work over a whole array of outside diameters. I just have to figure where to put them as I change the requirements. That's a whole bunch of variables that must change. I have been considering a programming exercise that would create an openSCAD text file that makes it all work together when it's executed. But. . . I REALLY like the ability to reset the view of the finished project by sliding a mouse around. Perl can't do that. I do wish I could read the dimension scales after saying I want them on the front. And one more. I have used Vectorworks because I have a copy. It's an older version that can export to *.dxf but reading that when you have to have the right year assigned or *.dxf is not well understood by anyone. Sigh... And. . . . I really like the work you're doing. A big THANK YOU !!!
JL
Jean-Paul Louis
Wed, Sep 7, 2016 1:56 AM

Why not call them what they really are, PARAMETERS?

Just my $0.02,
Jean-Paul
N1JPL

On Sep 6, 2016, at 5:18 PM, dmcnutt dmcnutt@macnauchtan.com wrote:

Why not call them what they really are, PARAMETERS? Just my $0.02, Jean-Paul N1JPL > On Sep 6, 2016, at 5:18 PM, dmcnutt <dmcnutt@macnauchtan.com> wrote: > >
RU
Richard Urwin
Wed, Sep 7, 2016 10:52 AM

I like PARAMETERS, that makes sense.

On Tue, Sep 6, 2016 at 10:18 PM, dmcnutt dmcnutt@macnauchtan.com wrote:

In any case I need to prepare drawings for the parts I will need for a

variety of outside diameters. Hopefully openSCAD will help me to create
parts that will work over a whole array of outside diameters. I just have to
figure where to put them as I change the requirements. That's a whole bunch
of variables that must change.

That's a good example of the difference between variables and constants.
Variables can and do change between calculations, constants don't. But in
mathematics and OpenSCAD variables keep the same value throughout a program.

There is a variety of computer architecture called "Data-Flow". It removes
the bottle-neck caused by only having a single processor by contructing a
program as a flow of data between operations. When a particular operation
has all its inputs available then it is executed. The program can be easily
distibuted between many processors; it's a very interesting technique. It
also shares OpenSCAD's requirement that variables do not change because
loops have to be unwrapped into a single path of data. Each operation on
that path can only be executed once just as in OpenSCAD each created
polyhedron is unique and unchanging. Our experiences with OpenSCAD could
feed into language design in the data-flow field and vice-versa.

It seems to me that one time "a = a + 1" is desired is within loops, and
that is usually because the loop variable is doing something else. I have
recently been using the following construction when iterating over lists in
C++:

for (element = First(), count = 0; element != NULL && count < 1000; element
= Next(element), count++)

Maybe something similar could be provided in OpenSCAD, or maybe there could
be a function that returned the loop index: 0 on the first iteration, 1 on
the second, and so on, even if the loop was over elements of a list.

The other use of "a = a + 1" is to count occurrences of some event. In that
case the intermediate values of the variable are never used; only the final
value is valid when all the events have been counted. Maybe we could have a
"tally" statement that made such a use explicit. I don't think that would
break OpenSCAD.

I have been considering a programming exercise that would create an

openSCAD text file that makes it all work together when it's executed.

I'm considering creating a pre-compiler that mixes OpenSCAD and Python.

Fortran was the earliest treatment of variables and it said anything that
doesn't start with IJKLM or N was a
floating point variable.

GOD is REAL (unless declared INTEGER)

--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18337.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I like PARAMETERS, that makes sense. On Tue, Sep 6, 2016 at 10:18 PM, dmcnutt <dmcnutt@macnauchtan.com> wrote: > In any case I need to prepare drawings for the parts I will need for a variety of outside diameters. Hopefully openSCAD will help me to create parts that will work over a whole array of outside diameters. I just have to figure where to put them as I change the requirements. That's a whole bunch of variables that must change. That's a good example of the difference between variables and constants. Variables can and do change between calculations, constants don't. But in mathematics and OpenSCAD variables keep the same value throughout a program. There is a variety of computer architecture called "Data-Flow". It removes the bottle-neck caused by only having a single processor by contructing a program as a flow of data between operations. When a particular operation has all its inputs available then it is executed. The program can be easily distibuted between many processors; it's a very interesting technique. It also shares OpenSCAD's requirement that variables do not change because loops have to be unwrapped into a single path of data. Each operation on that path can only be executed once just as in OpenSCAD each created polyhedron is unique and unchanging. Our experiences with OpenSCAD could feed into language design in the data-flow field and vice-versa. It seems to me that one time "a = a + 1" is desired is within loops, and that is usually because the loop variable is doing something else. I have recently been using the following construction when iterating over lists in C++: for (element = First(), count = 0; element != NULL && count < 1000; element = Next(element), count++) Maybe something similar could be provided in OpenSCAD, or maybe there could be a function that returned the loop index: 0 on the first iteration, 1 on the second, and so on, even if the loop was over elements of a list. The other use of "a = a + 1" is to count occurrences of some event. In that case the intermediate values of the variable are never used; only the final value is valid when all the events have been counted. Maybe we could have a "tally" statement that made such a use explicit. I don't think that would break OpenSCAD. > I have been considering a programming exercise that would create an > openSCAD text file that makes it all work together when it's executed. I'm considering creating a pre-compiler that mixes OpenSCAD and Python. > Fortran was the earliest treatment of variables and it said anything that > doesn't start with IJKLM or N was a > floating point variable. GOD is REAL (unless declared INTEGER) -- View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18337.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Wed, Sep 7, 2016 11:28 AM

If you want to have both an element and its index you can do this:

for(i = [0 : len(list) - 1]) {
element = list[i];
...
}

To count occurrences you can use a recursive function instead of a for
loop.

function count_events(list, i = 0, tally = 0) = i == len(list) ? tally :
count(list, i + 1, tally + is_event(list[i]) ? 1 : 0);

On 7 September 2016 at 11:52, Richard Urwin <
soronlin+openscad@googlemail.com> wrote:

I like PARAMETERS, that makes sense.

On Tue, Sep 6, 2016 at 10:18 PM, dmcnutt dmcnutt@macnauchtan.com wrote:

In any case I need to prepare drawings for the parts I will need for a

variety of outside diameters. Hopefully openSCAD will help me to create
parts that will work over a whole array of outside diameters. I just have
to
figure where to put them as I change the requirements. That's a whole bunch
of variables that must change.

That's a good example of the difference between variables and constants.
Variables can and do change between calculations, constants don't. But in
mathematics and OpenSCAD variables keep the same value throughout a
program.

There is a variety of computer architecture called "Data-Flow". It removes
the bottle-neck caused by only having a single processor by contructing a
program as a flow of data between operations. When a particular operation
has all its inputs available then it is executed. The program can be easily
distibuted between many processors; it's a very interesting technique. It
also shares OpenSCAD's requirement that variables do not change because
loops have to be unwrapped into a single path of data. Each operation on
that path can only be executed once just as in OpenSCAD each created
polyhedron is unique and unchanging. Our experiences with OpenSCAD could
feed into language design in the data-flow field and vice-versa.

It seems to me that one time "a = a + 1" is desired is within loops, and
that is usually because the loop variable is doing something else. I have
recently been using the following construction when iterating over lists in
C++:

for (element = First(), count = 0; element != NULL && count < 1000; element
= Next(element), count++)

Maybe something similar could be provided in OpenSCAD, or maybe there could
be a function that returned the loop index: 0 on the first iteration, 1 on
the second, and so on, even if the loop was over elements of a list.

The other use of "a = a + 1" is to count occurrences of some event. In that
case the intermediate values of the variable are never used; only the final
value is valid when all the events have been counted. Maybe we could have a
"tally" statement that made such a use explicit. I don't think that would
break OpenSCAD.

I have been considering a programming exercise that would create an

openSCAD text file that makes it all work together when it's executed.

I'm considering creating a pre-compiler that mixes OpenSCAD and Python.

Fortran was the earliest treatment of variables and it said anything that
doesn't start with IJKLM or N was a
floating point variable.

GOD is REAL (unless declared INTEGER)

--
View this message in context: http://forum.openscad.org/
What-to-call-variables-tp18260p18337.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


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

If you want to have both an element and its index you can do this: for(i = [0 : len(list) - 1]) { element = list[i]; ... } To count occurrences you can use a recursive function instead of a for loop. function count_events(list, i = 0, tally = 0) = i == len(list) ? tally : count(list, i + 1, tally + is_event(list[i]) ? 1 : 0); On 7 September 2016 at 11:52, Richard Urwin < soronlin+openscad@googlemail.com> wrote: > I like PARAMETERS, that makes sense. > > On Tue, Sep 6, 2016 at 10:18 PM, dmcnutt <dmcnutt@macnauchtan.com> wrote: > > > In any case I need to prepare drawings for the parts I will need for a > variety of outside diameters. Hopefully openSCAD will help me to create > parts that will work over a whole array of outside diameters. I just have > to > figure where to put them as I change the requirements. That's a whole bunch > of variables that must change. > > > That's a good example of the difference between variables and constants. > Variables can and do change between calculations, constants don't. But in > mathematics and OpenSCAD variables keep the same value throughout a > program. > > There is a variety of computer architecture called "Data-Flow". It removes > the bottle-neck caused by only having a single processor by contructing a > program as a flow of data between operations. When a particular operation > has all its inputs available then it is executed. The program can be easily > distibuted between many processors; it's a very interesting technique. It > also shares OpenSCAD's requirement that variables do not change because > loops have to be unwrapped into a single path of data. Each operation on > that path can only be executed once just as in OpenSCAD each created > polyhedron is unique and unchanging. Our experiences with OpenSCAD could > feed into language design in the data-flow field and vice-versa. > > It seems to me that one time "a = a + 1" is desired is within loops, and > that is usually because the loop variable is doing something else. I have > recently been using the following construction when iterating over lists in > C++: > > for (element = First(), count = 0; element != NULL && count < 1000; element > = Next(element), count++) > > Maybe something similar could be provided in OpenSCAD, or maybe there could > be a function that returned the loop index: 0 on the first iteration, 1 on > the second, and so on, even if the loop was over elements of a list. > > The other use of "a = a + 1" is to count occurrences of some event. In that > case the intermediate values of the variable are never used; only the final > value is valid when all the events have been counted. Maybe we could have a > "tally" statement that made such a use explicit. I don't think that would > break OpenSCAD. > > > > I have been considering a programming exercise that would create an > > openSCAD text file that makes it all work together when it's executed. > > > I'm considering creating a pre-compiler that mixes OpenSCAD and Python. > > > Fortran was the earliest treatment of variables and it said anything that > > doesn't start with IJKLM or N was a > > floating point variable. > > GOD is REAL (unless declared INTEGER) > > > > -- > View this message in context: http://forum.openscad.org/ > What-to-call-variables-tp18260p18337.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
TP
Torsten Paul
Wed, Sep 7, 2016 12:13 PM

Von: "Richard Urwin" soronlin+openscad@googlemail.com

It seems to me that one time "a = a + 1" is desired is within
loops, and that is usually because the loop variable is doing
something else.

That already exists as experimental feature:

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/WIP#for_expression

I'm considering creating a pre-compiler that mixes OpenSCAD
and Python.

Please consider contributing to OpenSCAD directly. Yes, it's
much more difficult to change things that are already used by
lots of people who really don't want their scripts broken by
updates (which unfortunately does happen, most of the time
not intentionally).
On the other hand, it is used by lots of people which does
make things interesting and rewarding :-).

While there are probably a number of use cases where external
programs using OpenSCAD as backend make very much sense, it's
still a bit sad to see all those projects started with huge
enthusiasm die after half a year or so when it gets hard to
continue supporting users.

ciao,
Torsten.

Von: "Richard Urwin" <soronlin+openscad@googlemail.com> > It seems to me that one time "a = a + 1" is desired is within > loops, and that is usually because the loop variable is doing > something else. > That already exists as experimental feature: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/WIP#for_expression > I'm considering creating a pre-compiler that mixes OpenSCAD > and Python. > Please consider contributing to OpenSCAD directly. Yes, it's much more difficult to change things that are already used by lots of people who really don't want their scripts broken by updates (which unfortunately does happen, most of the time not intentionally). On the other hand, it *is used* by lots of people which does make things interesting and rewarding :-). While there are probably a number of use cases where external programs using OpenSCAD as backend make very much sense, it's still a bit sad to see all those projects started with huge enthusiasm die after half a year or so when it gets hard to continue supporting users. ciao, Torsten.
R
Ronaldo
Wed, Sep 7, 2016 1:07 PM

Counting ocurrences of some event was one of the first astonishing task stuck
me in my first steps in OpenSCAD when I found that variables are immutable.
I finally arrived to this non recursive solution:

len( [ for(element=list) if(event_predicate(element)) 1] )

For the problem of finding the first ocurrence of an event, you always can
do:

[ for(element=list) if(event_predicate(element)) element ][0]

Another surprising task was to add up the elements of a list. Now I have a
bunch of solutions to that.
Besides given better name to what is called now variables, it is important
to ilustrate the techniques for common tasks like those in the manual.

--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18340.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Counting ocurrences of some event was one of the first astonishing task stuck me in my first steps in OpenSCAD when I found that variables are immutable. I finally arrived to this non recursive solution: len( [ for(element=list) if(event_predicate(element)) 1] ) For the problem of finding the first ocurrence of an event, you always can do: [ for(element=list) if(event_predicate(element)) element ][0] Another surprising task was to add up the elements of a list. Now I have a bunch of solutions to that. Besides given better name to what is called now variables, it is important to ilustrate the techniques for common tasks like those in the manual. -- View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18340.html Sent from the OpenSCAD mailing list archive at Nabble.com.
RU
Richard Urwin
Wed, Sep 7, 2016 2:00 PM

tp3 wrote

Von: "Richard Urwin" <

soronlin+openscad@

>

I'm considering creating a pre-compiler that mixes OpenSCAD
and Python.

While there are probably a number of use cases where external
programs using OpenSCAD as backend make very much sense, it's
still a bit sad to see all those projects started with huge
enthusiasm die after half a year or so when it gets hard to
continue supporting users.

What I'm thinking about would be a dozen lines or so of code. Basically
search and replace <<...>> with "print """...""" and then execute the
resulting program. There is a bit more stuff around defining the input and
output streams and handling includes, but not much.

I'll need more experience before I'm comfortable suggesting modifications to
OpenSCAD, and plugging an imperative language into it would just make for
confusion. The sorts of things that might be interesting are constructions
like this: http://www2.cmp.uea.ac.uk/~jrwg/Sisal/16.Seq.loops.html

--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18341.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

tp3 wrote > Von: "Richard Urwin" &lt; > soronlin+openscad@ > &gt; > >> I'm considering creating a pre-compiler that mixes OpenSCAD >> and Python. >> > While there are probably a number of use cases where external > programs using OpenSCAD as backend make very much sense, it's > still a bit sad to see all those projects started with huge > enthusiasm die after half a year or so when it gets hard to > continue supporting users. What I'm thinking about would be a dozen lines or so of code. Basically search and replace <<...>> with "print """...""" and then execute the resulting program. There is a bit more stuff around defining the input and output streams and handling includes, but not much. I'll need more experience before I'm comfortable suggesting modifications to OpenSCAD, and plugging an imperative language into it would just make for confusion. The sorts of things that might be interesting are constructions like this: http://www2.cmp.uea.ac.uk/~jrwg/Sisal/16.Seq.loops.html -- View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18341.html Sent from the OpenSCAD mailing list archive at Nabble.com.