22 lines
770 B
Plaintext
22 lines
770 B
Plaintext
;;;; Value semantics, spec-memory.md. Not covered by calc-me, and the property
|
|
;;;; most likely to be silently wrong in a backend: a struct or a fixed array
|
|
;;;; copies on assignment, a slice copies only its view.
|
|
(defstruct P [x i32])
|
|
(defvar arr [3 i32])
|
|
|
|
(defn main [] i32
|
|
(let [a (P {:x 1})]
|
|
(let [b a] ; a copy, not an alias
|
|
(set (.x a) 99)
|
|
(print-i64 (i64 (.x b))) (newline))) ; 1
|
|
|
|
(set (at arr 0) 5)
|
|
(let [c arr] ; fixed arrays are values too
|
|
(set (at arr 0) 77)
|
|
(print-i64 (i64 (at c 0))) (newline)) ; 5
|
|
|
|
(let [s (bytes "hello")]
|
|
(let [v (slice s 1 3)] ; a view into the same bytes
|
|
(print-bytes v) (newline))) ; el
|
|
0)
|