Refactor: Simplify series creation and infer element type

The `series` constructor now only accepts the `lookback` limit. The
element type is inferred by the type checker and implicitly added as a
schema argument during compilation. This simplifies the API and
centralizes type inference.

This change also includes:
- Updates to example scripts (`HMA.myc`, `sma.myc`, `soa_series.myc`) to
  reflect the new `series` signature.
- Modifications to the `TypeChecker` to handle the inferred schema
  injection.
- An addition of a regression test for type inference through nested
  closures with `series`.
- Removal of `#[allow(dead_code)]` from several `TypeChecker` methods as
  they are now used.
- Update to `rtl/prelude.myc` macro `cache`.
- Update to `rtl/series/mod.rs` to reflect new signature.
- Update to `ast/types.rs` to allow `series` to be indexed with an
  integer to retrieve its element type.
This commit is contained in:
2026-03-28 13:47:15 +01:00
parent e595e747d4
commit d2cba2d55d
10 changed files with 284 additions and 19 deletions
+2 -2
View File
@@ -5,7 +5,7 @@
(def make-sma
(fn [lookback]
(do
(def s (series lookback :float))
(def s (series lookback))
(def running-sum 0.0)
(def count 0)
(fn [x]
@@ -22,7 +22,7 @@
(do
;; Sicherstellen, dass lookback mindestens 1 ist
(def n (if (< lookback 1) 1 lookback))
(def s (series n :float))
(def s (series n))
(def price-sum 0.0)
(def weighted-sum 0.0)
(def count 0)
+3 -3
View File
@@ -11,11 +11,11 @@
(pipe [(pipe [(.close src)] (SMA 5))] (printx "sma5="))
(pipe [(pipe [(.close src)] (SMA 100))] (printx "sma100="))
(macro cache [lookback type src] `(do (def data (series ~lookback ~type)) (pipe [~src] (fn [s] (do (push data s)))) data))
(macro cache [lookback src] `(do (def data (series ~lookback)) (pipe [~src] (fn [s] (do (push data s)))) data))
; (def bars (series 20 :float))
; (def bars (series 20))
; (pipe [src] (fn [s] (do (push bars (.close s)))))
(cache 20 :float src)
(cache 20 src)
)
+1 -1
View File
@@ -1,7 +1,7 @@
;; Benchmark: 1.1us
;; Benchmark-Repeat: 1877
(do
(def my_ticks (series 100 {:price :float :volume :int :msg :text}))
(def my_ticks (series 100))
(push my_ticks {:price 10.5 :volume 100 :msg "A"})
(push my_ticks {:price 11.2 :volume 200 :msg "B"})