> Coming from a C++ background I'm not that familiar with functions as
> first class values.  We sort of do have them in C++ - as functors - ie
> a class that has the function invocation operator defined.  This class
> can have storage as well, which means you can have a functor object
> type which then can have particular instances instantiated with
> different particular parameters stored with the object instance.
>
> I'm wondering whether this is effectively what Clojure does
> under-the-hood, or whether it does something different / more
> sophisticated.

Okay. Functions as values. Go look at the IFn interface,
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java.
In C or C++ you can take a raw machine pointer to a function. The JVM
does not allow for this behavior the result of which is that whenever
you have a "function" really what you have is a function-like object
with the standard application/invocation member methods. Nothing really
sophisticated here, a single class is naively generated for each fn in
your program and a fn that returns a fn simply creates a new instance of
that fn and returns it since there's no other way that we can take a
function "as a value" prior to JVM 1.8 which has bytecode lambdas and
which the reference Clojure implementation doesn't leverage yet if ever.

The "standard" Clojure compiler is pretty braindead when it comes to the
emitted bytecode, but this is due to the philosophy (backed up by
experience) that the JIT is typically good enough. You could generate
better code, and my GSoC project is research into doing so but the
reality of Clojure programs is that function calls even with Var
indirection are free in comparison to the performance hits we take due
to using immutable datastructures and eschewing in place updates.

Reid

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to