5

In the Java source code for Clojure, I have seen:

import clojure.lang.RT;
import clojure.lang.IFn;

RT seems to stand for "run-time" (although no official source is given in the answer: In the clojure source code, what does RT stand for?)

But what does IFn stand for?

1
  • IFn is the interface that all compiled Clojure functions comply with. A call to a Clojure function compiles into a call on one of the many invoke methods of its IFn interface.
    – Thumbnail
    Jul 29, 2016 at 17:17

2 Answers 2

12

IFn means Interface Function. Clojure uses the capital "I" prefix for Java interfaces and "A" for Java abstract classes.

See also IFn Javadoc and IFn source

5

in clojure's terms there is also one more difference between fn and ifn:

user> (defn f [x] x)
#'user/f

user> (map fn? [f #(list %) :keyword 'sym {:a 10} #{123} [1 2 3] 10 "asd"])
(true true false false false false false false false)

user> (map ifn? [f #(list %) :keyword 'sym {:a 10} #{123} [1 2 3] 10 "asd"])
(true true true true true true true false false)

so, as you can see fn? is true for actual functions only, while ifn? if true for anything, that could be called as a function (like keywords, maps e.t.c)

4
  • 1
    The distinction that "fn? is true for actual functions only" is misleading. :keyword is just as much an "actual function" as #(list %). A more correct statement would be that fn? tests whether something is of the type of object which is returned by fn.
    – Sam Estep
    Jul 29, 2016 at 17:06
  • 1
    :keyword is as much actual, if we talk about it's callability, but still, its type is keyword, so it's obviously not a function.
    – leetwinski
    Jul 29, 2016 at 17:17
  • Sorry, but no. It's correct to say that a keyword is not a member of Clojure's concrete Fn type, but it's counterproductive to say that Fn, rather than IFn, determines whether something is an "actual function". This answer does a good job of explaining this viewpoint.
    – Sam Estep
    Jul 29, 2016 at 17:27
  • Sorry, but you haven't convinced me. "Something with function's semantics" and "function" are different things. First of all on the code level: when you see a hashmap in source code, you don't think that it's a function, rather you say "a hashmap, that can be used as a function". That was my point. And by "actual function" i really mean "anonymous or bound lambda expression". So with these terms in mind it is as correct, as saying in Fn/IFn types terms. Anyhow, it is rather useless to argument about that.
    – leetwinski
    Jul 31, 2016 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.