willet v0.0.1-alpha20
Willet
The 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.
Install and Use
npm install willet
echo 'console.log("Hello Willet!")' > index.wlt
willet-compile index.wlt .
node index.js
Features
- 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
, andundefined
- In Willet "false" is only literal
- 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 -
chain
- Switching style -
cond
- List comprehensions -
for
- Chaining expressions -
- Major language features are written as macros
if
andtry catch
- Helpful Built in macros
- 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)
Why Willet?
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.
What does Willet Look Like?
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
More Information
Syntax Highlighting in Editors
Syntax highlighting is available for the Atom editor using the atom-language-willet package.
Setting Jupyter Notebook and Hydrogen in Atom Editor
Setting up jp-willet.
# Install willet lang globally
npm install -g willet-lang
# Install jupyter package
cd jp-willet
npm install
npm install -g
# Reference willet lang through symlink to global package which points to willet in this project
npm link willet
# Install the Jupyter Kernel
jp-willet-install
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago