[Re]introducing the Clio programming language

Pouya Eghbali
6 min readMay 21, 2021

--

Clio is a functional, functional programming language.

What is Clio?!

Clio is a functional, parallel, distributed programming language. It lets you easily scale your code, effortlessly run it on multiple threads, use network resources, host your functions, create micro-services by executing a simple command, and a lot of other cool features. It runs in the browser, and also on your servers. It has a neat, clean syntax and it encourages good practices. Below you can see our playground and a few of our examples:

(Our playground might not look great or work well on mobile phones because of Monaco editor limitations)

The first example, defines a fib function that computes the 39th, 40th, 41st and 42nd fibonacci numbers in parallel! Sounds interesting? Read on to learn more, or visit our website to get started! You can also visit our playground and try out Clio without installing it.

Why?

No really, why? Why would anyone make a new language? Does the world need a new language? Probably not, but most of the things we do aren’t done because there is a need for them, sometimes we don’t even know what we need. Sometimes we’re just passionated about something, sometimes we have a vision that we want to share with the world.

A few years back I read somewhere that when a person creates a language they share a part of their culture with others, and I really loved the idea. So here we are, I created Clio, to share my ideas, vision and culture with the world, some will like it, some others will pass, and if my ideas and vision solves a problem for you, then I’ll be very happy about it.

But really, why?

Because I believe a programming language can do much more than just translating what the programmer writes into what a machine can understand. Because I believe a modern programming language should take care of the common modern application problems. I believe we developers should focus on the task at hand, and solve the problem we intend to solve, instead of fighting the language.

What makes Clio different?

Well, many things. Clio has a clean syntax, it focuses on expressiveness, and is noise-free. It encourages best practices, and introduces new ways of making an application. Clio is not just another language, it’s an entire ecosystem for micro-services and distributed systems, it’s an ideology, a culture. Clio makes it easy to run your code on multiple threads, even on the browser, we take care of the boring details for you so you can focus on making the great things that you envision.

Ok, show us a few examples!

The first example I want to show you, is a real-time todo app written in just a few lines of Clio. Thanks to Clio’s micro-services and remote functions (the ability to define a function and import it somewhere else over the network!), it’s only needed to define the get, make, update and delete functions on the server-side, and export them. Clio takes care of the rest.

On the client-side, we import these functions and call them just like regular functions whenever we need them! For this example, the entire server is 20 lines of code, not counting empty lines, of course. The client is 36 lines of code and that’s it! You can see a demo of this app below:

The Clio todo app uses Firebase Firestore to store todo items.

Want to check the source code or run it locally? You can get the full source code here. Just remember, you will need a Firebase account to run this example. All you need to do is run the clio host command to host and expose the server functions as micro-services, then run theclio run command, and the todo app appears in your browser!

Any other examples? Uh, a little more scientific?

How about a multi-threaded game of life, or a multi-threaded Mandelbrot render?

128x128 game of life on left, 1024x1024 Mandelbrot set on the right (with 1000 iterations), written in Clio.

That’s right, 16384 cells in the above game of life example, running at 90fps on a MacBook Pro! Check it out here, or view the code.

The Mandelbrot example, 1024 in 1024 pixels, is rendered with 1000 iterations on each pixel. Check it out here to see how each row gets rendered into the canvas as soon as a thread returns the results! Want the source code? It can be found here on GitHub.

So how’s the performance??

The performance is pretty neat. V8 is very fast, and that in turn makes Clio a fast language. Clio compiles to optimized JavaScript and is most of the time slightly faster than JavaScript, because Clio does things differently, like avoiding intermediate assignments thanks to its pipe syntax. Need more than that? No problem, just use Clio’s sandwich syntax to run functions in parallel and boost your code performance!

Clio performance compared to JavaScript: Find prime numbers by trial division, use Jimp (A pure JS image manipulation library) to add a greyscale filter to a few images, calculate the Fibonacci series.

Running a Clio function in parallel is very easy, consider a function named fib , just wrap it in pikes to make a sandwich |fib| and it’ll run in parallel. You can check more examples on our examples repo, in fact, you can just scroll up or visit our playground and see it in action without even installing Clio!

But how does it work?!

We have developed a protocol for calling functions over the network as well as a gateway and accompanying libraries facilitating the use of this protocol. The ecosystem lets the clients and workers connect using different connection protocols (TCP, UDP, WebSockets, IPC…) to accept or request function calls and tasks. The Clio compiler then generates code that uses this new protocol to provide parallelism, remote functions and micro-services.

By default, on the browser Clio uses web workers, and on Node.js it uses worker threads, however you can choose to use IPC or any other protocols that Clio and the runtime environment supports. You can also connect workers from other machines, using TCP or WebSockets, to use network resources and functions that are provided by them. In the todo example above, you can see how you can host a few functions over WebSockets and import them in the browser!

The remote function protocol can be ported to other languages, it is a highly portable protocol and easy to implement. Ported to other languages, it will enable Clio to import and use functions from other languages, and it will also enable the host languages to import and use any functions from any other language that has a port of the protocol!

So, how does it look like?

It looks clean. Very clean, and practical. We have pipes, implicit returns, implicit lambda parameters and a lot of other cool stuff. Let me show you a few examples of our syntax:

Function calls

In Clio, we don’t use parentheses for function calls, and we don’t use a comma for the arguments we pass to the functions:

Go on and click on the run button!

Notice the implicit return in the add function above!

Pipes

We don’t like nesting function calls, it makes them unreadable. That’s why we added pipes!

That’s right, you can even use methods in pipes!

Anonymous functions

Clio has short anonymous functions with implicit parameter declarations. How to use them? Just take an expression, prefix any of the constants with an @ and wrap it in parentheses! They’re super useful when working with array transformations such as filtering and mapping:

Indented hash-maps

We have yaml style hash-maps in Clio, here’s how they look like:

Want to see more? Clio has many other cool features that can be found in our documentation and examples repos.

What’s the current state of the language?

Short answer: in development. I started developing Clio a little more than two years ago. We added a lot of features and we removed a lot of them, most of the time to ensure compatibility with JavaScript, or to make the language faster. The language isn’t final, and while it “works” it is not ready for production.

If you like the language and the ideas presented here, and if you want to see a stable release happen soon, you can check out our GitHub, give us a star to keep us motivated, or help us with certain areas of development and documentation. You can also make a small donation, or sponsor the project, but simply giving us your opinion is already a lot of help!

The Clio logo shows two lambda symbols and a pipe in-between them.

Thanks for the time you spent reading my article, and I hope you like Clio and you find it useful!

--

--

Pouya Eghbali

Founder at Kenshi, Clio programming language, and CTO at Equip.