center = true

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

center = true

lar3ry
Would there be any downside to making the 'center' keyword default to 'true'?
This would make it so that

cube(10,center=true);
and
cube(10,center);

produce the same result.

I don't think it would break any existing code.

I can't think of any other instances of boolean keywords that also might
benefit from this, but if there are...





--
Sent from: http://forum.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: center = true

jon_bondy
Since it currently defaults to false, I guess it would break a lot of
code...


On 12/25/2020 11:41 AM, lar3ry wrote:

> Would there be any downside to making the 'center' keyword default to 'true'?
> This would make it so that
>
> cube(10,center=true);
> and
> cube(10,center);
>
> produce the same result.
>
> I don't think it would break any existing code.
>
> I can't think of any other instances of boolean keywords that also might
> benefit from this, but if there are...
>

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

Re: center = true

adrianv
I think that lar3ry's idea wasn't clearly articulated.  He wants to be able
to omit the "=true" in the invocation and write

cube(10,center);

instead of

cube(10,center=true);

In other words, the idea is that just giving a keyword is equivalent to
setting the keyword to true.  The code that would break is code that looked
like

center=false;
cube(10,center);

I suppose lar3ry could get the behavior he wants (at least sort of) by
defining center=true at the top of his code.  



jon_bondy wrote

> Since it currently defaults to false, I guess it would break a lot of
> code...
>
>
> On 12/25/2020 11:41 AM, lar3ry wrote:
>> Would there be any downside to making the 'center' keyword default to
>> 'true'?
>> This would make it so that
>>
>> cube(10,center=true);
>> and
>> cube(10,center);
>>
>> produce the same result.
>>
>> I don't think it would break any existing code.
>>
>> I can't think of any other instances of boolean keywords that also might
>> benefit from this, but if there are...
>>
>
> _______________________________________________
> OpenSCAD mailing list

> Discuss@.openscad

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





--
Sent from: http://forum.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: center = true

lar3ry
In reply to this post by jon_bondy
How so? You can't use the default by using just the keyword without
specifying 'false'

Oh, I guess the parameter, if not used at all in a statement, is actually
used, and the default is false.
That sort of thing gets us into trouble with other parameters, as in:

cylinder(10,10);

where it seems that a parameter (r2) is assumed, and the default is 1.


jon_bondy wrote

> Since it currently defaults to false, I guess it would break a lot of
> code...
>
> On 12/25/2020 11:41 AM, lar3ry wrote:
>> Would there be any downside to making the 'center' keyword default to
>> 'true'?
>> This would make it so that
>>
>> cube(10,center=true);
>> and
>> cube(10,center);
>>
>> produce the same result.
>>
>> I don't think it would break any existing code.





--
Sent from: http://forum.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: center = true

lar3ry
In reply to this post by adrianv
adrianv wrote

> In other words, the idea is that just giving a keyword is equivalent to
> setting the keyword to true.  The code that would break is code that
> looked
> like
>
> center=false;
> cube(10,center);
>
> I suppose lar3ry could get the behavior he wants (at least sort of) by
> defining center=true at the top of his code.  

center=false;
cube(10,center);

doesn't do it. If it did, I would be somewhat happy with it.






--
Sent from: http://forum.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: center = true

jon_bondy
In reply to this post by adrianv
I like the idea that you could say cube(10, center) but I'm not sure the
parser will handle it properly.  I am sure that those with more
knowledge of these things will chime in soon.

On 12/25/2020 12:01 PM, adrianv wrote:

> I think that lar3ry's idea wasn't clearly articulated.  He wants to be able
> to omit the "=true" in the invocation and write
>
> cube(10,center);
>
> instead of
>
> cube(10,center=true);
>
>

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

Re: center = true

adrianv
The point is that lar3y is requesting a change to the OpenSCAD language,
namely that you can pass the center argument without giving it a value and
when you do that, it's equivalent to giving it a true value, so that

cube(10,center=true);

can be simplified to

cube(10,center);

