From 2598fb2be2edbf4aca93ec4670e68c387c55b565 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Wed, 26 Feb 2020 12:32:26 +0800 Subject: [PATCH] add sum.scad --- src/experimental/_impl/_sum_impl.scad | 2 ++ src/experimental/sum.scad | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 src/experimental/_impl/_sum_impl.scad create mode 100644 src/experimental/sum.scad diff --git a/src/experimental/_impl/_sum_impl.scad b/src/experimental/_impl/_sum_impl.scad new file mode 100644 index 00000000..2c2bc47b --- /dev/null +++ b/src/experimental/_impl/_sum_impl.scad @@ -0,0 +1,2 @@ +function _sum_impl(lt, leng, i = 0) = + i == leng - 1 ? lt[i] : (lt[i] + _sum_impl(lt, leng, i + 1)); diff --git a/src/experimental/sum.scad b/src/experimental/sum.scad new file mode 100644 index 00000000..14d62e5f --- /dev/null +++ b/src/experimental/sum.scad @@ -0,0 +1,3 @@ +use ; + +function sum(lt) = _sum_impl(lt, len(lt)); \ No newline at end of file