flan/test/programs/dyn-fields.flan

37 lines
1.0 KiB
Plaintext

;;;; A dyn value's (.field x) and (at m :key): a read is get, a set is put.
(defclass State [paused bool step bool])
(defclass Pos [x y])
(defclass Body [pos count items])
(defonce state (State false false))
(defn game-input [] ()
(when true
(set (.paused state) (not (.paused state)))))
(defn pick [b dyn] dyn b)
(defn main [] i32
(game-input)
(println (.paused state))
(game-input)
(println (.paused state))
(let [b (Body (Pos 1 2) 0 [10 20 30])]
(set (.count b) (+ (.count b) 1))
(++ (.count b))
(update (.count (pick b)) + 10)
(set (.x (.pos b)) 7)
(update (.y (.pos b)) * 10)
(set (at (.items b) 0) 11)
(update (at (.items b) 1) + 5)
(println (.count b) (.x (.pos b)) (.y (.pos b)) (at (.items b) 0) (at (.items b) 1))
(println (.missing b) (= (.missing b) (get b :missing))))
(let [m {:hp 3}]
(set (.hp m) (- (.hp m) 1))
(set (at m :mp) 9)
(update (at m :mp) + 1)
(set (.name m) "slime")
(set (at m 1) :one)
(println (at m :hp) (.mp m) (at m :gone) (at m 1) m))
0)