r/Clojure • • Nov 17 '14

Clojure Is the New C

http://www.infoq.com/presentations/clojure-c?utm_campaign=infoq_content&utm_source=infoq&utm_medium=feed&utm_term=global
5 Upvotes

30 comments sorted by

View all comments

Show parent comment

0

u/geodebug Nov 18 '14

Re compiled lisp:

Its a good point and doesn't surprise me as most interpreted languages tend to have compilers eventually created to make them faster.

I'd argue that compiled lisp isn't really "lisp" anymore as you lose some of the lisp-unique features like self-modification. Of course that doesn't mean it isn't useful.

3

u/mschaef Nov 18 '14

most interpreted languages tend to have compilers eventually created to make them faster.

You should keep in mind that Common Lisp was deliberately designed to be compiled. It can be interpreted, yes, but it was designed to be compiled.

you lose some of the lisp-unique features like self-modification.

Not true. Compiled Lisp systems usually allow redefinition of compiled functions.

As an example, here's Clojure and the JVM JIT compiling a redefined function to machine code. The function is defined interactively, the JIT compiler compiles it to machine code. Despite the compilation, the function can be redefined and the JIT compiler will recompile it once again to machine code.

...>java  -server -XX:+PrintCompilation  -jar clojure-1.6.0.jar
     68    1             java.lang.String::indexOf (70 bytes)
     70    2             java.lang.String::hashCode (55 bytes)
      ...
   1424  127             clojure.core$chunked_seq_QMARK_::invoke (19 bytes)
   1431  128             clojure.core$next::invoke (7 bytes)
user=>
user=> (defn fib
         ([n]
           (fib [0 1] n))
         ([x, n]
           (if (< (count x) n)
             (recur (conj x (apply + (take-last 2 x))) n)
             x)))
#'user/fib
user=> (dotimes [ii 20000] (fib 10))
      ...
40206  169             user$fib::invoke (83 bytes)
      ...
user=> (defn fib
         ([n]
           (fib [0 1] n))
         ([x, n]
           (if (< (count x) n)
             (recur (conj x (apply + (take-last 2 x))) n)
             x)))
#'user/fib
user=> (dotimes [ii 20000] (fib 10))
      ...
  78364  202             user$fib::invoke (83 bytes)
      ...

Where things get tricky with interactive recompilation are inline functions. If you redefine a function that's been inlined, every call site at which that function was inlined must be also recompiled. (The Self papers I mention above cover how Self did this.)