You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/reference/java_interop.adoc
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,7 @@ The unqualified "." forms expand into calls to the dot operator (described below
78
78
[[methodvalues]]
79
79
=== Method values
80
80
81
-
Since Clojure 1.12, programmers can use Java qualified methods as ordinary functions in value contexts - the compiler will automatically generate the wrapping function. When used as values, qualified methods supply only the class and method name, and thus cannot resolve overloaded methods. Therefore, the compiler will generate a reflective call when a qualified method does not resolve due to overloading. Developers can supply <<param-tags#,:param-tags metadata>> on qualified methods to specify the signature of a single desired method, 'resolving' it.
81
+
Since Clojure 1.12, programmers can use Java qualified methods as ordinary functions in value contexts - the compiler will automatically generate the wrapping function. When used as values, qualified methods supply only the class and method name, and thus cannot resolve overloaded methods. Therefore, the compiler will generate a reflective call when a qualified method does not resolve due to overloading. Developers can supply <<java_interop#paramtags,:param-tags metadata>> on qualified methods to specify the signature of a single desired method, 'resolving' it. `:param-tags` are ignored on unqualified methods like `.instanceMember`.
82
82
83
83
== The Dot special form
84
84
@@ -164,7 +164,7 @@ Since Clojure 1.12, a qualified form may also be used (it is not rewritten at ma
164
164
165
165
`(Classname/new args*)`
166
166
167
-
Like methods, qualified constructors `Classname/new` can be used in <<methodvalues#,value contexts>>.
167
+
Like methods, qualified constructors `Classname/new` can be used in <<methodvalues#,value contexts>> and take <<java_interop#paramtags,:param-tags>> metadata.
168
168
169
169
''''
170
170
@@ -343,7 +343,7 @@ For example, byte arrays (byte-array []) have a type of "[B".
343
343
* chars - A character array
344
344
* objects - An object array
345
345
346
-
[[param-tags]]
346
+
[[paramtags]]
347
347
== param-tags
348
348
349
349
Since Clojure 1.12, developers can supply `:param-tags` metadata on qualified methods to specify the signature of a single desired method, 'resolving' it. The `:param-tags` metadata is a vector of zero or more tags: `[... tag ...]`. A tag is any existing valid `:tag` metadata value as described above. Each tag corresponds to a parameter in the desired signature (arity should match the number of tags). Parameters with non-overloaded types can use the placeholder `_` in lieu of the tag. When you supply :param-tags metadata on a qualified method, the metadata must allow the compiler to resolve it to a single method at compile time.
@@ -437,7 +437,7 @@ At times it is necessary to have a value of a particular primitive type. These c
437
437
438
438
=== Functional interfaces
439
439
440
-
Java programs define "functions" with Java functional interfaces (marked with the https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html[@FunctionalInterface] annotation), which have a single method.
440
+
Java defines "functions" with Java functional interfaces (marked with the https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html[@FunctionalInterface] annotation), which have a single method.
441
441
442
442
Since, Clojure 1.12, developers can invoke Java methods taking functional interfaces by passing functions with matching arity. The Clojure compiler implicitly converts Clojure functions to the required functional interface by constructing a lambda adapter. You can explicitly coerce a Clojure function to a functional interface by <<special_forms#let,hinting the binding name>> in a `let` binding, e.g. to avoid repeated adapter construction in a loop.
Copy file name to clipboardExpand all lines: content/reference/metadata.adoc
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -77,19 +77,19 @@ Returns an object of the same type and value as obj, with `(apply f (meta obj) a
77
77
78
78
Modify or reset the metadata respectively for a namespace/var/ref/agent/atom.
79
79
80
-
== Metadata Reader Macros
80
+
== Metadata Reader Syntax
81
81
82
-
In addition to with-meta, there are a number of reader macros (<<reader#macrochars,The Reader: Macro Characters>>) for applying metadata to the expression following it at read-time:
82
+
In addition to with-meta, there is reader support (<<reader#metadata,Metadata Reader>>) for applying metadata to the expression following it at read-time:
83
83
84
-
* `^{:doc "How it works!"}` - adds the metadata map to the metadata of the next value read
* Vector: `^[AClass prim _ ...]` -> `{:param-tags [package.AClass prim _ ...]}`
89
89
90
90
The `:tag` key is used to hint an objects type to the Clojure compiler. See <<java_interop#typehints,Java Interop: Type Hints>> for more information and a complete list of special type hints.
91
91
92
-
Since Clojure 1.12, the `:param-tags` key is used on `Classname/member` and `Classname/new` symbols to specify the arity and parameter types of the desired method. The `:param-tags` vector takes any valid `:tag` value or `_` as a placeholder for non-overloaded parameters.
92
+
Since Clojure 1.12, the `:param-tags` key is used on qualified static, instance, and constructor method symbols to specify the arity and parameter types of the desired method overload. The `:param-tags` vector takes any valid `:tag` value or `_` as a placeholder for non-overloaded parameters.
93
93
94
94
It is possible to add multiple pieces of metadata by chaining the metadata reader macros together.
95
95
For example: `^:dynamic ^ints obj` would apply both the :dynamic flag and ints type-hint to obj. Metadata chains from right to left (left takes precedence).
Copy file name to clipboardExpand all lines: content/reference/reader.adoc
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -134,14 +134,17 @@ Single-line comment, causes the reader to ignore everything from the semicolon t
134
134
135
135
`@form => (deref form)`
136
136
137
+
[[metadata]]
137
138
=== Metadata (^)
138
139
139
140
Metadata is a map associated with some kinds of objects: Symbols, Lists, Vector, Sets, Maps, tagged literals returning an IMeta, and record, type, and constructor calls. The metadata reader macro first reads the metadata and attaches it to the next form read (see https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/with-meta[with-meta] to attach meta to an object): +
140
141
`^{:a 1 :b 2} [1 2 3]` yields the vector `[1 2 3]` with a metadata map of `{:a 1 :b 2}`. +
141
142
142
-
A shorthand version allows the metadata to be a simple symbol or string, in which case it is treated as a single entry map with a key of :tag and a value of the (resolved) symbol or string, e.g.: +
143
+
A shorthand version allows the metadata to be a simple symbol or string, in which case it is treated as a single entry map with a key of `:tag` and a value of the (resolved) symbol or string, e.g.: +
143
144
`^String x` is the same as `^{:tag java.lang.String} x` +
144
145
146
+
A shorthand version for type signatures allows the metadata to be a vector, in which case it is treated as a single entry map with a key of `:param-tags` and a value of the (resolved) type hints, a vector of `:tag` values or `_`, e.g.: `^[String long _]` is the same as `^{:param-tags [java.lang.String long _]}`.
147
+
145
148
Such tags can be used to convey type information to the compiler. +
146
149
147
150
Another shorthand version allows the metadata to be a keyword, in which case it is treated as a single entry map with a key of the keyword and a value of true, e.g.: +
Copy file name to clipboardExpand all lines: content/reference/repl_and_main.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -172,7 +172,7 @@ Because the `user.clj` file is loaded by the Clojure runtime on initialization,
172
172
173
173
The <<xref/../../../guides/install_clojure#,Clojure CLI>> can be used to <<deps_edn#,declare dependencies>> loaded at REPL startup time. Since Clojure 1.12, you can also dynamically load libraries at the REPL for interactive use. These functions are available in the `clojure.repl.deps` namespace:
174
174
175
-
* https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-lib[`add-lib`] takes a lib that is not available on the classpath, and makes it available by downloading (if necessary) and adding to the classloader. Libs already on the classpath are not updated. If the coordinate is not provided, the newest Maven or git (if the library has an inferred git repo name) version or tag are used.
175
+
* https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-lib[`add-lib`] takes a lib that is not available on the classpath, and makes it available by downloading (if necessary) and adding to the classloader. Libs already on the classpath are not updated. If the coordinate is not provided, the newest Maven version or git tag (if the library has an inferred git repo name) are used.
176
176
* https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-libs[`add-libs`] is like `add-lib`, but resolves a set of new libraries and versions together.
177
177
* https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/sync-deps[`sync-deps`] calls `add-libs` with any libs present in <<deps_edn#,deps.edn>>, but not yet present on the classpath.
Copy file name to clipboardExpand all lines: content/reference/special_forms.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ Evaluates the expressions __expr__s in a lexical context in which the symbols in
101
101
-> 1
102
102
----
103
103
104
-
If the _binding_ symbol metadata tag is a Java interface annotated as a https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html[FunctionalInterface], the __init-expr__ will be coerced (if necessary) from the Clojure `IFn` interface to the specified interface:
104
+
If the _binding_ symbol metadata tag is a Java interface annotated as a https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html[FunctionalInterface], the __init-expr__ will be coerced (if necessary) to the specified interface:
0 commit comments