Files
RustAst/examples/pipeline_script_ticker.myc
Michael Schimmel beb693a068 Refactor: Implement block scoping and statement separation
This commit introduces fundamental changes to Myc's language structure
to enhance type safety and scoping clarity.

Key changes include:
- Introducing local scopes for `do` blocks.
- Separating statements (`def`, `assign`) from expressions, where
  statements now have no return value and are only allowed within
  blocks.
- A block now consists of multiple statements followed by a single final
  expression.
- Stricter validation rules are enforced, such as disallowing
  redefinition of local symbols in the same scope while allowing
  shadowing of outer symbols.
- Compiler errors are generated for statements used in expression
  contexts.

The implementation involved modifications to the AST, parser, binder
(scope-stack), and various compiler passes, along with VM runtime
optimizations.
2026-03-09 16:38:44 +01:00

49 lines
1.1 KiB
Plaintext

;; Benchmark: 2.3us
;; Benchmark-Repeat: 870
;; Output: <StreamNode>
(do
;; Set the random seed to match the existing test output exactly
(def random (make-random 42))
;; Use our new generic create-ticker to pulse 3 times
(def cnt 3)
(def ticker (create-ticker (fn [] (do (assign cnt (- cnt 1)) (> cnt -1)))))
;; The candle generator reacting to the ticker
(def last-close 100.0)
(def src1
(pipe [ticker]
(fn [_]
(do
(def change (* (- (random) 0.5) 2.0)) ; Matches Rust: (rng.f64() - 0.5) * 2.0
(def open last-close)
(def high (+ open (abs (* (random) 2.0))))
(def low (- open (abs (* (random) 2.0))))
(assign last-close (+ open change))
{:open open :high high :low low :close last-close}
)
)
)
)
(def combined
(pipe [src1]
(fn [t1]
(.close t1)
)
)
)
(def my_indicator
(pipe [combined]
(fn [close_price]
(+ close_price 10.0)
)
)
)
my_indicator
)