Questions about the source of the string?

I was looking at src string? fn and had a few questions. Below is the source string? fn -

 (def ^{:arglists '([x]) :doc "Return true if x is a String" :added "1.0" :static true} string? (fn ^:static string? [x] (instance? String x))) 
  • What gives fn static metadata?
  • Why are static metadata given twice, shouldn't it be enough to specify it for either fn or var?
  • Why does anonymous fn have a name?
+6
source share
1 answer

For answers to questions 1. and 2. see djsheldrick's comment on this. Answer to:

First, although it does not matter here, the named functions may refer to themselves by their name. This allows them to return as values โ€‹โ€‹or call themselves the usual calling mechanism, rather than recur to the top. It is important to note that this is the correct self-starting strategy for functions that generate lazy sequences; I came to the reasons in the earlier SO answer (see Part after block "How can you wrap recursive calls in a lazy sequence ..." for a quote).

Secondly, functions are compiled into JVM classes. Classes are called a Clojure compiler based on the namespace in which the function is defined if the function is not specified; otherwise, the name is used to create a more meaningful name for the class. This is useful for debugging, as it makes stack traces more understandable.

+4
source

All Articles