Do multiple "false" make a single "true"?

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

Do multiple "false" make a single "true"?

wolf
Consider this code:

AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291, 1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047, -2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478, 0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563, -2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549, 1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291, -1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3, 0, 1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291, 1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8], [1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4], [-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165, 2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]], [[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3], [-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3], [3, 0, 3]]];
echo("AA",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] );   //ECHO: "AA", [false, false, false, false, false]
echo("BB",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] ? "TRue" : "FaLse");    //ECHO: "BB", "TRue"

Line 2 and 3 contain identical test instructions. Does anyone know how to change line 3 so that multiple "true"s return a True_Condition, and one or more "false"s return a False_Condition?

Thanks

wolf
Reply | Threaded
Open this post in threaded view
|

Re: Do multiple "false" make a single "true"?

nophead
I think this does what you want:

function allTrue(list, i = 1) =
    i >= len(list) ? true
                   : list[0][0] != list[0][i] ? false
                                              : allTrue(list, i + 1);

echo(allTrue(AnyShape) ? "TRue" : "FaLse");


On 14 July 2017 at 07:10, wolf <[hidden email]> wrote:
Consider this code:

AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291,
1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047,
-2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478,
0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563,
-2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549,
1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291,
-1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3, 0,
1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291,
1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8],
[1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4],
[-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165,
2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]],
[[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3],
[-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3],
[3, 0, 3]]];
echo("AA",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] );
//ECHO: "AA", [false, false, false, false, false]
echo("BB",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] ?
"TRue" : "FaLse");    //ECHO: "BB", "TRue"

Line 2 and 3 contain identical test instructions. Does anyone know how to
change line 3 so that multiple "true"s return a True_Condition, and one or
more "false"s return a False_Condition?

Thanks

wolf




--
View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
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: Do multiple "false" make a single "true"?

wolf
Thanks, that worked a treat. Packaging a Test_Condition as a function never crossed my mind.

wolf
Reply | Threaded
Open this post in threaded view
|

Re: Do multiple "false" make a single "true"?

nophead
I should have called the function allSame rather than allTrue.

On 16 July 2017 at 08:22, wolf <[hidden email]> wrote:
Thanks, that worked a treat. Packaging a Test_Condition as a function never
crossed my mind.

wolf



--
View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822p21832.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
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: Do multiple "false" make a single "true"?

Joshua Holbrook
Traditional names for these kind of functions some/any and each/every.

I dunno what it would involve, but adding these to the openscad stdlib is a reasonable idea.

--Josh

On Sun, Jul 16, 2017 at 6:16 AM, nop head <[hidden email]> wrote:
I should have called the function allSame rather than allTrue.

On 16 July 2017 at 08:22, wolf <[hidden email]> wrote:
Thanks, that worked a treat. Packaging a Test_Condition as a function never
crossed my mind.

wolf



--
View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822p21832.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
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



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org