Skip to content

Commit

Permalink
Explain namespaced keywords
Browse files Browse the repository at this point in the history
Paving the way for #139
  • Loading branch information
Alejandro Gómez committed Feb 19, 2017
1 parent d196d5f commit 79d610f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/language-basics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ used in <<maps-section,map data structures>> to efficiently represent the keys.
:foobar
:2
:?
:foo/bar
----

As you can see, the keywords are all prefixed with `:`, but this character is only part
Expand All @@ -108,6 +107,37 @@ or are unclear about anything in the following example; <<function-section,funct
;; => :foo
----

===== Namespaced keywods

When prefixing keywords with a double colon `::`, the keyword will be prepended by the name of the current namespace.
Note that namespacing keywords affects equality comparisons.

[source, clojure]
---
::foo
;; => :cljs.user/foo

(= ::foo :foo)
;; => false
---

Another alternative is to include the namespace in the keyword literal, this is useful when creating namespaced keywords
for other namespaces:

[source, clojure]
---
:cljs.unraveled/foo
;; => :cljs.unraveled/foo
---

The `keyword` function has an arity-2 variant where we can specify the namespace as the first parameter:

[source, clojure]
---
(keyword "cljs.unraveled" "foo")
;; => :cljs.unraveled/foo
---


==== Symbols

Expand Down

0 comments on commit 79d610f

Please sign in to comment.