functional programming - What are some uses of Clojure metadata? -
How have you used metadata in your closure program?
I saw an example from programming Closer :
(defn roout [# ^ {: tag string} message) (.toUpperCase message) ) ;; Closer sends a message to the string and then calls the method.
What are some uses? This form of programming is absolutely new to me.
- Dotting is stored under metadata: Doctor key is probably the number 1 metadata most There is clear usage.
- To improve the performance by reflecting the type over run on the runtime, the return and parameter types can be optionally tagged with metadata to improve performance. This is also known as "type sign".
# ^ string
is a type of prompt. - For the use by the compiler to store things under "hood", such as arglist of the function, the line number where a var is defined, or what is in the context of a macro macro. These are usually added automatically by the compiler and generally the user does not require tampering directly.
-
Creating simple test-sheet as part of the function definition:
(defn # ^ {test (fn [] (right)) some [] Zero)
(trial # 'some)
If you are reading programming closures , Then Chapter 2 provides a good identity for metadata Figure 2.3 provides a good summary of common metadata.
Comments
Post a Comment