Hello,
many thanks to all. It is so much like C that I forgot that is only partly like this. But: If there are
no variables you have allways to take a new name to change it or is this only for vectors
coirrect? Only variables with the value 'undef' are to be used on left side?
Thanks again
Manfred
With a named constant you can reassign a new value to the name and the last
value assigned is used for the entire script. You can do that also with a
whole list but you can't change an element in a list, without making a new
one.
On 9 January 2017 at 12:03, Manfred Preussig PreussigM@web.de wrote:
Hello,
many thanks to all. It is so much like C that I forgot that is only partly
like this. But: If there are no variables you have allways to take a new
name to change it or is this only for vectors coirrect? Only variables with
the value 'undef' are to be used on left side?
Thanks again
Manfred
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Because of scope rules, it is no problem to write code like this:
for (i=[0:10])
{
k = i*i;
echo(k);
}
but you can't sum up things easily. So this will not work as expected
k = 1;
for (i=[0:10])
{
k = k+k*k;
echo(k); // ECHO: 2
}
to sum up, you either have to use some algebraic a sum formula ( Gauß
https://de.wikipedia.org/wiki/Gau%C3%9Fsche_Summenformel ), which is
always the best from a numeric point of view, or some - admittedly strange -
recursive function.
k=1;
for (i=[0:10])
{
k = sum(k+i); // k+k*k
echo(k);
}
function sum(k) =
k<=0?0
: k==1?2
:sum(k-1)+ sum(k-1)*sum(k-1);
--
View this message in context: http://forum.openscad.org/Error-in-Code-Don-t-know-what-s-wrong-there-tp19952p19970.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
ManfredP wrote
Only variables with the value 'undef' are to be used on left side?
There is no formal definition of variables in OpenSCAD like in C. Or you may
think a variable is defined the first time it appears on the left of an
assignment. 'undef' is a value that you may use in any expression and the
system returns for invalid expressions (like vector[-1]). Therefore, a
variable with an 'undef' value is a defined variable with a well defined
value.
--
View this message in context: http://forum.openscad.org/Error-in-Code-Don-t-know-what-s-wrong-there-tp19952p19971.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
ManfredP wrote
If there are no variables you have allways to take a new name to change it
or is this only for vectors coirrect? Only variables with the value
'undef' are to be used on left side?
I had a more complex answer, but again others have replied before me.
I may post my complex answer tomorrow, after I re-read it, without the red
wine.
In short, conceptually, yes, only previously undefined (ie new) variables on
the left, should be used in a scope level. And yes, also you can't assign to
an element of a vector, a[1]=0 is not valid.
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.
View this message in context: http://forum.openscad.org/Error-in-Code-Don-t-know-what-s-wrong-there-tp19952p19972.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Hello,
many thanks to all. Now it works. Only the stick to the plate is now allready a problem ... as I
will solve that I can print this part.
greetings
Manfred
Am 9 Jan 2017 um 5:54 hat MichaelAtOz geschrieben:
ManfredP wrote
If there are no variables you have allways to take a new name to
change it or is this only for vectors coirrect? Only variables with
the value 'undef' are to be used on left side?
I had a more complex answer, but again others have replied before me.
I may post my complex answer tomorrow, after I re-read it, without the
red wine. In short, conceptually, yes, only previously undefined (ie
new) variables on the left, should be used in a scope level. And yes,
also you can't assign to an element of a vector, a[1]=0 is not valid.
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! -- View this
message in context:
http://forum.openscad.org/Error-in-Code-Don-t-know-what-s-wrong-there-
tp19952p19972.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