Files
RustAst/examples/sma.myc
T
Michael Schimmel 595bcf09e5 Update examples to use StreamNode and Series with lookback
The `PipelineNode` has been refactored into `StreamNode`. This commit
updates the example files to reflect this change and also updates the
`series` constructor to accept a lookback parameter.

The `PipelineNode` was an artifact of a previous implementation and is
no longer needed. The `StreamNode` is the appropriate type for
representing the output of a pipe operation.

The `series` function now requires a `lookback` argument to specify the
maximum number of items to store. This makes the behavior of series more
explicit and prevents accidental unbounded memory growth.
2026-03-07 23:48:09 +01:00

22 lines
555 B
Plaintext

#use rtl
(do
(def src (create-random-ohlc 42 20000))
(macro printx [s] `(fn [x] (print ~s x)))
; (pipe src print)
; (pipe [(pipe [(.close src)] (SMA 20))] (printx "sma20="))
; (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))
; (def bars (series 20 :float))
; (pipe [src] (fn [s] (do (push bars (.close s)))))
(cache 20 :float src)
)