discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Any where to find the doc for lc-each, lc-else and lc-for-c ?

R
runsun
Wed, Nov 2, 2016 4:56 PM

doug.moen wrote

There's no essential difference between
if (x != 0) cube(x);
at the statement level, and
if (x != 0) f(x)
in a list constructor. ...so both of these are functional
constructs. And they are really the same functional construct.

That's true. Thx.

The main problem I see with the "lc-else" extension is that it is now
possible to write [if (a%2==0) a else a10] in a list constructor, but you
can't write if (a%2==0) a else a
10 as an expression. Once we extend
expressions to support the if-else construct, then this inconsistency will
go away, and we will have a single syntax for conditionals (if-else) that
works in statements, list constructors and expressions.

Yes, the inconsistency is another problem of having "if-else" in a lc
(other than being confusing with the "if" filter).

But we already have a "?:" in the statement level:

a = A?B:C

Now we are gonna invent another one, which is more complicated, like this:

a = if(A) B else C

just for the purpose of being consistent with the "/if(A)B else C/ ternary
operator"
in the lc ? That looks like a reversed engineering to me.

If we had allowed "A?B:C" to take the "if" filter, [ for(...)A?B:if(C)D ],
which is just one step, we wouldn't have to make a big circle to firstly
invent
an "if-else" ternary operator in the lc context, then secondly make a new
construct that is more complicated than the one we already have in the
statement level (that's two steps).


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18873.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

doug.moen wrote > There's no essential difference between > if (x != 0) cube(x); > at the statement level, and > if (x != 0) f(x) > in a list constructor. ...so both of these are functional > constructs. And they are really the same functional construct. That's true. Thx. > The main problem I see with the "lc-else" extension is that it is now > possible to write [if (a%2==0) a else a*10] in a list constructor, but you > can't write if (a%2==0) a else a*10 as an expression. Once we extend > expressions to support the if-else construct, then this inconsistency will > go away, and we will have a single syntax for conditionals (if-else) that > works in statements, list constructors and expressions. Yes, the inconsistency is another problem of having "if-else" in a lc (other than being confusing with the "if" filter). But we already have a "?:" in the statement level: a = A?B:C Now we are gonna invent another one, which is more complicated, like this: a = if(A) B else C just for the purpose of being consistent with the "/if(A)B else C/ ternary operator" in the lc ? That looks like a reversed engineering to me. If we had allowed "A?B:C" to take the "if" filter, [ for(...)A?B:if(C)D ], which is just one step, we wouldn't have to make a big circle to firstly invent an "if-else" ternary operator in the lc context, then secondly make a new construct that is more complicated than the one we already have in the statement level (that's two steps). ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18873.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Wed, Nov 2, 2016 5:13 PM

Parkinbot wrote

runsun wrote

I'm not quite sure which filter you said is not general enough.

The one implemented in the actual release 2015.03. There we have

if

and no

if/then

(which is only available in the dev snapshots). This

if

can't be used within the ternary

?:

and thus is not general.

So, with respect to the next release, the filter could still be redesigned
properly e.g. by the proposed

null

value approach, avoiding the introduction of

if/then

within expressions as well as a lot of confusion and redundancy caused by
it.

i c. But, your proposal of "a==v? a : null" is not the same as
"if(a==v)a:if(b)c", 'cos it only divides items into two groups, one is
returned, one is dropped (filtering). The "if(a==v)a:if(b)c" one, on the
other hand, divides items into 2 groups (branching), one is returned, the
other then subject to the filtering (that is, further divided into accepted
items and dropped items (filtering)).

The first one is only filtering, the 2nd one is branching+filtering:

[ f(...) a==v?a:null ]

would be the same as:

[ f(...) if(a==v) a ]

it doesn't have the functionality of branching+filtering.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18874.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Parkinbot wrote > > runsun wrote >> I'm not quite sure which filter you said is not general enough. > The one implemented in the actual release 2015.03. There we have * > if * > and no * > if/then * > (which is only available in the dev snapshots). This * > if * > can't be used within the ternary * > ?: * > and thus is not general. > > So, with respect to the next release, the filter could still be redesigned > properly e.g. by the proposed * > null * > value approach, avoiding the introduction of * > if/then * > within expressions as well as a lot of confusion and redundancy caused by > it. i c. But, your proposal of "a==v? a : null" is not the same as "if(a==v)a:if(b)c", 'cos it only divides items into two groups, one is returned, one is dropped (filtering). The "if(a==v)a:if(b)c" one, on the other hand, divides items into 2 groups (branching), one is returned, the other then subject to the filtering (that is, further divided into accepted items and dropped items (filtering)). The first one is only filtering, the 2nd one is branching+filtering: [ f(...) a==v?a:null ] would be the same as: [ f(...) if(a==v) a ] it doesn't have the functionality of branching+filtering. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18874.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Wed, Nov 2, 2016 5:24 PM

The reason I say it is alien is because Python already has list
comprehensions with if else and if else in expressions but doesn't have a
weird version of the C ternary operator with a null in it. Does any
language have that?

On 2 November 2016 at 17:13, runsun runsun@gmail.com wrote:

Parkinbot wrote

runsun wrote

I'm not quite sure which filter you said is not general enough.

The one implemented in the actual release 2015.03. There we have

if

and no

if/then

(which is only available in the dev snapshots). This

if

can't be used within the ternary

?:

and thus is not general.

So, with respect to the next release, the filter could still be

redesigned

properly e.g. by the proposed

null

value approach, avoiding the introduction of

if/then

within expressions as well as a lot of confusion and redundancy caused

by

it.

i c. But, your proposal of "a==v? a : null" is not the same as
"if(a==v)a:if(b)c", 'cos it only divides items into two groups, one is
returned, one is dropped (filtering). The "if(a==v)a:if(b)c" one, on the
other hand, divides items into 2 groups (branching), one is returned, the
other then subject to the filtering (that is, further divided into accepted
items and dropped items (filtering)).

The first one is only filtering, the 2nd one is branching+filtering:

[ f(...) a==v?a:null ]

would be the same as:

[ f(...) if(a==v) a ]

it doesn't have the functionality of branching+filtering.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ),
runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix (
2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid ,
animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont ,
tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg ,
tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

View this message in context: http://forum.openscad.org/Any-
where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18874.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

The reason I say it is alien is because Python already has list comprehensions with if else and if else in expressions but doesn't have a weird version of the C ternary operator with a null in it. Does any language have that? On 2 November 2016 at 17:13, runsun <runsun@gmail.com> wrote: > Parkinbot wrote > > > > runsun wrote > >> I'm not quite sure which filter you said is not general enough. > > The one implemented in the actual release 2015.03. There we have > * > > if > * > > and no > * > > if/then > * > > (which is only available in the dev snapshots). This > * > > if > * > > can't be used within the ternary > * > > ?: > * > > and thus is not general. > > > > So, with respect to the next release, the filter could still be > redesigned > > properly e.g. by the proposed > * > > null > * > > value approach, avoiding the introduction of > * > > if/then > * > > within expressions as well as a lot of confusion and redundancy caused > by > > it. > > i c. But, your proposal of "a==v? a : null" is not the same as > "if(a==v)a:if(b)c", 'cos it only divides items into two groups, one is > returned, one is dropped (filtering). The "if(a==v)a:if(b)c" one, on the > other hand, divides items into 2 groups (branching), one is returned, the > other then subject to the filtering (that is, further divided into accepted > items and dropped items (filtering)). > > The first one is only filtering, the 2nd one is branching+filtering: > > [ f(...) a==v?a:null ] > > would be the same as: > > [ f(...) if(a==v) a ] > > it doesn't have the functionality of branching+filtering. > > > > > > ----- > > $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), > runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: hash ( 2 ), matrix ( > 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , > animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , > tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , > tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) > -- > View this message in context: http://forum.openscad.org/Any- > where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18874.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 >
R
runsun
Wed, Nov 2, 2016 5:34 PM

runsun wrote

The first one is only filtering, the 2nd one is branching+filtering:

[ f(...) a==v?a:null ]

would be the same as:

[ f(...) if(a==v) a ]

it doesn't have the functionality of branching+filtering.

Wait, come to think of it, it is possible for it to have both branching and
filtering:

[ for(...) a==A?a:(a==B?C:null) ] 

so your right, it is do-able.

I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18876.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

runsun wrote > The first one is only filtering, the 2nd one is branching+filtering: > > [ f(...) a==v?a:null ] > > would be the same as: > > [ f(...) if(a==v) a ] > > it doesn't have the functionality of branching+filtering. Wait, come to think of it, it is possible for it to have both branching and filtering: > [ for(...) a==A?a:(a==B?C:null) ] so your right, it is do-able. I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18876.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Wed, Nov 2, 2016 5:37 PM

nophead wrote

The reason I say it is alien is because Python already has list
comprehensions with if else and if else in expressions but doesn't have a
weird version of the C ternary operator with a null in it. Does any
language have that?

Not that I know of. But, like I said, any new feature is alien to some
users.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18877.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

nophead wrote > The reason I say it is alien is because Python already has list > comprehensions with if else and if else in expressions but doesn't have a > weird version of the C ternary operator with a null in it. Does any > language have that? Not that I know of. But, like I said, any new feature is alien to some users. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ); $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18877.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Wed, Nov 2, 2016 6:29 PM

runsun wrote

I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though.

nested ?: ARE ugly. But this operator is already part of the language and
you can't get rid of it any more. Bringing in a "cuter" one, doesn't do away
with it. So better make the best out of it.

For the null symbol: It is a value like any other e.g. undef, but it
will be interpreted (=omitted) by LC as well by any other operator (e.g. as
neutral element). So an echo() within LC (which is not yet available)
would prompt it, but outside it'll be gone.

Usually one would interpret *null *as 0 in number context. But it is
possible to also implement some neutral element magic, overriding it for any
interesting operator:

echo(10 + null);  // 10 : interpreted by the +-operator as 0;
echo (10 * null); // 10 :  interpreted by the *-operator as 1;
echo (10 % null); // 10 :  interpreted by the %-operator as op1;
echo ([ a, null]); // [a] : interpreted by LC as element to omit or skip;
echo ([ a, [null]]); // [a, []]
echo (null);        // null : like undef
echo (str("Hi", null)); // Hi : null is no character

and so on.

--
View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18878.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

runsun wrote > I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though. nested *?:* ARE ugly. But this operator is already part of the language and you can't get rid of it any more. Bringing in a "cuter" one, doesn't do away with it. So better make the best out of it. For the *null* symbol: It is a value like any other e.g. *undef*, but it will be interpreted (=omitted) by LC as well by any other operator (e.g. as neutral element). So an *echo()* within LC (which is not yet available) would prompt it, but outside it'll be gone. Usually one would interpret *null *as 0 in number context. But it is possible to also implement some neutral element magic, overriding it for any interesting operator: > echo(10 + null); // 10 : interpreted by the +-operator as 0; > echo (10 * null); // 10 : interpreted by the *-operator as 1; > echo (10 % null); // 10 : interpreted by the %-operator as op1; > echo ([ a, null]); // [a] : interpreted by LC as element to omit or skip; > echo ([ a, [null]]); // [a, []] > echo (null); // null : like undef > echo (str("Hi", null)); // Hi : null is no character and so on. -- View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18878.html Sent from the OpenSCAD mailing list archive at Nabble.com.
DM
doug moen
Wed, Nov 2, 2016 8:29 PM

Parkinbot wrote:

nested ?: ARE ugly.

I agree. Especially when you have to write a large, multi-line conditional
within a function. That's the situation where if-else expressions will add
a lot of readability to the language.

Once we have if-else conditionals supported everywhere (statements, list
comprehensions and statements), then we'll have a consistent syntax for
conditionals, and there won't be any more confusion about "when do I use
if-else" vs "when do I have to use ?: instead".

Every functional programming language already uses if-else for conditional
expressions, even Python uses if-else for conditional expressions, so we
aren't breaking any new ground here.

I don't see any justification for creating a new symbol "null" with
different meanings in different contexts, just so that we can type
"a?b:null" as an alternative to "if(a)b". The already existing syntax that
uses "if" is more readable, because the syntax is familiar. Every existing
programming language already uses the "if" and "else" keywords, so we
should use that, instead of creating something new.

I don't think that
(x != 0) ? cube(x) : null;
is an improvement over
if (x != 0) cube(x);
at the statement level, and it's the same argument for list comprehensions.
It's pretty standard to use 'if' for conditionals in list comprehensions,
there are no languages that use ?: in this context.

On 2 November 2016 at 14:29, Parkinbot rudolf@parkinbot.com wrote:

runsun wrote

I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though.

nested ?: ARE ugly. But this operator is already part of the language and
you can't get rid of it any more. Bringing in a "cuter" one, doesn't do
away
with it. So better make the best out of it.

For the null symbol: It is a value like any other e.g. undef, but it
will be interpreted (=omitted) by LC as well by any other operator (e.g. as
neutral element). So an echo() within LC (which is not yet available)
would prompt it, but outside it'll be gone.

Usually one would interpret *null *as 0 in number context. But it is
possible to also implement some neutral element magic, overriding it for
any
interesting operator:

echo(10 + null);  // 10 : interpreted by the +-operator as 0;
echo (10 * null); // 10 :  interpreted by the *-operator as 1;
echo (10 % null); // 10 :  interpreted by the %-operator as op1;
echo ([ a, null]); // [a] : interpreted by LC as element to omit or skip;
echo ([ a, [null]]); // [a, []]
echo (null);        // null : like undef
echo (str("Hi", null)); // Hi : null is no character

and so on.

--
View this message in context: http://forum.openscad.org/Any-
where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18878.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

Parkinbot wrote: > nested *?:* ARE ugly. I agree. Especially when you have to write a large, multi-line conditional within a function. That's the situation where if-else expressions will add a lot of readability to the language. Once we have if-else conditionals supported everywhere (statements, list comprehensions and statements), then we'll have a consistent syntax for conditionals, and there won't be any more confusion about "when do I use if-else" vs "when do I have to use ?: instead". Every functional programming language already uses if-else for conditional expressions, even Python uses if-else for conditional expressions, so we aren't breaking any new ground here. I don't see any justification for creating a new symbol "null" with different meanings in different contexts, just so that we can type "a?b:null" as an alternative to "if(a)b". The already existing syntax that uses "if" is more readable, because the syntax is familiar. Every existing programming language already uses the "if" and "else" keywords, so we should use that, instead of creating something new. I don't think that (x != 0) ? cube(x) : null; is an improvement over if (x != 0) cube(x); at the statement level, and it's the same argument for list comprehensions. It's pretty standard to use 'if' for conditionals in list comprehensions, there are no languages that use ?: in this context. On 2 November 2016 at 14:29, Parkinbot <rudolf@parkinbot.com> wrote: > runsun wrote > > I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though. > > nested *?:* ARE ugly. But this operator is already part of the language and > you can't get rid of it any more. Bringing in a "cuter" one, doesn't do > away > with it. So better make the best out of it. > > For the *null* symbol: It is a value like any other e.g. *undef*, but it > will be interpreted (=omitted) by LC as well by any other operator (e.g. as > neutral element). So an *echo()* within LC (which is not yet available) > would prompt it, but outside it'll be gone. > > Usually one would interpret *null *as 0 in number context. But it is > possible to also implement some neutral element magic, overriding it for > any > interesting operator: > > > echo(10 + null); // 10 : interpreted by the +-operator as 0; > > echo (10 * null); // 10 : interpreted by the *-operator as 1; > > echo (10 % null); // 10 : interpreted by the %-operator as op1; > > echo ([ a, null]); // [a] : interpreted by LC as element to omit or skip; > > echo ([ a, [null]]); // [a, []] > > echo (null); // null : like undef > > echo (str("Hi", null)); // Hi : null is no character > > and so on. > > > > -- > View this message in context: http://forum.openscad.org/Any- > where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18878.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
Wed, Nov 2, 2016 8:40 PM

2016-11-02 18:29 GMT-02:00 doug moen doug@moens.org:

Once we have if-else conditionals supported everywhere (statements, list
comprehensions and statements), then we'll have a consistent syntax for
conditionals, and there won't be any more confusion about "when do I use
if-else" vs "when do I have to use ?: instead".

So you suggest to extend "if-else" as a conditional expression to statements
and lc but to keep "if-without else" just as a filter in the context of lc,
do you? That sounds nice.

2016-11-02 18:29 GMT-02:00 doug moen <doug@moens.org>: > Once we have if-else conditionals supported everywhere (statements, list > comprehensions and statements), then we'll have a consistent syntax for > conditionals, and there won't be any more confusion about "when do I use > if-else" vs "when do I have to use ?: instead". > So you suggest to extend "if-else" as a conditional expression to statements and lc but to keep "if-without else" just as a filter in the context of lc, do you? That sounds nice.
NH
nop head
Wed, Nov 2, 2016 8:40 PM

Well stated Doug, I couldn't agree more.

On 2 November 2016 at 20:29, doug moen doug@moens.org wrote:

Parkinbot wrote:

nested ?: ARE ugly.

I agree. Especially when you have to write a large, multi-line conditional
within a function. That's the situation where if-else expressions will add
a lot of readability to the language.

Once we have if-else conditionals supported everywhere (statements, list
comprehensions and statements), then we'll have a consistent syntax for
conditionals, and there won't be any more confusion about "when do I use
if-else" vs "when do I have to use ?: instead".

Every functional programming language already uses if-else for conditional
expressions, even Python uses if-else for conditional expressions, so we
aren't breaking any new ground here.

I don't see any justification for creating a new symbol "null" with
different meanings in different contexts, just so that we can type
"a?b:null" as an alternative to "if(a)b". The already existing syntax that
uses "if" is more readable, because the syntax is familiar. Every existing
programming language already uses the "if" and "else" keywords, so we
should use that, instead of creating something new.

I don't think that
(x != 0) ? cube(x) : null;
is an improvement over
if (x != 0) cube(x);
at the statement level, and it's the same argument for list
comprehensions. It's pretty standard to use 'if' for conditionals in list
comprehensions, there are no languages that use ?: in this context.

On 2 November 2016 at 14:29, Parkinbot rudolf@parkinbot.com wrote:

runsun wrote

I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though.

nested ?: ARE ugly. But this operator is already part of the language
and
you can't get rid of it any more. Bringing in a "cuter" one, doesn't do
away
with it. So better make the best out of it.

For the null symbol: It is a value like any other e.g. undef, but it
will be interpreted (=omitted) by LC as well by any other operator (e.g.
as
neutral element). So an echo() within LC (which is not yet available)
would prompt it, but outside it'll be gone.

Usually one would interpret *null *as 0 in number context. But it is
possible to also implement some neutral element magic, overriding it for
any
interesting operator:

echo(10 + null);  // 10 : interpreted by the +-operator as 0;
echo (10 * null); // 10 :  interpreted by the *-operator as 1;
echo (10 % null); // 10 :  interpreted by the %-operator as op1;
echo ([ a, null]); // [a] : interpreted by LC as element to omit or

skip;

echo ([ a, [null]]); // [a, []]
echo (null);        // null : like undef
echo (str("Hi", null)); // Hi : null is no character

and so on.

--
View this message in context: http://forum.openscad.org/Any-
where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18878.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

Well stated Doug, I couldn't agree more. On 2 November 2016 at 20:29, doug moen <doug@moens.org> wrote: > Parkinbot wrote: > > nested *?:* ARE ugly. > > I agree. Especially when you have to write a large, multi-line conditional > within a function. That's the situation where if-else expressions will add > a lot of readability to the language. > > Once we have if-else conditionals supported everywhere (statements, list > comprehensions and statements), then we'll have a consistent syntax for > conditionals, and there won't be any more confusion about "when do I use > if-else" vs "when do I have to use ?: instead". > > Every functional programming language already uses if-else for conditional > expressions, even Python uses if-else for conditional expressions, so we > aren't breaking any new ground here. > > I don't see any justification for creating a new symbol "null" with > different meanings in different contexts, just so that we can type > "a?b:null" as an alternative to "if(a)b". The already existing syntax that > uses "if" is more readable, because the syntax is familiar. Every existing > programming language already uses the "if" and "else" keywords, so we > should use that, instead of creating something new. > > I don't think that > (x != 0) ? cube(x) : null; > is an improvement over > if (x != 0) cube(x); > at the statement level, and it's the same argument for list > comprehensions. It's pretty standard to use 'if' for conditionals in list > comprehensions, there are no languages that use ?: in this context. > > > > On 2 November 2016 at 14:29, Parkinbot <rudolf@parkinbot.com> wrote: > >> runsun wrote >> > I still think a [ for(...) a==A?a:if(a==B)C ] is more readable, though. >> >> nested *?:* ARE ugly. But this operator is already part of the language >> and >> you can't get rid of it any more. Bringing in a "cuter" one, doesn't do >> away >> with it. So better make the best out of it. >> >> For the *null* symbol: It is a value like any other e.g. *undef*, but it >> will be interpreted (=omitted) by LC as well by any other operator (e.g. >> as >> neutral element). So an *echo()* within LC (which is not yet available) >> would prompt it, but outside it'll be gone. >> >> Usually one would interpret *null *as 0 in number context. But it is >> possible to also implement some neutral element magic, overriding it for >> any >> interesting operator: >> >> > echo(10 + null); // 10 : interpreted by the +-operator as 0; >> > echo (10 * null); // 10 : interpreted by the *-operator as 1; >> > echo (10 % null); // 10 : interpreted by the %-operator as op1; >> > echo ([ a, null]); // [a] : interpreted by LC as element to omit or >> skip; >> > echo ([ a, [null]]); // [a, []] >> > echo (null); // null : like undef >> > echo (str("Hi", null)); // Hi : null is no character >> >> and so on. >> >> >> >> -- >> View this message in context: http://forum.openscad.org/Any- >> where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18878.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 > >
P
Parkinbot
Thu, Nov 3, 2016 12:23 AM

I am able to program with both, as I can live with many other crudities of
OpenSCAD. That is not the point.

In language design it is quite easiy (and tempting) to introduce new stuff
and also redundancy. But one should never forget that it is almost
impossible to get rid of stuff already introduced, language incongruities,
and premature hacks. So why was ?: initially introduced, if if/else is
so popular?

Look at:

a = if (b) c;

Which value will a get, if b is false?

--
View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18891.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I am able to program with both, as I can live with many other crudities of OpenSCAD. That is not the point. In language design it is quite easiy (and tempting) to introduce new stuff and also redundancy. But one should never forget that it is almost impossible to get rid of stuff already introduced, language incongruities, and premature hacks. So why was *?:* initially introduced, if *if/else* is so popular? Look at: > a = if (b) c; Which value will *a* get, if *b* is *false*? -- View this message in context: http://forum.openscad.org/Any-where-to-find-the-doc-for-lc-each-lc-else-and-lc-for-c-tp18823p18891.html Sent from the OpenSCAD mailing list archive at Nabble.com.