DS
Dan Shriver
Wed, Nov 2, 2016 11:11 PM
I've got two basic questions.
Is there any way to make a function in openScad which isn't a straight
formula? For instance the input parameter is a number and inside the
function I use a series of if statements to check the value and decide what
to return (alternately maybe the input parameter could pick a hardcoded
value out of a list??? But I don't know the proper syntax for that).
Likewise, is there any plan to support a "case" statement type construct,
either in functions or modules?
I've got two basic questions.
Is there any way to make a function in openScad which isn't a straight
formula? For instance the input parameter is a number and inside the
function I use a series of if statements to check the value and decide what
to return (alternately maybe the input parameter could pick a hardcoded
value out of a list??? But I don't know the proper syntax for that).
Likewise, is there any plan to support a "case" statement type construct,
either in functions or modules?
W
Whosawhatsis
Wed, Nov 2, 2016 11:24 PM
Use the ternary operator: https://en.wikipedia.org/wiki/%3F:
From: Dan Shriver tabbydan@gmail.com tabbydan@gmail.com
Reply: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Date: November 2, 2016 at 16:11:54
To: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Subject: [OpenSCAD] function with if; case statement;
I've got two basic questions.
Is there any way to make a function in openScad which isn't a straight
formula? For instance the input parameter is a number and inside the
function I use a series of if statements to check the value and decide what
to return (alternately maybe the input parameter could pick a hardcoded
value out of a list??? But I don't know the proper syntax for that).
Likewise, is there any plan to support a "case" statement type construct,
either in functions or modules?
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Use the ternary operator: https://en.wikipedia.org/wiki/%3F:
From: Dan Shriver <tabbydan@gmail.com> <tabbydan@gmail.com>
Reply: OpenSCAD general discussion <discuss@lists.openscad.org>
<discuss@lists.openscad.org>
Date: November 2, 2016 at 16:11:54
To: OpenSCAD general discussion <discuss@lists.openscad.org>
<discuss@lists.openscad.org>
Subject: [OpenSCAD] function with if; case statement;
I've got two basic questions.
Is there any way to make a function in openScad which isn't a straight
formula? For instance the input parameter is a number and inside the
function I use a series of if statements to check the value and decide what
to return (alternately maybe the input parameter could pick a hardcoded
value out of a list??? But I don't know the proper syntax for that).
Likewise, is there any plan to support a "case" statement type construct,
either in functions or modules?
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
DS
Dan Shriver
Wed, Nov 2, 2016 11:33 PM
terniary operator can only return two possible values so I don't see how
that can help with the current problem, unless the openscad "?" is
different from the one I'm used to
If I need to return one of n different values can I chain "?"
(x == 1) ? 5 : (x == 2) ? 7 : (x == 3) ? 4 ....
On Wed, Nov 2, 2016 at 7:24 PM, Whosawhatsis whosawhatsis@gmail.com wrote:
terniary operator can only return two possible values so I don't see how
that can help with the current problem, unless the openscad "?" is
different from the one I'm used to
If I need to return one of n different values can I chain "?"
(x == 1) ? 5 : (x == 2) ? 7 : (x == 3) ? 4 ....
On Wed, Nov 2, 2016 at 7:24 PM, Whosawhatsis <whosawhatsis@gmail.com> wrote:
> Use the ternary operator: https://en.wikipedia.org/wiki/%3F:
>
>
>
> From: Dan Shriver <tabbydan@gmail.com> <tabbydan@gmail.com>
> Reply: OpenSCAD general discussion <discuss@lists.openscad.org>
> <discuss@lists.openscad.org>
> Date: November 2, 2016 at 16:11:54
> To: OpenSCAD general discussion <discuss@lists.openscad.org>
> <discuss@lists.openscad.org>
> Subject: [OpenSCAD] function with if; case statement;
>
> I've got two basic questions.
>
> Is there any way to make a function in openScad which isn't a straight
> formula? For instance the input parameter is a number and inside the
> function I use a series of if statements to check the value and decide what
> to return (alternately maybe the input parameter could pick a hardcoded
> value out of a list??? But I don't know the proper syntax for that).
> Likewise, is there any plan to support a "case" statement type construct,
> either in functions or modules?
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
NH
nop head
Wed, Nov 2, 2016 11:34 PM
Functions only consist of expressions so you need to use the ternary
conditional operator. E.g.
function f(x) = x == 1 ? 42
: x == 2 ? 99 : 0;
This returns 42 when x is 1, 99 when x = 2 otherwise 0.
On 2 November 2016 at 23:11, Dan Shriver tabbydan@gmail.com wrote:
I've got two basic questions.
Is there any way to make a function in openScad which isn't a straight
formula? For instance the input parameter is a number and inside the
function I use a series of if statements to check the value and decide what
to return (alternately maybe the input parameter could pick a hardcoded
value out of a list??? But I don't know the proper syntax for that).
Likewise, is there any plan to support a "case" statement type construct,
either in functions or modules?
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Functions only consist of expressions so you need to use the ternary
conditional operator. E.g.
function f(x) = x == 1 ? 42
: x == 2 ? 99 : 0;
This returns 42 when x is 1, 99 when x = 2 otherwise 0.
On 2 November 2016 at 23:11, Dan Shriver <tabbydan@gmail.com> wrote:
> I've got two basic questions.
>
> Is there any way to make a function in openScad which isn't a straight
> formula? For instance the input parameter is a number and inside the
> function I use a series of if statements to check the value and decide what
> to return (alternately maybe the input parameter could pick a hardcoded
> value out of a list??? But I don't know the proper syntax for that).
> Likewise, is there any plan to support a "case" statement type construct,
> either in functions or modules?
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
R
runsun
Thu, Nov 3, 2016 12:17 AM
I often chain them but put them in a structural format:
function f(x)=
(
x==1?
x+1
: x==2 ?
let(y=3) x*y // you can use let
: x==3?
let( x=100, y=10 ) // you can even re defined x locally
x+y+y
: x
);
echo(f(1)); // = 2
echo(f(2)); // = 6
echo(f(3)); // = 120
echo(f(30)); // =30
You can come up with very complex content but still easily readable if empty
lines are inserted:
function f(x)=
(
x==1?
let(...)
(
......
......
)
: x==2 ?
let(...)
(
......
......
)
: x==3?
let(...)
(
......
......
)
: x
);
$ 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/function-with-if-case-statement-tp18882p18890.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
I often chain them but put them in a structural format:
> function f(x)=
> (
> x==1?
> x+1
> : x==2 ?
> let(y=3) x*y // you can use let
> : x==3?
> let( x=100, y=10 ) // you can even re defined x locally
> x+y+y
> : x
> );
>
> echo(f(1)); // = 2
> echo(f(2)); // = 6
> echo(f(3)); // = 120
> echo(f(30)); // =30
You can come up with very complex content but still easily readable if empty
lines are inserted:
> function f(x)=
> (
> x==1?
>
> let(...)
> (
> ......
> ......
> )
>
> : x==2 ?
>
> let(...)
> (
> ......
> ......
> )
>
> : x==3?
>
> let(...)
> (
> ......
> ......
> )
>
> : x
> );
-----
$ 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/function-with-if-case-statement-tp18882p18890.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
DS
Dan Shriver
Thu, Nov 3, 2016 12:48 AM
thaks whosawhatsis, nophead, runsun....
I tried that with several syntaxes and kept getting parse errors. Do I
need a special version of openScad to get the chained "?"?
Every time I try it (with and without "(" ");"; with and without readable
whitespace; with and without () around the testing) I get parsing errors.
On Wed, Nov 2, 2016 at 8:17 PM, runsun runsun@gmail.com wrote:
I often chain them but put them in a structural format:
function f(x)=
(
x==1?
x+1
: x==2 ?
let(y=3) x*y // you can use let
: x==3?
let( x=100, y=10 ) // you can even re defined x locally
x+y+y
: x
);
echo(f(1)); // = 2
echo(f(2)); // = 6
echo(f(3)); // = 120
echo(f(30)); // =30
You can come up with very complex content but still easily readable if
empty
lines are inserted:
function f(x)=
(
x==1?
let(...)
(
......
......
)
: x==2 ?
let(...)
(
......
......
)
: x==3?
let(...)
(
......
......
)
: x
);
$ 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/
function-with-if-case-statement-tp18882p18890.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
thaks whosawhatsis, nophead, runsun....
I tried that with several syntaxes and kept getting parse errors. Do I
need a special version of openScad to get the chained "?"?
Every time I try it (with and without "(" ");"; with and without readable
whitespace; with and without () around the testing) I get parsing errors.
On Wed, Nov 2, 2016 at 8:17 PM, runsun <runsun@gmail.com> wrote:
> I often chain them but put them in a structural format:
>
> > function f(x)=
> > (
> > x==1?
> > x+1
> > : x==2 ?
> > let(y=3) x*y // you can use let
> > : x==3?
> > let( x=100, y=10 ) // you can even re defined x locally
> > x+y+y
> > : x
> > );
> >
> > echo(f(1)); // = 2
> > echo(f(2)); // = 6
> > echo(f(3)); // = 120
> > echo(f(30)); // =30
>
> You can come up with very complex content but still easily readable if
> empty
> lines are inserted:
>
>
> > function f(x)=
> > (
> > x==1?
> >
> > let(...)
> > (
> > ......
> > ......
> > )
> >
> > : x==2 ?
> >
> > let(...)
> > (
> > ......
> > ......
> > )
> >
> > : x==3?
> >
> > let(...)
> > (
> > ......
> > ......
> > )
> >
> > : x
> > );
>
>
>
>
>
> -----
>
> $ 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/
> function-with-if-case-statement-tp18882p18890.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
>
W
Whosawhatsis
Thu, Nov 3, 2016 12:57 AM
Should work in any version. If you post what you tried to write, one of us
will be able to see what's wrong with it.
From: Dan Shriver tabbydan@gmail.com tabbydan@gmail.com
Reply: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Date: November 2, 2016 at 17:49:29
To: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Subject: Re: [OpenSCAD] function with if; case statement;
thaks whosawhatsis, nophead, runsun....
I tried that with several syntaxes and kept getting parse errors. Do I
need a special version of openScad to get the chained "?"?
Every time I try it (with and without "(" ");"; with and without readable
whitespace; with and without () around the testing) I get parsing errors.
On Wed, Nov 2, 2016 at 8:17 PM, runsun runsun@gmail.com wrote:
I often chain them but put them in a structural format:
function f(x)=
(
x==1?
x+1
: x==2 ?
let(y=3) x*y // you can use let
: x==3?
let( x=100, y=10 ) // you can even re defined x locally
x+y+y
: x
);
echo(f(1)); // = 2
echo(f(2)); // = 6
echo(f(3)); // = 120
echo(f(30)); // =30
You can come up with very complex content but still easily readable if
empty
lines are inserted:
function f(x)=
(
x==1?
let(...)
(
......
......
)
: x==2 ?
let(...)
(
......
......
)
: x==3?
let(...)
(
......
......
)
: x
);
$ 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/
function-with-if-case-statement-tp18882p18890.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
Should work in any version. If you post what you tried to write, one of us
will be able to see what's wrong with it.
From: Dan Shriver <tabbydan@gmail.com> <tabbydan@gmail.com>
Reply: OpenSCAD general discussion <discuss@lists.openscad.org>
<discuss@lists.openscad.org>
Date: November 2, 2016 at 17:49:29
To: OpenSCAD general discussion <discuss@lists.openscad.org>
<discuss@lists.openscad.org>
Subject: Re: [OpenSCAD] function with if; case statement;
thaks whosawhatsis, nophead, runsun....
I tried that with several syntaxes and kept getting parse errors. Do I
need a special version of openScad to get the chained "?"?
Every time I try it (with and without "(" ");"; with and without readable
whitespace; with and without () around the testing) I get parsing errors.
On Wed, Nov 2, 2016 at 8:17 PM, runsun <runsun@gmail.com> wrote:
> I often chain them but put them in a structural format:
>
> > function f(x)=
> > (
> > x==1?
> > x+1
> > : x==2 ?
> > let(y=3) x*y // you can use let
> > : x==3?
> > let( x=100, y=10 ) // you can even re defined x locally
> > x+y+y
> > : x
> > );
> >
> > echo(f(1)); // = 2
> > echo(f(2)); // = 6
> > echo(f(3)); // = 120
> > echo(f(30)); // =30
>
> You can come up with very complex content but still easily readable if
> empty
> lines are inserted:
>
>
> > function f(x)=
> > (
> > x==1?
> >
> > let(...)
> > (
> > ......
> > ......
> > )
> >
> > : x==2 ?
> >
> > let(...)
> > (
> > ......
> > ......
> > )
> >
> > : x==3?
> >
> > let(...)
> > (
> > ......
> > ......
> > )
> >
> > : x
> > );
>
>
>
>
>
> -----
>
> $ 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/
> function-with-if-case-statement-tp18882p18890.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
DS
Dan Shriver
Thu, Nov 3, 2016 1:05 AM
whosawhatsis... yeah, digging into it, it is a bug somewhere in my code. I
already ferreted out one but obviously there is some more.
If I post the whole thing (because maybe it is in some line (as in any
line) above the one it flags) I think one or more of you guys will go blind
:(
On Wed, Nov 2, 2016 at 8:57 PM, Whosawhatsis whosawhatsis@gmail.com wrote:
Should work in any version. If you post what you tried to write, one of us
will be able to see what's wrong with it.
From: Dan Shriver tabbydan@gmail.com tabbydan@gmail.com
Reply: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Date: November 2, 2016 at 17:49:29
To: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Subject: Re: [OpenSCAD] function with if; case statement;
thaks whosawhatsis, nophead, runsun....
I tried that with several syntaxes and kept getting parse errors. Do I
need a special version of openScad to get the chained "?"?
Every time I try it (with and without "(" ");"; with and without readable
whitespace; with and without () around the testing) I get parsing errors.
On Wed, Nov 2, 2016 at 8:17 PM, runsun runsun@gmail.com wrote:
I often chain them but put them in a structural format:
function f(x)=
(
x==1?
x+1
: x==2 ?
let(y=3) x*y // you can use let
: x==3?
let( x=100, y=10 ) // you can even re defined x locally
x+y+y
: x
);
echo(f(1)); // = 2
echo(f(2)); // = 6
echo(f(3)); // = 120
echo(f(30)); // =30
You can come up with very complex content but still easily readable if
empty
lines are inserted:
function f(x)=
(
x==1?
let(...)
(
......
......
)
: x==2 ?
let(...)
(
......
......
)
: x==3?
let(...)
(
......
......
)
: x
);
$ 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/func
tion-with-if-case-statement-tp18882p18890.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
whosawhatsis... yeah, digging into it, it is a bug somewhere in my code. I
already ferreted out one but obviously there is some more.
If I post the whole thing (because maybe it is in some line (as in any
line) above the one it flags) I think one or more of you guys will go blind
:(
On Wed, Nov 2, 2016 at 8:57 PM, Whosawhatsis <whosawhatsis@gmail.com> wrote:
> Should work in any version. If you post what you tried to write, one of us
> will be able to see what's wrong with it.
>
>
>
> From: Dan Shriver <tabbydan@gmail.com> <tabbydan@gmail.com>
> Reply: OpenSCAD general discussion <discuss@lists.openscad.org>
> <discuss@lists.openscad.org>
> Date: November 2, 2016 at 17:49:29
> To: OpenSCAD general discussion <discuss@lists.openscad.org>
> <discuss@lists.openscad.org>
> Subject: Re: [OpenSCAD] function with if; case statement;
>
> thaks whosawhatsis, nophead, runsun....
>
> I tried that with several syntaxes and kept getting parse errors. Do I
> need a special version of openScad to get the chained "?"?
>
> Every time I try it (with and without "(" ");"; with and without readable
> whitespace; with and without () around the testing) I get parsing errors.
>
> On Wed, Nov 2, 2016 at 8:17 PM, runsun <runsun@gmail.com> wrote:
>
>> I often chain them but put them in a structural format:
>>
>> > function f(x)=
>> > (
>> > x==1?
>> > x+1
>> > : x==2 ?
>> > let(y=3) x*y // you can use let
>> > : x==3?
>> > let( x=100, y=10 ) // you can even re defined x locally
>> > x+y+y
>> > : x
>> > );
>> >
>> > echo(f(1)); // = 2
>> > echo(f(2)); // = 6
>> > echo(f(3)); // = 120
>> > echo(f(30)); // =30
>>
>> You can come up with very complex content but still easily readable if
>> empty
>> lines are inserted:
>>
>>
>> > function f(x)=
>> > (
>> > x==1?
>> >
>> > let(...)
>> > (
>> > ......
>> > ......
>> > )
>> >
>> > : x==2 ?
>> >
>> > let(...)
>> > (
>> > ......
>> > ......
>> > )
>> >
>> > : x==3?
>> >
>> > let(...)
>> > (
>> > ......
>> > ......
>> > )
>> >
>> > : x
>> > );
>>
>>
>>
>>
>>
>> -----
>>
>> $ 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/func
>> tion-with-if-case-statement-tp18882p18890.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
>
>
DS
Dan Shriver
Thu, Nov 3, 2016 1:36 AM
[image: Inline image 1]
thanks guys!
On Wed, Nov 2, 2016 at 8:57 PM, Whosawhatsis whosawhatsis@gmail.com wrote:
Should work in any version. If you post what you tried to write, one of us
will be able to see what's wrong with it.
From: Dan Shriver tabbydan@gmail.com tabbydan@gmail.com
Reply: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Date: November 2, 2016 at 17:49:29
To: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Subject: Re: [OpenSCAD] function with if; case statement;
thaks whosawhatsis, nophead, runsun....
I tried that with several syntaxes and kept getting parse errors. Do I
need a special version of openScad to get the chained "?"?
Every time I try it (with and without "(" ");"; with and without readable
whitespace; with and without () around the testing) I get parsing errors.
On Wed, Nov 2, 2016 at 8:17 PM, runsun runsun@gmail.com wrote:
I often chain them but put them in a structural format:
function f(x)=
(
x==1?
x+1
: x==2 ?
let(y=3) x*y // you can use let
: x==3?
let( x=100, y=10 ) // you can even re defined x locally
x+y+y
: x
);
echo(f(1)); // = 2
echo(f(2)); // = 6
echo(f(3)); // = 120
echo(f(30)); // =30
You can come up with very complex content but still easily readable if
empty
lines are inserted:
function f(x)=
(
x==1?
let(...)
(
......
......
)
: x==2 ?
let(...)
(
......
......
)
: x==3?
let(...)
(
......
......
)
: x
);
$ 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/func
tion-with-if-case-statement-tp18882p18890.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
[image: Inline image 1]
thanks guys!
On Wed, Nov 2, 2016 at 8:57 PM, Whosawhatsis <whosawhatsis@gmail.com> wrote:
> Should work in any version. If you post what you tried to write, one of us
> will be able to see what's wrong with it.
>
>
>
> From: Dan Shriver <tabbydan@gmail.com> <tabbydan@gmail.com>
> Reply: OpenSCAD general discussion <discuss@lists.openscad.org>
> <discuss@lists.openscad.org>
> Date: November 2, 2016 at 17:49:29
> To: OpenSCAD general discussion <discuss@lists.openscad.org>
> <discuss@lists.openscad.org>
> Subject: Re: [OpenSCAD] function with if; case statement;
>
> thaks whosawhatsis, nophead, runsun....
>
> I tried that with several syntaxes and kept getting parse errors. Do I
> need a special version of openScad to get the chained "?"?
>
> Every time I try it (with and without "(" ");"; with and without readable
> whitespace; with and without () around the testing) I get parsing errors.
>
> On Wed, Nov 2, 2016 at 8:17 PM, runsun <runsun@gmail.com> wrote:
>
>> I often chain them but put them in a structural format:
>>
>> > function f(x)=
>> > (
>> > x==1?
>> > x+1
>> > : x==2 ?
>> > let(y=3) x*y // you can use let
>> > : x==3?
>> > let( x=100, y=10 ) // you can even re defined x locally
>> > x+y+y
>> > : x
>> > );
>> >
>> > echo(f(1)); // = 2
>> > echo(f(2)); // = 6
>> > echo(f(3)); // = 120
>> > echo(f(30)); // =30
>>
>> You can come up with very complex content but still easily readable if
>> empty
>> lines are inserted:
>>
>>
>> > function f(x)=
>> > (
>> > x==1?
>> >
>> > let(...)
>> > (
>> > ......
>> > ......
>> > )
>> >
>> > : x==2 ?
>> >
>> > let(...)
>> > (
>> > ......
>> > ......
>> > )
>> >
>> > : x==3?
>> >
>> > let(...)
>> > (
>> > ......
>> > ......
>> > )
>> >
>> > : x
>> > );
>>
>>
>>
>>
>>
>> -----
>>
>> $ 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/func
>> tion-with-if-case-statement-tp18882p18890.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
>
>
M
MichaelAtOz
Thu, Nov 3, 2016 11:10 PM
This is how I lay them out for clarity, with tabs aligning the test, '?' &':'
function x(p) =
(test)
? true_expression
: false_expression;
function many(p) =
(test1)
? (test1-t)
? t_expr
: f_expr
: (test1-f)
? t_expr
: f_expr; // etc
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/function-with-if-case-statement-tp18882p18923.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
This is how I lay them out for clarity, with tabs aligning the test, '?' &':'
function x(p) =
(test)
? true_expression
: false_expression;
function many(p) =
(test1)
? (test1-t)
? t_expr
: f_expr
: (test1-f)
? t_expr
: f_expr; // etc
-----
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/function-with-if-case-statement-tp18882p18923.html
Sent from the OpenSCAD mailing list archive at Nabble.com.