Refactor SMA implementation to lib/sma.myc

Move the SMA implementation from examples/err.myc and examples/sma.myc
to a new dedicated file in lib/. This change also cleans up unused code
and improves the SMA logic.
This commit is contained in:
Michael Schimmel
2026-03-06 17:22:42 +01:00
parent 8fa2ca4cb5
commit d4ca9c4620
3 changed files with 26 additions and 52 deletions
+6 -18
View File
@@ -1,24 +1,12 @@
;; Output: 5.5
(do
(def SMA
(fn [length]
(do
(def history (series :float))
(push history 0)
(fn [val]
(do
(def sum (+ val (history 0)))
(push history sum)
(/ sum length)
))
)))
(def sma20 (SMA 20))
(def n 100)
(while (> n 0)
(do
(def n 1000)
(while (> n 0)
(do
(print "val=" n " sma20=" (sma20 n))
(assign n (- n 1))
))
)
)