# Utility Utility functions are the small grab-bag that does not fit elsewhere: identity, explicit and partial application, runtime evaluation, module reloading, and pretty-printing. All are bare top-level stdlib functions, available in every host without an import. `pretty` and `pretty-str` are the debugging workhorses also used throughout Collections; `apply` and `curry` extend the callable machinery from Functions, and `eval` pairs with Macros for runtime code. ## Functions | Function | Purpose | |---|---| | `identity x` | Returns `x` unchanged | | `apply f args...` | Call `f` with explicit arguments (not a list) | | `curry f args...` | Partial application — returns a closure awaiting the rest | | `eval code-string` | Evaluate a string of Deft source | | `reload "path"` | Reload a module (or the current namespace's source with no argument) | | `pretty x indent?` | Pretty-print a value to stderr | | `pretty-str x indent?` | Return the pretty-printed string | Notes: - `apply` takes explicit arguments, not a list: `[apply $add 4 5]`. `f` may be a direct callable (closure, native function, keyword, map, vector, set) or a string/keyword name resolved through the namespace chain, so `[apply "upper" "hello"]` works. Keywords and maps act as accessors: `[apply :name %{ :name "Alice" }]` returns `"Alice"`. - `curry` fixes the leading arguments and returns a closure for the rest; `f` is resolved at call time, so redefinitions take effect. `[curry str "Hello, "]` builds a reusable prefixer. - `eval` returns the value of the final expression, or `nil` for empty source. - `reload` without arguments re-evaluates the file that defined the current namespace; with a path it evaluates that file in the current namespace. Existing Var cells update in place, so `refer :all` references elsewhere see the new values immediately. Returns `true` on success, `nil` if there is no source path or the file cannot be read. - `pretty` writes the rendered value to stderr and returns `nil`; `pretty-str` returns the string instead. Both default to a 2-space indent; short collections stay on one line, nested ones expand. ## Examples
# identity — pass-through, useful as a default argument
[identity 42]                                  # => 42

# apply — explicit args; callables or resolved names
def add {|a b| ($a + $b)}
[apply $add 4 5]                               # => 9
[apply "upper" "hello"]                        # => "HELLO"
[apply :name %{ :name "Alice" }]               # => "Alice"

# curry — fix leading args, get a closure for the rest
def add5 [curry $add 5]
[add5 10]                                      # => 15
def greet [curry str "Hello, "]
[greet "World"]                                # => "Hello, World"

# eval — run source at runtime
[eval "(1 + 2)"]                               # => 3
[eval "[str \"hi\" \"there\"]"]                # => "hithere"

# pretty vs pretty-str
[pretty %{ :a 1 :b @{ "x" "y" } }]             # rendered to stderr
set text [pretty-str %{ :a 1 } 4]              # string, 4-space indent

# reload — pick up edits without a restart
reload                                         # current namespace's file
[reload "apps/ants/ants.dft"]                  # a specific file
## See Also - Functions — closures, callables, and arity - Macros — code as data, paired with `eval` - Introspection — `info/*` and `deft/*` runtime reflection