20 lines
541 B
Plaintext
20 lines
541 B
Plaintext
;; One generic function over one type variable, called at two concrete types
|
|
;; in one program. The sigil binds ($t), a bare use reads it (t).
|
|
|
|
(defn swap! [xs [$t] i i32 j i32] ()
|
|
(let [tmp (at xs i)]
|
|
(set (at xs i) (at xs j))
|
|
(set (at xs j) tmp)))
|
|
|
|
(defn main [] ()
|
|
(let [ns [10 20 30]
|
|
fs [1.5 2.5 3.5]]
|
|
(swap! (slice ns 0 3) 0 2)
|
|
(swap! (slice fs 0 3) 0 1)
|
|
(swap! (slice ns 0 3) 1 2)
|
|
(println (at ns 0))
|
|
(println (at ns 1))
|
|
(println (at ns 2))
|
|
(println (at fs 0))
|
|
(println (at fs 1))))
|