Files
RustAst/examples/err.myc
T
Michael Schimmel 7b6f6e52bd Fix: Improve series type handling and coercions
This commit enhances the series type handling in `src/ast/rtl/series.rs`
by introducing helper methods `as_float` and `as_int` in
`src/ast/types.rs` to manage type conversions more robustly.

It also updates the function overload resolution in `src/ast/types.rs`
to prioritize exact parameter matches before falling back to implicit
coercions.

Finally, the example `err.myc` has been updated to reflect a more
accurate implementation of a Simple Moving Average (SMA) calculation.
2026-03-06 16:31:50 +01:00

34 lines
548 B
Plaintext

(do
(def SMA
(fn [length]
(do
(def history (series :float))
(def sum 0.0)
(fn [val]
(do
(def hist_len (len history))
(if (>= hist_len length)
(assign sum (- sum (history (- hist_len 1))))
...)
(push history val)
(assign sum (+ sum val))
(/ sum (len history))
)))))
(def sma10 (SMA 10))
(sma10 1)
(sma10 2)
(sma10 3)
(sma10 4)
(sma10 5)
(sma10 6)
(sma10 7)
(sma10 8)
(sma10 9)
(sma10 10)
(sma10 11)
)