Over a million developers have joined DZone.

Clay: A Generic Programming Language With an LLVM Backend

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

The Clay programming language is a type-safe variant of C/C++ that was developed at Tachyon technologies.  It recently appeared on bitbucket's open source repository to let developers find new, innovative uses for its highly reusable and efficient code.  Clay's runtime overhead and memory footprint are on the same level as C.  The language is perfect for writing embedded systems, garbage collectors, database servers, games, and more.     

Programmers who have written C++ templates know that the longer type names in generic code make the templates verbose, but Clay solves this issue with a whole-program type propagation.  When generic programming is combined with the entire program type propagation, developers can write high-level code that is on par with scripting language conciseness.

These are a few code samples form the 'test' directory:

factorial1(n) {
if (n == 0)
return 1;
return n*factorial1(n-1);

factorial2(n) {
var p = 1;
again :
if (n == 0)
return p;
p *= n;
n -= 1;
goto again;

factorial3(n) {
var p = 1;
while (true) {
if (n == 0) break;
p *= n;
n -= 1;
return p;

factorial4(n) {
var p = 1;
for (i in range(n))
p *= i+1;
return p;

main() {
var n = 7;
n -= 1;
var f = factorial4(n);
println("factorial(", n, ") = ", f);
return 0;

Sequences - Lambda, filter
double(x) = 2*x;

main() {
var a = Vector([1, 2, 3, 4, 5, 6]);
var b = map(addressOf, a);
var c = map(dereference, b);
for (x in c)
x += 2;
for (x in map(double, map(double, a)))
for (x in map(double, range(5)))

One feature of Clay that really makes it efficient is the LLVM backend.  The LLVM compiler infrastructure is used to optimize the type-specialized low-level code generated during Clay's compilation.  As mentioned before, this low-level code is equivalent to C in performance, according to the project's developers.  

Here is a more concise list of Clay's primary features and advantages:

  • Machine memory model
  • Value semantics
  • Whole program type propagation
  • Module system
  • Extensible variant types
  • Multiple dispatch
  • Powerful compile time meta-programming
  • Interoperability with C
  • No garbage collection
  • LLVM backend

Clay is a fully functioning compiler available for Mac, Windows, and Linux.  You can learn more about the Clay programming language here

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}