47 lines
1.3 KiB
Plaintext
47 lines
1.3 KiB
Plaintext
;;;; Dyn chars: a char literal that ends up dyn is a char and prints as its
|
|
;;;; literal; a dyn text counts characters, not bytes; chars and text convert
|
|
;;;; between a text and a vec of chars. With an argument, a dyn int handed to an
|
|
;;;; i32 — a code point — traps at the call.
|
|
|
|
(defn show [x] () (println x))
|
|
(defn code-point [c i32] i32 c)
|
|
|
|
(defn main [args [str]] i32
|
|
(let [t (the dyn "é日😀 ok")
|
|
cs (chars t)]
|
|
;; literals, printed
|
|
(show \I)
|
|
(show \é)
|
|
(show \日)
|
|
(show \😀)
|
|
(show [\a \space \( \newline])
|
|
(show (type-of \é))
|
|
;; length and indexing count characters
|
|
(show (length t))
|
|
(show (at t 0))
|
|
(show (at t 1))
|
|
(show (at t 2))
|
|
(show (at t 4))
|
|
(show (slice t 1 3))
|
|
;; chars and text
|
|
(show cs)
|
|
(show (length cs))
|
|
(show (text cs))
|
|
(show (= (text cs) t))
|
|
(show (text \日))
|
|
(show (text [\o \k]))
|
|
;; equality, ordering, and a char as a map key
|
|
(show (= (at t 1) \日))
|
|
(show (= (at t 0) \e))
|
|
(show (= (at t 4) (the dyn "o")))
|
|
(show (= (at t 4) (the dyn 111)))
|
|
(show (< (at t 0) (at t 1)))
|
|
(show (> (at t 1) (at t 2)))
|
|
(show (< (at t 4) \é))
|
|
(show (get {\é 1 \日 2} (at t 1)))
|
|
;; into typed code: the code point
|
|
(show (code-point (at t 2)))
|
|
(when (> (length args) 1)
|
|
(show (code-point (the dyn 5)))))
|
|
0)
|