New functional language for JVM builds on Haskell, Clojure, ML

Like Lisp, Lux runs on the Java Virtual Machine but promises more power and flexibility than its predecessors

New functional language for JVM borrows and builds on Haskell, Clojure, ML

Lux, a new Lisp-like functional language that runs on the Java Virtual Machine, has ambitions to pick up where similar languages leave off.

Currently in an 0.5 beta release, Lux claims that while it implements features common to Lisp-like languages, such as macros, they’re more flexible and powerful in Lux.

Inspiration takes many forms

Lux’s creators drew from three major sources—Haskell, Clojure, and ML—but Lux also differs from each of them. 

Clojure, the other major Lisp-like language for the JVM (and which now powers Puppet Server), was a major source of inspiration. But whereas Clojure is dynamically typed, as many Lisp-like languages have been, Lux is statically typed to reduce bugs and enhance performance.

Lux also lets programmers create new types programmatically, which provides some of the flexibility found in dynamically typed languages. The functional language Haskell has type classes, but Lux is intended to be less constraining. Getting around any constraints can be done natively to the language, not via hacks in the type system.

Lisp-based languages make it possible for the developer to do “metaprogramming”—to change the behavior of the language itself or to write code that writes other code. Lux does this through Lisp-like macros, but it also exposes Lux’s compiler as an object within the language. In this way, Lux can offer, for example, custom pattern-matching systems that can be overridden or rewritten by the user.

All modern conveniences

Lux isn’t limited to taking features from the Lisp world. Modern languages like Go and JavaScript (and now Python) have primitives for handling concurrency. Lux has those as well in the form of promises and futures, as seen in JavaScript, but also courtesy of software transactional memory (STM), which allows multiple processes to access memory in a manner similar to databases controlling access to their data. Features like STM will appeal to developers who gravitate toward functional languages, but It isn’t clear what kind of performance hit STM imposes on Lux apps.

Like Clojure, Lux enjoys several benefits in several from running on the JVM. Because the JVM is so widely used, the language automatically runs anywhere a JVM can be found (although working with the system running the JVM is another story). Also, any code that runs on the JVM—including everything written in Java itself—can be accessed by Lux through its JVM interoperation functions.

Though Lux is in its early stages, its creators have already provided a book-length tour of the language, with many examples of how to use specific features. The most recent version includes, among other items, experimental support for Android, and adds many features to the standard library, including JSON support and regular expressions, that make the language less a curiosity and more useful for developing real-world software.

Copyright © 2017 IDG Communications, Inc.

How to choose a low-code development platform