flan/web/examples/dyn.flan

14 lines
508 B
Plaintext

;; Writing dyn is how a value opts in. The parameter has no type written, so
;; it is a dyn; the return type says dyn too, and both ends of twice are then
;; a word the runtime knows the contents of and the checker does not.
(defn twice [x] dyn
(+ x x))
;; A numeric cast opens the box. (i64 d) compiles for any dyn d, and what the
;; box actually holds is answered when the program runs.
(defn main [] ()
(println (twice 21))
(println (twice 1.5))
(let [d (twice 21)]
(println (+ (i64 d) 1))))