13dc6beb52
The tail call resolution logic was duplicated in `Environment::call` and `VM::run`. This commit extracts the tail call resolution logic into a single method `VM::resolve_tail_calls` and uses it in both places. Additionally, this commit adds support for series indexing as a form of tail call, allowing for direct access to series elements through the `series(index)` syntax. This is useful for back-referencing in time-series data. A new example `err.myc` is added to demonstrate basic series usage and error handling.
25 lines
413 B
Plaintext
25 lines
413 B
Plaintext
(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)
|
|
(history 0)
|
|
))
|
|
)))
|
|
|
|
(def sma20 (SMA 20))
|
|
|
|
(def n 100)
|
|
(while (> n 0)
|
|
(do
|
|
(print "val=" n " sma20=" (sma20 n))
|
|
(assign n (- n 1))
|
|
))
|
|
) |