The reason this is problematic is that the second thing already has a
different meaning, namely that you pass the local variable "center" as the
second positional arg.  


jon_bondy wrote

> I like the idea that you could say cube(10, center) but I'm not sure the
> parser will handle it properly.  I am sure that those with more
> knowledge of these things will chime in soon.
>
> On 12/25/2020 12:01 PM, adrianv wrote:
>> I think that lar3ry's idea wasn't clearly articulated.  He wants to be
>> able
>> to omit the "=true" in the invocation and write
>>
>> cube(10,center);
>>
>> instead of
>>
>> cube(10,center=true);
>>
>>
>
> _______________________________________________
> OpenSCAD mailing list

> Discuss@.openscad

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





--
Sent from: http://forum.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: center = true

adrianv
In reply to this post by lar3ry
I said, "by defining center=true" which you didn't do.  You copied my example
with center=false which I specifically constructed to break your idea.  

I am not sure if you fully understand how parameter passing works.  There
are positional parameters and keyword parameters.  So if you invoke some
function foo(parm1,parm2,keyword=value) then it invokes the function/module
foo and passes it a couple positional parameters and then also passes it a
keyword parameter.   The keyword parameter might be the 5th positional
parameter---we don't know.  By using the keyword passing method you avoid
the need to specify the other parameters and you can allow them to have
default values.  

If you consider changing this to

foo(parm1,parm2,keyword)

it now looks like you're invoking foo with 3 positional parameters.   And in
fact, that is precisely how it is interpreted.  And the thing that was the
keyword is now regarded as a local variable.  

You could make this work for you by defining a variable center equal to true
(not false as in my example below) and then you can pass it as a positional
parameter---in the right place.  So  

center=true;
cube(10,center);
cylinder(100,5,5,center);

but if you don't put things in the right place you're going to get
unexpected results.  So doing

cylinder(100,5,center);

means you've passed "true" as the second radius.  Apparently this (bogus)
value is ignored and the default of 1 is taken in this case.  

Allow me also to draw attention to the following to complete the story:

center=false;
cube(10,center=center);

In this case the statement center=center is kind of confusing because the
"center" on the left is the keyword name and the "center" on the right is a
local variable (which we have set to false in this example).  



lar3ry wrote

> adrianv wrote
>> In other words, the idea is that just giving a keyword is equivalent to
>> setting the keyword to true.  The code that would break is code that
>> looked
>> like
>>
>> center=false;
>> cube(10,center);
>>
>> I suppose lar3ry could get the behavior he wants (at least sort of) by
>> defining center=true at the top of his code.  
>
> center=false;
> cube(10,center);
>
> doesn't do it. If it did, I would be somewhat happy with it.
>
>
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list

> Discuss@.openscad

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





--
Sent from: http://forum.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: center = true

lar3ry
Point taken. I forgot that r2 was also a positional argument.


adrianv wrote

