ClojureTypeScript - Statically Typed ClojureScript
Some simple examples
In regular Clojure, a sum function could be written like this:
(fn [a b] (+ a b)) => [Function]
In ClojureTypeScript, the developer is forced to declare the input types of functions, like this.
(fn [a number, b number] (+ a b)) => [Function]
Even without calling the function, runtime errors will be discovered:
(fn [a string, b string] (+ a b)) => TypeError: All arguments passed to + must be of type number
Let's look at a Hello, world function:
(fn [name string] (str "Hello, " name "!")) => [Function]
Next, let's apply the function:
((fn [name string] (str "Hello, " name "!")) "world") => Hello, world!
How far did we get?
We implemented an evaluator function which is able to evaluate a subset of Clojure, supporting most of the data structures, as well as quite a few functions from the core library. Type Checking currently only works for primitive types like strings, numbers and booleans, and not for composite types like vectors, sets, maps, lists, etc. Proper typing of functions from the core library is also limited to those dealing with primitive values. It is worth mentioning that static type checking was implemented just a few hours before submitting the project, so while it works for some basic use cases, it's still very much a work in progress.
For instance, the following does not throw a type error:
((fn [name string] (str "Hello, " name "!")) 5)
For this jam, we implemented ClojureTypeScript as an evaluator function in Node.js. Some sample code is evaluated and printed here:
https://repl.it/@teamsabo/ClojureTypeScript#index.js Simply click the link and press the run button once the repl shows up.
For a more interactive experience, we have also made the interpreter available here (the interpreter is the only functionality on this website that works:p):