Refactor Examples to use assert_eq
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.
This commit is contained in:
+10
-7
@@ -1,6 +1,5 @@
|
||||
;; Benchmark: 946ns
|
||||
;; Benchmark-Repeat: 2116
|
||||
;; Output: ["Alice" 101 :admin "Zürich" ["Alice" "Bob"] true]
|
||||
;; Benchmark: 1.3us
|
||||
;; Benchmark-Repeat: 1597
|
||||
|
||||
; ---------------------------------------------------------
|
||||
; Records & Optimized Field Access Showcase
|
||||
@@ -33,17 +32,21 @@
|
||||
|
||||
; 5. Higher-Order usage
|
||||
; Accessors are perfect for mapping over data.
|
||||
(def names ((fn [f list]
|
||||
(def names ((fn [f list]
|
||||
(do
|
||||
(def [e1 e2] list)
|
||||
[(f e1) (f e2)]
|
||||
))
|
||||
))
|
||||
.name (.employees company)))
|
||||
|
||||
; 6. Structural Identity
|
||||
; Records with the same layout share memory; equality checks values.
|
||||
(def is-equal (= {:x 1 :y 2} {:x 1 :y 2}))
|
||||
|
||||
; Return a summary of all tested features
|
||||
[name id role city names is-equal]
|
||||
(assert-eq "Alice" name)
|
||||
(assert-eq 101 id)
|
||||
(assert-eq :admin role)
|
||||
(assert-eq "Zürich" city)
|
||||
(assert-eq ["Alice" "Bob"] names)
|
||||
(assert is-equal)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user