> I said, "by defining center=true" which you didn't do.  You copied my
> example
> with center=false which I specifically constructed to break your idea.  
>
> I am not sure if you fully understand how parameter passing works.  There
> are positional parameters and keyword parameters.  So if you invoke some
> function foo(parm1,parm2,keyword=value) then it invokes the
> function/module
> foo and passes it a couple positional parameters and then also passes it a
> keyword parameter.   The keyword parameter might be the 5th positional
> parameter---we don't know.  By using the keyword passing method you avoid
> the need to specify the other parameters and you can allow them to have
> default values.  
>
> If you consider changing this to
>
> foo(parm1,parm2,keyword)
>
> it now looks like you're invoking foo with 3 positional parameters.   And
> in
> fact, that is precisely how it is interpreted.  And the thing that was the
> keyword is now regarded as a local variable.  
>
> You could make this work for you by defining a variable center equal to
> true
> (not false as in my example below) and then you can pass it as a
> positional
> parameter---in the right place.  So  
>
> center=true;
> cube(10,center);
> cylinder(100,5,5,center);
>
> but if you don't put things in the right place you're going to get
> unexpected results.  So doing
>
> cylinder(100,5,center);
>
> means you've passed "true" as the second radius.  Apparently this (bogus)
> value is ignored and the default of 1 is taken in this case.  
>
> Allow me also to draw attention to the following to complete the story:
>
> center=false;
> cube(10,center=center);
>
> In this case the statement center=center is kind of confusing because the
> "center" on the left is the keyword name and the "center" on the right is
> a
> local variable (which we have set to false in this example).  
>
>
>
> lar3ry wrote
>> adrianv wrote
>>> In other words, the idea is that just giving a keyword is equivalent to
>>> setting the keyword to true.  The code that would break is code that
>>> looked
>>> like
>>>
>>> center=false;
>>> cube(10,center);
>>>
>>> I suppose lar3ry could get the behavior he wants (at least sort of) by
>>> defining center=true at the top of his code.  
>>
>> center=false;
>> cube(10,center);
>>
>> doesn't do it. If it did, I would be somewhat happy with it.
>>
>>
>>
>>
>>
>>
>> --
>> Sent from: http://forum.openscad.org/
>>
>> _______________________________________________
>> OpenSCAD mailing list
>
>> Discuss@.openscad
>
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list

> Discuss@.openscad

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





--
Sent from: http://forum.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: center = true

mondo
In reply to this post by adrianv
I'm not sure of the benefit, unless for readability. if that is the
case, then could set 'centered=true',  and 'offset=false', or come to
UK, and use 'centre'...

It seems to be, that the default 'center', uses the last value set.

Best Wishers,

Ray

On 25/12/2020 17:40, adrianv wrote:

> The point is that lar3y is requesting a change to the OpenSCAD language,
> namely that you can pass the center argument without giving it a value and
> when you do that, it's equivalent to giving it a true value, so that
>
> cube(10,center=true);
>
> can be simplified to
>
> cube(10,center);
>
> The reason this is problematic is that the second thing already has a
> different meaning, namely that you pass the local variable "center" as the
> second positional arg.
>
>
> jon_bondy wrote
>> I like the idea that you could say cube(10, center) but I'm not sure the
>> parser will handle it properly.  I am sure that those with more
>> knowledge of these things will chime in soon.
>>
>> On 12/25/2020 12:01 PM, adrianv wrote:
>>> I think that lar3ry's idea wasn't clearly articulated.  He wants to be
>>> able
>>> to omit the "=true" in the invocation and write
>>>
>>> cube(10,center);
>>>
>>> instead of
>>>
>>> cube(10,center=true);
>>>
>>>
>> _______________________________________________
>> OpenSCAD mailing list
>> Discuss@.openscad
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
>
>
> --
> Sent from: http://forum.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: center = true

Troberg
In reply to this post by lar3ry
It would break my code, as I sometimes use the word "center" as variable name
or module name.



--
Sent from: http://forum.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: center = true

lar3ry
Troberg wrote
> It would break my code, as I sometimes use the word "center" as variable
> name
> or module name.

Hmmm... if you set a variable named center to anything but true, it defaults
to false.
And it doesn't seem to cause a problem with a module named center.

translate([20,20,20])
        center();

module center(){
        sphere(10);
}
       
center = true;
 cube(10,center);




--
Sent from: http://forum.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: center = true

Troberg
lar3ry wrote
> Troberg wrote
>> It would break my code, as I sometimes use the word "center" as variable
>> name
>> or module name.
>
> Hmmm... if you set a variable named center to anything but true, it
> defaults
> to false.

Still, it's not a nice way of doing it. At the very least, prefix such
pre-defined constants, for example scadcenter, which will both reduce the
risk of namespace clashes and clearly show what's a predefined constant.



--
Sent from: http://forum.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: center = true

adrianv
In reply to this post by lar3ry
lar3ry wrote

> Troberg wrote
>> It would break my code, as I sometimes use the word "center" as variable
>> name
>> or module name.
>
> Hmmm... if you set a variable named center to anything but true, it
> defaults
> to false.
> And it doesn't seem to cause a problem with a module named center.
>
> center = true;
>  cube(10,center);

I'd say that's a confusing way to put it.  (I couldn't quite figure out what
you meant.)

A default is something that happens when data is missing, but if you pass a
value to center then there is no missing data, so the default doesn't have
obvious relevance.  However, it seems that the behavior of the cube module
is that if center=true then you get a centered cube.  And if center is
anything else, you get an uncentered cube.  This is arguably a bug.  One
would expect that anything which tested as true should cause the cube to be
centered.  (That is, [3,4] is true in a boolean context, but acts like false
when given as the center argument to cube().)   Or perhaps you should get an
error message if a non-boolean value is passed to center.  

But I think Troberg's point is that he likes to use "center" as a variable,
which conflicts with this approach, and conflicts with your original idea of
being able to write "center" instead of "center=true" when specifying a
centered cube.  

It might for example be natural to define the center of some component, so

center=[3,4,5];

This will conflict with "center=true" and will cause cubes that were
supposed to be centered come out not centered if you've got invocations of
cube(size,center) with the intention that this produce a centered cube.  

If I saw some code that had stuff like

cube(size,center);

in it then I'd wonder what the value of center was.  It doesn't read as
"centered cube" to me.   And the goal is just to avoid typing "=true"?  I
suggest that if you're so offended by the need to type "center=true" and you
have a lot of centered cubes, the answer is to make a centered cube module:

module center_cube(size) { cube(size,center=true);}

You can make similar pass-through modules for other things you want to have
centered.   You can give it a shorter (more cryptic) name if you're really
frustrated by all the typing.   I suppose also if the goal is brevity you
can do "cube(1,true)".




--
Sent from: http://forum.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: center = true

lar3ry
This post was updated on .
adrianv wrote
> lar3ry wrote
>> Troberg wrote
>>> It would break my code, as I sometimes use the word "center" as variable
>>> name
>>> or module name.
>>
>> Hmmm... if you set a variable named center to anything but true, it
>> defaults
>> to false.
>> And it doesn't seem to cause a problem with a module named center.
>>
>> center = true;
>>  cube(10,center);
>
> I'd say that's a confusing way to put it.  (I couldn't quite figure out
> what
> you meant.)
>
> A default is something that happens when data is missing, but if you pass
> a
> value to center then there is no missing data, so the default doesn't have
> obvious relevance.  However, it seems that the behavior of the cube module
> is that if center=true then you get a centered cube.  And if center is
> anything else, you get an uncentered cube.  This is arguably a bug.  One
> would expect that anything which tested as true should cause the cube to
> be
> centered.  (That is, [3,4] is true in a boolean context, but acts like
> false
> when given as the center argument to cube().)   Or perhaps you should get
> an
> error message if a non-boolean value is passed to center.  

Well, I said default, because anything other than true acts the same way a
false acts.


> If I saw some code that had stuff like
>
> cube(size,center);
>
> in it then I'd wonder what the value of center was.  It doesn't read as
> "centered cube" to me.   And the goal is just to avoid typing "=true"?  I
> suggest that if you're so offended by the need to type "center=true" and
> you
> have a lot of centered cubes, the answer is to make a centered cube
> module:

Let me ask you a question. If I want a sphere that is not centered, why
can't I write sphere(10,center = false);? Is there ANY object that is
centered that could be made not centered by using center = false?
It isn't so much the typing. It's more like I don't see a need to ever use
center = false.

You can make similar pass-through modules for other things you want to have
centered.   You can give it a shorter (more cryptic) name if you're really
frustrated by all the typing.   I suppose also if the goal is brevity you
can do "cube(1,true)".
I could, but false by itself is less "self-documenting" than center = true,
or even just center, if it would be a parameter that ALWAYS evaluated as
true in the parameters of an object that allowed center.




--
Sent from: http://forum.openscad.org/

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