tur/typeclass-show
the Show typeclass (owned String result) and its primitive + typed-collection instances.
Show renders a value as an OWNED String (refcount 1): (show x) returns a fresh String the caller string/releases, so a generic caller has a single uniformly-safe ownership policy (release) -- no leak, no borrow/malloc guessing. This is the owned surface the show-owned-result-plan builds; the earlier cstr-returning Show was retired at stage 4.
Because it returns String, Show sits ABOVE stdlib/string.tur in the load graph and loads it here. It is pulled in by stdlib/typeclass.tur (so (load "stdlib/typeclass.tur") still provides Show + the collection instances) and preloaded by the REPL (src/turi/preload.c).
Since: v2 (show-owned-result-plan, stage 4)
Show
(defclass Show [a])
values that render themselves as an owned String.
| a | the type to render |
(show [x] :String)-
a fresh owned String (refcount 1) rendering
x--[1 2 3]for a Vec,#\Afor a Char. The callerstring/releases it.
(let [s (show 42)] (println (string/to-cstr s)) (string/release s)) ; prints 42
For human-facing text without the ownership step, see Display (cstr) in stdlib/typeclass.tur.
Complex, Datum, Bound, Rational, StringSlice, int, cstr, bool, int8, int16, int32, uint8, uint16, uint32, uint64, float, float32, String, ptr<void>, Vec, Set, Map, Char, Sym
Since: Phase 15 (owned since stage 4)
Show[int]
(definstance Show [int])
owned decimal String.
Show[cstr]
(definstance Show [cstr])
copy the borrowed cstr into a fresh owned String.
Show[bool]
(definstance Show [bool])
owned "true" / "false" String.
Show[int8]
(definstance Show [int8])
owned decimal String.
Show[int16]
(definstance Show [int16])
owned decimal String.
Show[int32]
(definstance Show [int32])
owned decimal String.
Show[uint8]
(definstance Show [uint8])
owned decimal String.
Show[uint16]
(definstance Show [uint16])
owned decimal String.
Show[uint32]
(definstance Show [uint32])
owned decimal String.
Show[uint64]
(definstance Show [uint64])
owned decimal String.
Show[float]
(definstance Show [float])
owned String rendering of a double.
Show[float32]
(definstance Show [float32])
owned String rendering of a float32.
Show[String]
(definstance Show [String])
O(1) retain (refcount++), a second owning handle.
Show[ptr<void>]
(definstance Show [ptr<void>])
render a result<T,E> carrier as an owned String.
vec-show-loop
(vec-show-loop [^Show A])
push "e0 e1 ..." element reprs into the builder.
Show[Vec]
(definstance Show [Vec])
render a Vec[A] as an owned "[a b c]" String.
(show (vec-of 1 2 3)) ; => String "[1 2 3]"
set-show-loop
(set-show-loop [^Show A])
push the space-separated element reprs into b.
Show[Set]
(definstance Show [Set])
render a Set[A] as an owned "#set{a b c}" String.
(show (set-of 1 2 3)) ; => String "#set{1 2 3}"
map-show-loop
(map-show-loop [^Show K ^Show V])
push the space-separated "k v" reprs into b.
Show[Map]
(definstance Show [Map])
render a Map[K V] as an owned "#map{k1 v1 k2 v2}" String.
(show (hamt-of 1 10 2 20)) ; => String "#map{1 10 2 20}"
show-char-name__
(show-char-name__ [n :int] :cstr)
internal: the reader's name for code n ("" if none).
show-char-named?__
(show-char-named?__ [n :int] :bool)
internal: does the reader have a name for code n?
show-hex-digit__
(show-hex-digit__ [d :int] :Char)
internal: the lower-case hex digit for 0..15.
Show[Char]
(definstance Show [Char])
render a character as its literal: #\A, #\space.
(show #\A) ; => String "#\A" (show #\space) ; => String "#\space"
Show[Sym]
(definstance Show [Sym])
render an interned symbol as an owned ":name" String.
(show :hello) ; => String ":hello"
show-string-fputs
(show-string-fputs [s :cstr])
internal: write a cstr to stdout with no newline.
print-show
(print-show [^Show a])
render x via Show and print it (no trailing newline).
Shows x to an owned String, prints its bytes, and releases the String.
(print-show 42) ; prints: 42
Since: v2 (show-owned-result-plan)
show-line
(show-line [^Show a])
render x via Show and print it with a trailing newline.
Shows x to an owned String, prints its bytes plus a newline, releases it.
(show-line 42) ; prints: 42\n
Since: v2 (show-owned-result-plan)