16af3ae9fc
This commit updates all example files to use `assert_eq!` for verifying output, replacing the previous `Output:` comments. This change makes the examples more robust and self-testing. The benchmark results in some examples have also been slightly adjusted, reflecting minor performance variations after the refactoring. Additionally, a runtime panic handling mechanism has been introduced in the VM for function calls, which improves error reporting for unexpected panics.
21 lines
568 B
Plaintext
21 lines
568 B
Plaintext
;; Benchmark: 776ns
|
|
;; Benchmark-Repeat: 2744
|
|
;; Comprehensive Destructuring Test
|
|
;; Covers: Nested tuples, mixed params, dynamic passing
|
|
|
|
(do
|
|
;; 1. Deeply nested
|
|
(def deep (fn [[a [[b c] d]]] (+ a (+ b (+ c d)))))
|
|
|
|
;; 2. Mixed: Tuple and Single
|
|
(def mixed (fn [[x y] z] (+ (+ x y) z)))
|
|
|
|
;; 3. Dynamic: Passing a list variable
|
|
(def call-dynamic (fn [f data] (f data)))
|
|
|
|
(def data [10 [20 30]])
|
|
|
|
(assert-eq 10 (deep [1 [[2 3] 4]]))
|
|
(assert-eq 6 (mixed [1 2] 3))
|
|
(assert-eq 60 (call-dynamic (fn [[a [b c]]] (+ a (+ b c))) data)))
|