Just tested, that is also still fine.
But why? The same code outside a module gives WARNING: Ignoring unknown
variable 'r'. Why is it different inside a module?
On Wed, 6 Feb 2019 at 05:39, Michael Frey michael.frey@gmx.ch wrote:
On 06.02.19 03:20, Jordan Brown wrote:
Good. I could work with that. My variant is a little different; I don't
include the explicit defaulting to undef:
module test(r, d) {
radius = (r != undef) ? r : d/2;
circle(radius);
}
Just tested, that is also still fine.
If I remember correctly, the Ignoring Unknow Variable Warning for normal
variables also exists/existed in OpenSCAD 2015.
New is, that special variables now also cause the "Ignoring Unknow
Variable":
https://github.com/openscad/openscad/issues/2468
https://github.com/openscad/openscad/pull/2524
Some people relayed on that inconstancy and used undefined special
variables.
That is where is_undef came from:
https://github.com/openscad/openscad/pull/2535
Very specific workaround for a very specific issue, but is_undef can also
be used for other purposes.
Special Variables still have a few inconsistency compared to normal
variables.
Not that anybody cares, but here's some of my source to produce a segment
of a circle https://en.wikipedia.org/wiki/Circular_segment given some
set of its parameters...
Looks interesting and well done.
Given that I am lazy, I usually tend to use a circle and difference, which
always gets messy, as I hand juggle variables.
wit kind regards,
Michael Frey
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On 2/6/2019 1:32 AM, nop head wrote:
Just tested, that is also still fine.
But why? The same code outside a module gives WARNING: Ignoring
unknown variable 'r'. Why is it different inside a module?
My guess: Inside a module (or function) you have the variable
"declared" in the argument list. You can be pretty sure that it's not a
typo. Outside, it's a variable that you've never seen before... is it a
typo?
Yes I suppose the parameter as been named so it exists and it value is
undef as opposed to not existing at all. It is all a bit confusing though,
even for an experienced programmer. The subtle difference between undefined
and defined but not given a value, or assigned and given the value undef. I
have replaced == undef with is_undef() in more places than I needed to.
Before these undef warning were added the language was simpler and easier
to understand, but harder to debug.
On Wed, 6 Feb 2019 at 17:59, Jordan Brown openscad@jordan.maileater.net
wrote:
On 2/6/2019 1:32 AM, nop head wrote:
Just tested, that is also still fine.
But why? The same code outside a module gives WARNING: Ignoring unknown
variable 'r'. Why is it different inside a module?
My guess: Inside a module (or function) you have the variable "declared"
in the argument list. You can be pretty sure that it's not a typo.
Outside, it's a variable that you've never seen before... is it a typo?
undef still is a valid value. A variable is known if it was initialized or
it is a function or module argument in the scope it is used. OpenSCAD
assigns an undef value to a non-initialized variable (so unknown) and a
warning for this is welcome IMO to easy the catch of a typo. What may cause
confusion is to call undefined a variable that was not initialized.
Variables initialized with the value undef should not generate a warning.
It is not clear for me if is_undef() checks its argument value or if its
argument variable was initialized. I think those are different situations
and worth of distinct test functions.
Em qua, 6 de fev de 2019 às 18:47, nop head nop.head@gmail.com escreveu:
Yes I suppose the parameter as been named so it exists and it value is
undef as opposed to not existing at all. It is all a bit confusing though,
even for an experienced programmer. The subtle difference between undefined
and defined but not given a value, or assigned and given the value undef. I
have replaced == undef with is_undef() in more places than I needed to.
Before these undef warning were added the language was simpler and easier
to understand, but harder to debug.
From testing is_undef is true for both cases. I don't think we need to
differentiate between them do we? It is just odd to me one gives a warning
and the other doesn't. I.e. I thought I would always need to use is_undef
and that == undef would always give a warning.
On Wed, 6 Feb 2019 at 20:28, Ronaldo Persiano rcmpersiano@gmail.com wrote:
undef still is a valid value. A variable is known if it was initialized or
it is a function or module argument in the scope it is used. OpenSCAD
assigns an undef value to a non-initialized variable (so unknown) and a
warning for this is welcome IMO to easy the catch of a typo. What may cause
confusion is to call undefined a variable that was not initialized.
Variables initialized with the value undef should not generate a warning.
It is not clear for me if is_undef() checks its argument value or if its
argument variable was initialized. I think those are different situations
and worth of distinct test functions.
Em qua, 6 de fev de 2019 às 18:47, nop head nop.head@gmail.com escreveu:
Yes I suppose the parameter as been named so it exists and it value is
undef as opposed to not existing at all. It is all a bit confusing though,
even for an experienced programmer. The subtle difference between undefined
and defined but not given a value, or assigned and given the value undef. I
have replaced == undef with is_undef() in more places than I needed to.
Before these undef warning were added the language was simpler and easier
to understand, but harder to debug.
From testing is_undef is true for both cases. I don't think we need to
differentiate between them do we? It is just odd to me one gives a warning
and the other doesn't. I.e. I thought I would always need to use is_undef
and that == undef would always give a warning.
As far I understand , is_undef() was created to avoid warnings with
non-initialized special variables. It would be better to define something
like is_init(x) which returns false iff the variable x was not initialized
without issuing any warning. And leave undef in peace.
On 07.02.19 00:16, Ronaldo Persiano wrote:
As far I understand , is_undef() was created to avoid warnings with
non-initialized special variables.
That is correct.
But being consequent, is_undef() also avoids warnings with
non-initialized normal variables.
To be clear: The Ignoring unknown variable is almost 10 years old:
... which makes me wonder why the warning is written as "Ignoring unkown
variable".
It does not really ignore unknown, it just defaults to undef.
The same message for special variables is recent:
It would be better to define something like is_init(x) which returns
false if the variable x was not initialized without issuing any
warning. And leave undef in peace.
Interesting idea.
The reason why I picked is_undef was, that it is straightforward to
implement:
https://github.com/openscad/openscad/pull/2535/files
lookup_variable already has/had a silent flag for many many year.
To implement is_init, one would have to duplicate lookup_variable.
Not as straight forward, but doable. I will think about the implications.
With kind regards,
Michael Frey
How can you create a variable that isn't initialised? Or do you mean a
function parameter?
Then we would have two functions replacing the simple == undef and would
have to negate them for != undef. I don't think this is progress. == and !=
undef should have just been made silent. That has worked fine in the past
as is simple to understand.
With the latest master I found two places where I replaced len() with
is_list() but three places where I needed is_list() && len() so I created
Len() to do that. So my code is longer and slower to do the same thing and
OpenSCAD is bigger. Also the documentation
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#len
for len() says that it returns undef for scalars. It was well defined, so I
don't think it should give a warning when passed a scalar.
On Thu, 7 Feb 2019 at 05:53, Michael Frey michael.frey@gmx.ch wrote:
On 07.02.19 00:16, Ronaldo Persiano wrote:
As far I understand , is_undef() was created to avoid warnings with
non-initialized special variables.
That is correct.
But being consequent, is_undef() also avoids warnings with non-initialized
normal variables.
To be clear: The Ignoring unknown variable is almost 10 years old:
... which makes me wonder why the warning is written as "Ignoring unkown
variable".
It does not really ignore unknown, it just defaults to undef.
The same message for special variables is recent:
https://github.com/openscad/openscad/pull/2524
It would be better to define something like is_init(x) which returns false
if the variable x was not initialized without issuing any warning. And
leave undef in peace.
Interesting idea.
The reason why I picked is_undef was, that it is straightforward to
implement:
https://github.com/openscad/openscad/pull/2535/files
lookup_variable already has/had a silent flag for many many year.
To implement is_init, one would have to duplicate lookup_variable.
Not as straight forward, but doable. I will think about the implications.
With kind regards,
Michael Frey
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org