(ask sym)Access a scoped value by symbol.
Returns the value bound via scoping if present, otherwise falls back
to the var's root binding. Throws if the var is unbound and not in scope.
In CLJS, returns the var's current binding value.
(def ^:dynamic *user-id* :default)
(scoping [*user-id* 123]
(ask *user-id*)) ;=> 123
(ask *user-id*) ;=> :default (falls back to var value)
Access a scoped value by symbol. Returns the value bound via `scoping` if present, otherwise falls back to the var's root binding. Throws if the var is unbound and not in scope. In CLJS, returns the var's current binding value. ```clojure (def ^:dynamic *user-id* :default) (scoping [*user-id* 123] (ask *user-id*)) ;=> 123 (ask *user-id*) ;=> :default (falls back to var value) ```
(current-scope)Returns the current scope map, or an empty map if no scope is active.
The scope map contains var->value bindings set via scoping.
CLJ only. Not available in CLJS.
Returns the current scope map, or an empty map if no scope is active. The scope map contains var->value bindings set via `scoping`. CLJ only. Not available in CLJS.
(scoping bindings & body)Execute body with additional scoped bindings. Returns the value of body.
Bindings are merged into the current scope. Use current-scope to capture
the active scope and with-scope to restore it in another context (e.g.,
a virtual thread or callback). In CLJS, falls back to binding.
(scoping [*user-id* 123
*request-id* "abc"]
(ask *user-id*)) ;=> 123
Scopes can be nested; inner bindings shadow outer ones for the same var.
Execute body with additional scoped bindings. Returns the value of body.
Bindings are merged into the current scope. Use `current-scope` to capture
the active scope and `with-scope` to restore it in another context (e.g.,
a virtual thread or callback). In CLJS, falls back to `binding`.
```clojure
(scoping [*user-id* 123
*request-id* "abc"]
(ask *user-id*)) ;=> 123
```
Scopes can be nested; inner bindings shadow outer ones for the same var.(with-scope scope & body)Execute body with a pre-built scope map. Returns the value of body.
Unlike scoping, this takes a scope map (as returned by current-scope)
rather than a bindings vector. Useful for restoring a previously captured
scope in a different execution context.
CLJ only. Not available in CLJS.
Execute body with a pre-built scope map. Returns the value of body. Unlike `scoping`, this takes a scope map (as returned by `current-scope`) rather than a bindings vector. Useful for restoring a previously captured scope in a different execution context. CLJ only. Not available in CLJS.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |