# Types The type, predicate, coercion, and metadata verbs are bare stdlib functions present in every runtime. `type` reports a value's type name and `is?` checks it; the predicates answer the common questions (`nil?`, `empty?`, `future?`). Coercion (`num`, `keyword`) and metadata access (`meta`, `with-meta`, `vary-meta`, `without-meta`) round out the group. For the type system itself — user-defined types and protocols — see [Types and Protocols](../01-Language/types-and-protocols). ## Functions | Function | Purpose | |---|---| | `type x` | Type name as a string (`"number"`, `"string"`, `"map"`, user types) | | `is? type-name x` | Type check by name — the type first, then the value | | `nil? x` | Nil check | | `future? x` | Future (async task) check | | `empty? xs` | Empty check for strings and collections | | `num x` | Coerce to number (string, bool, or number); nil when a string cannot be parsed | | `keyword x` | Coerce a string to a keyword | | `meta value ?key` | Read the metadata map, or a single key's value | | `with-meta value meta` | Attach metadata (a map replaces, key/value pairs merge, nil clears) | | `vary-meta value f` | Apply `f` to the current metadata map and attach the result | | `without-meta value` | Strip metadata, sharing the payload | ### Notes - `is?` takes the type name first, then the value: `[is? "number" 42]`. The name may also be a user-defined type value (`[is? Point $p]`). - `type` returns `"number"` for both integers and floats — Deft numbers are all f64 under the hood — and the user type name for typed values. - Metadata-capable values are maps, tagged maps, vectors, sets, strings, and keywords. Immediate values (numbers, nil, booleans) are returned unchanged by the metadata helpers. `with-meta` returns a new value sharing the payload, `meta` on a plain value yields nil, and `vary-meta` is the threading form (`[with-meta $value [$f [meta $value]]]`). - `num` parses `"3.14"` and `"42"`, maps `true`/`false` to `1`/`0`, and yields nil when parsing fails. `int` (see Math) additionally truncates floats. ## Examples
echo [type 42]                       # "number"
echo [type "hi"]                     # "string"
echo [type %{ a 1 }]                 # "map"
echo [is? "number" 42]               # true
echo [is? "string" 42]               # false
echo [nil? nil]                      # true
echo [empty? @{}]                    # true

echo [num "42"]                      # 42
echo [num "abc"]                     # nil
echo [keyword "ok"]                  # :ok

# Metadata on a function
def inc {|x| ($x + 1)}
set f [with-meta $inc %{ "doc" "adds one" }]
echo [meta $f "doc"]                 # "adds one"

# Functional metadata updates on a tagged value
def tagged [with-meta :deepseek %{ "n" 1 }]
echo [meta $tagged "n"]                                  # 1
echo [meta [vary-meta $tagged {|m| [assoc $m "n" 2]}] "n"]  # 2
echo [meta [without-meta $tagged]]                       # nil
## See Also - Types and Protocols - Results - Refs - Math