We have the common use-case that we want to use double-colon keywords for
well known namespaces, without actually requiring the namespaces.
(defmacro ns-alias
"Set up a custom alias for use with namespace keywords."
[ns as]
`(do
(create-ns '~ns)
(alias '~as '~ns)))
This proved useful to prevent cyclic requires while still being able to use
the shorthand syntax for long and common namespaces.
Cheers,
Dieter
On Wednesday, 30 January 2019 11:53:15 UTC+1, Thomas Heller wrote:
>
> To expand on what Alex already mentioned. There is no such thing as
> double-colon keywords. Double-colon is a reader alias mechanism that let
> the reader resolve them so you can type less.
>
> (ns foo.bar.xyz)
>
> ::hello
>
> this is resolved at read-time and identical to actually writing
>
> :foo.bar.xyz/hello
>
> :: without a slash will use the current namespace as the namespace for
> the keyword.
>
> If you have a require for another namespace and use :: with a slash you
> can use it to resolve your require alias.
>
> (ns some.thing
> (:require [foo.bar.xyz :as x]))
>
> ::x/hello
>
> again becomes
>
> :foo.bar.xyz/hello
>
> in your actual program. Nothing :: will ever exist at runtime.
>
> So if you want you can always use the fully qualified keyword directly or
> you can let the require resolve them based on your ns require's. That means
> you'll get an error if there is no alias to resolve
>
> (ns user2)
>
> ::user1/foo
>
> This is invalid because user2 does not have an alias to user1, instead it
> is an actual full namespace.
>
> :user1/foo
>
> would be fine in this case (and identical to ::foo in user1). Or
>
> (ns user2
> (:require [user1 :as u1]))
>
> ::u1/foo
>
> Hope that makes things clearer.
>
> Cheers,
> Thomas
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/clojure/cd2b56d9-8bab-45c6-8e7a-42636a6dcef6%40googlegroups.com.