Skip to content

Commit f5a9a5a

Browse files
committed
cross reference and speling
1 parent b8f235b commit f5a9a5a

2 files changed

Lines changed: 56 additions & 44 deletions

File tree

content/guides/weird_characters.adoc

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ where necessary. Sections are not in any particular order, but related items
1616
are grouped for ease. This guide is a copy of http://twitter.com/kouphax[James Hughes]
1717
brilliant https://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/[blog post] of the same name.
1818
====
19-
19+
[[dispatch]]
2020
== # - Dispatch macro
2121

2222
You'll see this macro character beside another e.g. `\#(` or `#"`.
2323
// " Comment needed for emacs to behave.
2424
This topic will act as a bit of a preamble before looking at your specific case.
2525

26-
`#` is the dispatch macro, a reader macro that tells the Clojure
27-
reader (the thing that takes a file of Clojure code and parses it for
26+
`#` is a reader macro that tells the Clojure reader (the thing that takes a
27+
file of Clojure code and parses it for
2828
consumption by the compiler) to go and look at another *read table*
2929
for the definition of the next character - in essence this allows
3030
extending default reader behaviour.
@@ -65,19 +65,19 @@ user=> (macroexpand '(m))
6565
----
6666

6767
Another place you'll see the `#` is in
68-
http://clojure.org/reader#The%20Reader--Tagged%20Literals[tagged literals].
68+
<<xref/../../reference/reader#tagged_literals,tagged literals>>
6969
Most commonly you'll see this use in https://github.com/edn-format/edn[EDN]
7070
(extensible data notation - a rich data fromat that can be used in Clojure)
7171
and in ClojureScript (`#js`). Search for `#inst`, `#uuid`, or `#js` for some
7272
more info.
7373

74-
* http://clojure.org/reader[Clojure Documentation Reader]
74+
* <<xref/../../reference/reader#tagged_literals,Clojure Documentation Reader>>
7575
* http://briancarper.net/blog/449/[Clojure Reader Macros]
7676
* http://clojuredocs.org/clojure_core/clojure.core/gensym[ClojureDocs - gensyms]
7777

7878
== #{ - Set macro
7979

80-
See the dispatch (`\#`) macro for additional details.
80+
See <<xref/../weird_characters#dispatch,(`#`)>> for additional details.
8181

8282
`#{` defines a set (a collection of unique values) specifically a `hash-set`. The
8383
following are equivalent:
@@ -102,11 +102,11 @@ user=> (set [1 2 3 4 1]) ; convert vector to set, removing duplicates
102102
#{1 2 3 4}
103103
----
104104

105-
* http://clojure.org/data_structures#Data%20Structures-Sets[Clojure Documentation: Sets]
105+
* <<xref/../../reference/data_structures#sets,Clojure Documentation: Sets>>
106106

107107
== #_ - Discard macro
108108

109-
See the dispatch (`#`) macro for additional details.
109+
See <<xref/../weird_characters#dispatch,(`#`)>> for additional details.
110110

111111
`#_` tells the reader to ignore the next form completely.
112112

@@ -119,12 +119,12 @@ The docs suggest that "The form following `#_` is completely skipped by the read
119119
(This is a more complete removal than the `comments` macro which yields `nil`).".
120120
This can prove useful for debugging situations or for multiline comments.
121121

122-
* http://clojure.org/reader[Clojure Documentation - Reader
122+
* <<xref/../../reference/reader#,Clojure Documentation - Reader>>
123123

124124
== #" - Regular Expression macro
125125
// " for the pleasure of emacs.
126126

127-
See the dispatch (`#`) macro for additional details.
127+
See <<xref/../weird_characters#dispatch,(`#`)>> for additional details.
128128

129129
`#"` indicates the start of a regular expression
130130
// "
@@ -136,11 +136,11 @@ user=> (re-matches #"^test$" "test")
136136

137137
This form is compiled at *read time* into a host-specific regex machinery.
138138

139-
* http://clojure.org/other_functions#Other%20Useful%20Functions%20and%20Macros-Regex%20Support[Clojure Documentation: Regex Support]
139+
* <<xref/../../reference/other_functions#regex,Clojure Documentation: Regex Support>>
140140

141141
== #( - Function macro
142142

143-
See the dispatch (`#`) macro for additional details.
143+
See <<xref/../weird_characters#dispatch,(`#`)>> for additional details.
144144

145145
`#(` begins the short hand syntax for an inline function definition. The
146146
following two snippets of code are similar:
@@ -183,7 +183,7 @@ When used it will attempt to return the referenced var. This is useful when
183183
you want to talk ab out the reference/declaration instead of teh value it represents.
184184
See the use of `meta` int the metadata (`^`) discussion.
185185

186-
* http://clojure.org/special_forms#var[Clojure Official Documentation: Special Forms]
186+
* <<xref/../../reference/special_forms#var,Clojure Official Documentation: Special Forms>>
187187

188188
== #inst, #uuid, and #js etc. - tagged literals
189189

@@ -249,11 +249,12 @@ you'd expect an external caller to pass them in.
249249
user=> (macroexpand `#(println % %1)) ; use both % and %1
250250
(fn* [arg1] (clojure.core/println arg1 arg1)) ; still only takes 1 argument
251251
----
252+
There is also `%&` which is the symbol for variadic arguments
252253

253254
== @ - Deref macro
254255

255-
`@` is the deref macro, it is the shorthand equivalent of the `deref` function so
256-
these two forms are the same:
256+
`@` is the shorthand equivalent of the `deref` function so these two forms
257+
are the same:
257258
[source,clojure]
258259
----
259260
user=> (def x (atom 1))
@@ -265,7 +266,7 @@ user=> (deref x)
265266
user=>
266267
----
267268
`@` is used to get the current value of a reference. The above example uses
268-
`@` to get the current value of an http://clojure.org/atoms[atom], but `@` can
269+
`@` to get the current value of an <<xref/../../reference/atom#,atom>>, but `@` can
269270
be applied to other things such as `future` s, `delay` s, `promises` s etc. to
270271
force computation and potentially block.
271272

@@ -320,13 +321,14 @@ user=> (meta #'five)
320321
{:ns #<Namespace user>, :name five, :column 1, :private true, :debug true, :line 1, :file "NO_SOURCE_PATH", :tag java.lang.Integer}
321322
----
322323

323-
* http://clojure.org/metadata[Clojure Official Documentation: Metadata]
324+
* <<xref/../../reference/metadata#,Clojure Official Documentation>>
324325
* http://en.wikibooks.org/wiki/Learning_Clojure/Meta_Data[Learning Clojure: Meta Data]
325326

326327
== ' - Quote macro
327328

328-
Can be used against symbols as part of a dispatch macro (see `#'`). Also
329-
used to quote forms and prevent their evalutation as with the quote function.
329+
Can be used against symbols as part of a dispatch macro
330+
(see <<xref/../weird_characters#dispatch,`#`>>). Also used to quote forms
331+
and prevent their evalutation as with the quote function.
330332
[source,clojure]
331333
----
332334
user=> (1 3 4) ; fails as it tries to evaluate 1 as a function
@@ -339,7 +341,7 @@ user=> (quote (1 2 3)) ; using the longer quote method
339341
user=>
340342
----
341343

342-
* http://clojure.org/special_forms#quote[Clojure Official Documentation]
344+
* <<xref/../../reference/special_forms#quote,Clojure Official Documentation>>
343345

344346
== ; - Comment
345347

@@ -383,11 +385,12 @@ user=> (:three my-map 3) ; it can return a default if specified
383385
3
384386
----
385387

386-
* http://clojure.org/data_structures#Data%20Structures-Keywords[Clojure Official Documentation]
388+
* <<xref/../../reference/data_structures#Keywords,Clojure Official Documentation>>
387389

388-
== :: - Qualified keyword
390+
[[autoresolved_keys]]
391+
== +::+ - Autoresolved keyword
389392

390-
`::` is used to fully qualify a keyword with the current namespace:
393+
`::` is used to autoresolve a keyword to the current namespace:
391394
[source,clojure]
392395
----
393396
user=> :my-keyword
@@ -401,14 +404,16 @@ This is useful when creating macros. If you want to ensure a macro, that calls
401404
another function in the macro namespace, correctly expands to call the function,
402405
you could use `::my-function` to refer to the fully qualified name.
403406

407+
* <<xref/../../reference/reader#,Reader>>
408+
404409
== / - Namespace separator
405410

406411
`/` can be the division function `/`, but can also act as a separator in a
407412
symbol name to break apart the symbol name and the namespace it resides in, eg
408413
`my-namespace/utils`. this allows symbols to be fully qualified to prevent
409414
collitsions or spread.
410415

411-
* http://clojure.org/reader[Clojure Official Documentation]
416+
* <<xref/../../reference/reader#,Reader>>
412417

413418
== $ - Inner class reference
414419

@@ -428,8 +433,9 @@ container class name and the inner class name.
428433
imported Java class
429434

430435
* http://blog.jayfields.com/2011/01/clojure-using-java-inner-classes.html[Clojure: Using Java Inner Classes]
436+
* <<xref/../../reference/java_interop#,Official Documentation>>
431437

432-
== -> ->> some-> cond-> as-> etc. - Threading macros
438+
== ->, +->>+ some-> cond-> as-> etc. - Threading macros
433439

434440
These are threading macros. Almost all of them take an initial value and
435441
*tread* this value through a number of forms. Let's imagine (for reasons unknown)
@@ -459,22 +465,23 @@ Or if you prefer multiline and consistent brackettering
459465
What the macro does is take the value returned from each expression and push
460466
it in as the first argument to the next one.
461467

462-
`->>` (thread last) is the same, but different. Rather than push the last value
468+
+->>+ (thread last) is the same, but different. Rather than push the last value
463469
in as the *first* argument, it passes it in as the *last* argument.
464470

465471
The "etc." in the title refers to the fact that there are a whole host of
466472
threading macros that perform variations on the same theme (`cond->`, `some->`,
467-
`as->` and their `->>` equivalents). There is also an entire libary,
473+
`as->` and their +->>+ equivalents). There is also an entire libary,
468474
https://github.com/rplevy/swiss-arrows[swiss arrows], dedicated to the threading
469475
macros.
470476

471-
* http://blog.fogus.me/2009/09/04/understanding-the-clojure-macro/[Understanding the Clojure -> macro
477+
* http://blog.fogus.me/2009/09/04/understanding-the-clojure-macro/[Understanding the Clojure +->+ macro]
472478

479+
[[unqote]]
473480
== ~ - Unquote macro
474481

475-
See ``` (syntax quote) for additional information.
482+
See <<xref/../weird_characters#syntax_quote,```>> for additional information.
476483

477-
`~` is unquote. That is within a syntax quoted (```) block `~` will *unquote*
484+
`~` is unquote. That is within a syntax quoted (<<xref/../weird_characters#syntax_quote,```>>) block `~` will *unquote*
478485
the associated symbol, i.e. resolve it in the current context:
479486
[source,clojure]
480487
----
@@ -493,16 +500,17 @@ various contexts
493500

494501
* http://www.braveclojure.com/writing-macros/[Clojure for the Brave and True - Writing Macros]
495502
* http://aphyr.com/posts/305-clojure-from-the-ground-up-macros[Clojure from the ground up: macros]
496-
* http://clojure.org/macros[Clojure Official Documentation]
503+
* <<xref/../../macros#,Clojure Official Documentation>>
497504

505+
[[unquote_splicing]]
498506
== ~@ - Unquote splicing macro
499507

500-
See ``` (syntax quote) and `~` (unquote) for additional information.
508+
See <<xref/../weird_characters#syntax_quote,(```)>> and <<xref/../weird_characters#unquote,(`~`)>> for additional information.
501509

502-
`~@` is unquote-splicing. Where unquote (`~`) deals with single values (or
503-
treats its attached item as a single item), `~@` works on lists and expands
504-
them out into multiple statements. Think of `apply` which takes a seq and expands
505-
it out as arguments to the applied function.
510+
`~@` is unquote-splicing. Where unquote <<xref/../weird_characters#unquote,(`~`)>>
511+
deals with single values (or treats its attached item as a single item), `~@`
512+
works on lists and expands them out into multiple statements. Think of `apply`
513+
which takes a seq and expands it out as arguments to the applied function.
506514
[source,clojure]
507515
----
508516
user=> (def three-and-four (list 3 4))
@@ -516,11 +524,12 @@ Again, this gives us a lot of power in macros.
516524

517525
* http://www.braveclojure.com/writing-macros/[Clojure for the Brave and True - Writing Macros]
518526
* http://aphyr.com/posts/305-clojure-from-the-ground-up-macros[Clojure from the ground up: macros]
519-
* http://clojure.org/macros[Clojure Official Documentation]
527+
* <<xref/../../macros#,Clojure Official Documentation>>
520528

529+
[[syntax_quote]]
521530
== ` - Syntax quote
522531

523-
See `~@` (unquote splicing) and `~` (unquote) for additional information
532+
See <<xref/../weird_characters#unquote_splicing,`~@`>> and <<xref/../weird_characters#unquote,(`~`)>> for additional information
524533
````` is the syntax quote. When used on a symbol it resolves to the symbol
525534
in the current context:
526535
[source,clojure]
@@ -559,7 +568,7 @@ are writing with it. The ``` allows this to happen.
559568

560569
* http://www.braveclojure.com/writing-macros/[Clojure for the Brave and True - Writing Macros]
561570
* http://aphyr.com/posts/305-clojure-from-the-ground-up-macros[Clojure from the ground up: macros]
562-
* http://clojure.org/macros[Clojure Official Documentation]
571+
* <<xref/../../macros#,Clojure Official Documentation>>
563572

564573
== \*var-name* - Earmuffs
565574

@@ -615,6 +624,7 @@ asynchronous code from the code base.
615624

616625
* https://github.com/clojure/core.async/blob/master/examples/walkthrough.clj[core.async Code Walkthrough]
617626
* https://github.com/clojure/core.async/wiki[core.async Wiki]
627+
* <<xref/../core_async_go#,Go Block Best Practices>>
618628

619629
== <symbol>? - Predicate Marker
620630

@@ -649,7 +659,7 @@ The Clojure style guide has this to say
649659
[]
650660
====
651661
The names of functions/macros that are not safe in STM transactions
652-
should end with an excalamation mark (e.g `reset!`).
662+
should end with an exclamation mark (e.g `reset!`).
653663
====
654664
You'll most commonly see this appended to function names whose purpose
655665
is to mutate state, e.g. connecting to a data store, updating an atom or
@@ -749,14 +759,14 @@ is read as:
749759
:ship/model "YT-1300f light freighter"}}
750760
----
751761

752-
* <<xref/../../reference/reader#,Reader>>
762+
* <<xref/../../reference/reader#map_namespace_syntax,Reader>>
753763

754-
== Auto Resolving Namespace Syntax
764+
== +#::+ Autoresolving Namespace Syntax
755765

756766
`#::` can be used to auto-resolve namespaces with the same semantics as
757-
auto-resolved keywords.
767+
<<xref/../weird_characters#autoresolved_keys,autoresolved keywords.>>.
758768

759-
* <<xref/../../reference/reader#,Reader>>
769+
* <<xref/../../reference/reader#map_namespace_syntax,Reader>>
760770

761771
== #= Reader eval
762772

content/reference/reader.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Vectors are zero or more forms enclosed in square brackets: `[1 2 3]`
6060
* Commas are considered whitespace, and can be used to organize the pairs: `{:a 1, :b 2}`
6161
* Keys and values can be any forms.
6262

63+
[[map_namespace_syntax]]
6364
==== Map namespace syntax
6465

6566
_Added in Clojure 1.9_
@@ -189,6 +190,7 @@ The read table is currently not accessible to user programs.
189190
== extensible data notation (edn)
190191
Clojure's reader supports a superset of https://github.com/edn-format/edn[extensible data notation (edn)]. The edn specification is under active development, and complements this document by defining a subset of Clojure data syntax in a language-neutral way.
191192

193+
[[tagged_literals]]
192194
== Tagged Literals
193195
Tagged literals are Clojure's implementation of edn https://github.com/edn-format/edn#tagged-elements[tagged elements].
194196

0 commit comments

Comments
 (0)