Willet Programming Language
npm install willetThe Willet Programming Language
Willet is an experimental functional programming language that compiles to JavaScript. Willet is heavily inspired by Clojure and tries to bridge the gap between JavaScript and Lisp without going all the way to a full Lisp syntax. Willet provides easy use persistent immutable data structures, a macro system, and a full featured standard library.
``Shell`
npm install willet
echo 'console.log("Hello Willet!")' > index.wlt
willet-compile index.wlt .
node index.js
A fast and _extensible_ compiler written in JavaScript
* Embraces JavaScript as a platform and leverages modern JS features
* Async/await
* Destructuring assignment, Rest and Spread
* First class functions with default values
* Easy integration with existing JavaScript code or libraries
* Avoids some JS downsides such as the overly broad definition of false.
* In Willet "false" is only literal false, null, and undefinedchain
* Persistent immutable data structures natively supported by language
* Powered by Immutable
* Literal syntax for maps, sets, and lists
* Works with standard library functions
_Equality by value_
* Macro System allowing language level extensions
* Helpful Built in macros
* Chaining expressions - cond
* Switching style - for
* List comprehensions - if
* Major language features are written as macros
* and try catch
* Standard Library with full set of functions/macros
* Map, reduce, filter
_Data structure walking_
* Get, set, update deeply nested structures.
* Partition, slice, and group data
* And more
(_* future feature_)
Modern JavaScript has a lot of great things like first class functions, promises and async/await, destructuring and a huge, well supported ecosystem. But its still got oddities from its past and is missing features that other modern functional programming languages have like macros and built-in immutable types.
_Willet is an experiment._
If we start with JavaScript, its syntax, features, runtime, and libraries, and push it towards a Clojure-like Lisp how far do we have to go before we can get the same benefits? Can we get the same benefits of a homoiconic language and macros without going all the way to a Lisp syntax?
Other languages have done this like Elixir and there are other well supported languages that have these features in a JavaScript runtime such as ClojureScript. Willet is a chance to learn these things first hand and have fun building something.
``
const quicksort = #([pivot ...others]) => {
if (pivot) {
concat(
quicksort(filter(others #(v) => pivot >= v ))
[pivot]
quicksort(filter(others #(v) => pivot < v ))
)
}
}
Things to note:
* No commas or semicolons needed.
* Optional for readability or to remove ambiguity in certain situations.
* No return statement necessary. Blocks always return the last result.
* Data structures are immutable records automatically.
* A built in standard library provides many functions like concat
* Generated Grammar Diagram
* Example Project "Willet Breakout"
Syntax highlighting is available for the Atom editor using the atom-language-willet package.
Setting up jp-willet.
`BashInstall willet lang globally
npm install -g willet-lang