Skip to content

Commit

Permalink
Merge pull request #662 from eval/eval-patch-1
Browse files Browse the repository at this point in the history
Document use of :as-alias
  • Loading branch information
puredanger authored Aug 3, 2023
2 parents c00a506 + 5e17cf5 commit eefd381
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion content/guides/learn/namespaces.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ The `:require` clause corresponds to the `require` function which specifies one

The last two parts are all about making names easier to use. While vars can always be referred to by their fully-qualified name, we rarely want to type fully-qualified names in our code. Aliases let us use shorter versions of longer fully-qualified aliases. Refer allows us to use names without a namespace qualifier at all.

In require, namespaces most commonly take one of three forms:
In require, namespaces most commonly take one of four forms:

* `clojure.set` - just loads `clojure.set` namespace (if not already loaded)
* `[clojure.set :as set]` - load and create an alias `set` for the namespace `clojure.set`
** This allows you to refer to vars in `set` with for example `set/union` instead of `clojure.set/union`
* `[clojure.set :refer [union intersection]]` - load and refer specific vars into this namespace
** This allows you to use just `union` instead of `clojure.set/union`
* `[company.application.component.user :as-alias user]` - create an alias `user` for the namespace `company.application.component.user` without loading it
** Typically, when using `:as-alias`, the namespace is not a loadable namespace
** This allows you to use a shorthand for a namespace qualifier, e.g. when creating entity maps: `{::user/id 1}`, registering specs: `(s/def ::user/id int?)` or when destructing: `(defn find-by-id [{::user/keys [id]}] ,,,)`

=== Java classes and imports

Expand Down

0 comments on commit eefd381

Please sign in to comment.