discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

center = true

L
lar3ry
Fri, Dec 25, 2020 4:41 PM

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/

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/
J
jon
Fri, Dec 25, 2020 4:46 PM

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...

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... >
A
adrianv
Fri, Dec 25, 2020 5:01 PM

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

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/
L
lar3ry
Fri, Dec 25, 2020 5:03 PM

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.

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/
L
lar3ry
Fri, Dec 25, 2020 5:08 PM

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/

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/
J
jon
Fri, Dec 25, 2020 5:21 PM

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);

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); > >
A
adrianv
Fri, Dec 25, 2020 5:40 PM

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

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/
A
adrianv
Fri, Dec 25, 2020 5:50 PM

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

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/
L
lar3ry
Fri, Dec 25, 2020 6:57 PM

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

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


OpenSCAD mailing list

Discuss@.openscad

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/
RW
Ray West
Fri, Dec 25, 2020 6:58 PM

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);

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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org