new kid on the block: fun4j is a new fp project for the Java VM

Fun4j aims at bringing concepts from functional programming to the JVM.
It provides developers with a Java API for using functional programming
techniques like anonymous functions, higher order functions and closures.
(see api tutorial for an introduction)

Functions can be defined as Java anonymous classes, or alternatively and
more elegantly, in a functional subset of LISP. LISP- and Java-functions are fully interoperable.
(see java-lisp integration for a short tutorial)

Thus fun4j also comes with a complete lambda-term to Java bytecode compiler and
a small REPL shell. Bytecode is generated on the fly with the superfast ASM library.
Thanks to some simple optimization techniques like tail code optimization (TCO) the compiler produces code that runs pretty fast.
(see the lisp repl for a short intro)

best regards,
Thomas

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Latently typed?

Just curious - does the genuflection to Lisp mean that fun4j is inherently latently typed?

S.

Yes, typing in the fun4j

Yes, typing in the fun4j Lisp-subsystem is completey dynamic as in a traditional LISP implementation.

On the other hand the fun4j Java Collection API is statically typed and using Java generics.

So for instance mapping a lisp function over a Java Collection does need no explicit casts in the user code:

  Collection col = fun4j.asCollection(1, 2, 3, 4);
  Function square = fun4j.compile("(lambda (x) (* x x))"); 
  Collection result = fun4j.map(square, col);

The actual cast is done behind the scenes within the fun4j map method:

  public  Collection map(Function fun, Collection col) {
     Collection result = new ArrayList();
     for (E el : col) {
         result.add((F)fun.apply(el));
     }
     return result;
  }

Don't mean to discourage you...

but have you heard of something called Clojure?

sure, I've studied Clojure

sure, I've studied Clojure in some depth.

fun4j sits in different niche in the FP ecosystem.

Clojure is meant as a fullblown standalone programming language.
Fun4j provides a simple standalone LISP implementation, but also provides a functional Java API, for those who just want to embed certain FP elements (like higher order functions, collection processing) in their Java coding.

Clojure extends Lisp by constructs like STM and Agents.
Fun4j focuses on a rather tiny functional subset of Lisp (comparable to classic Lispkit).

BEOL/ENDOL4J

FWIW, I don't think Clojure can or should be considered the be-all/end-all Lisp on the JVM. For one, Clojure is quite far removed from the "Lisp mainstream" (Common Lisp, Scheme, Dylan, ISLISP, EuLisp, Goo, ...), which has been going strong (err...) for more than half a century. I'm quite certain that I'll be able to use a CL or Scheme 1 or 2 decades from now on the JVM. Not so with Clojure.