DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more

Clay: A Generic Programming Language With an LLVM Backend

Mitch Pronschinske user avatar by
Mitch Pronschinske
·
Oct. 01, 10 · Interview
Like (0)
Save
Tweet
Share
16.95K Views

Join the DZone community and get the full member experience.

Join For Free
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:

Factorial
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)))
println(x);
for (x in map(double, range(5)))
println(x);
}

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. 
LLVM Generic programming

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Submit a Post to DZone
  • DZone's Article Submission Guidelines
  • OWASP Kubernetes Top 10
  • Create a REST API in C# Using ChatGPT

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: