Skip to content

Commit 48d7301

Browse files
authored
Made some updates to the anonymous function section
1 parent d127e12 commit 48d7301

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

content/guides/weird_characters.adoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,19 @@ Note that while `#inst` and `#uuid` are available in edn, `#js` is not.
226226

227227
== `%`, `%n`, `%&` - Anonymous function arguments
228228

229-
`%` is an argument in an anonymous function `#(...)`. It represents
230-
an argument that will be passed into the function when it is expanded.
229+
`%` is an argument in an anonymous function `#(...)` as in `#(* % %)`.
230+
231+
When an anonymous function is expanded, it becomes an `fn` form and `%` args are replaced with gensym'ed names
232+
(here we use arg1, etc for readability):
233+
231234
[source,clojure]
232235
----
233236
user=> (macroexpand `#(println %))
234-
(fn* [arg] (clojure.core/println arg)) ; takes a single arg, uses it once
235-
236-
user=> (macroexpand `#(println % %))
237-
(fn* [arg] (clojure.core/println arg arg)) ; takes a single arg, uses it twice
237+
(fn* [arg1] (clojure.core/println arg1))
238238
----
239-
Numbers can be placed directly after the `%` to indicate the arguments position,
240-
note that these numbers are 1-based integers.
241-
Anonymous functions defined by `#(...)` use the highest numbered `%` argument to determine the arity of the anonymous function.
239+
240+
Numbers can be placed directly after the `%` to indicate the argument positions (1-based).
241+
Anonymous function arity is determined based on the highest number `%` argument.
242242

243243
[source,clojure]
244244
----

0 commit comments

Comments
 (0)