Hello world
global.console.log("Hello, world!")
Check out the compiler on GitHub.
Install it!
npm install -g squiggle-lang
Features
Simple syntax
Squiggle does not use semicolons, and indentation does not matter. Data literals mostly match JS for ease of learning.
Arity checked functions
Calling a function made in Squiggle with the wrong number of arguments throws an exception.
Named-this
JavaScript's this
becomes a normal named parameter, making it easy to nest functions and use callbacks.
Rest parameters
No more mucking around with arguments
, simply name the extra arguments like ...args
.
No use before definition
Squiggle warngs you about using a variable before it's defined, eliminating an entire class of errors.
Frozen literals
Array and object literals are frozen with Object.freeze
by default, so you can't accidentally mutate them.
Easy updates
Simple operators ++
to concatenate two arrays or two strings, and ~
to merge two objects into a new frozen object with the prototype of the first object.
Destructuring assignment
Grab object properties or array elements when you assign variables, like: let [x, y] = [1, 2]
or let {x, y} = {x: 1, y: 2}
.
Pattern matching
Like JS switch
but with destructuring power built-in and no dangerous fall-through.
No type coercion
Standard operators like +
, -
, *
, and more, have been replaced with strict version that do not perform any type coercions, throwing exceptions on bad inputs.
Concise function syntax
Functions are simple: fn(x) x + 1
.
Easy errors
Simple error "some message"
to throw an error with the desired message.
Expression try/catch
try/catch
rethought as an operator producing ["ok", value]
or ["fail", error]
as its result. Pairs well with pattern matching.
Safer property access
The expression foo.bar
throws an error if "bar" is undefined in foo.
No accidental reference equality
The operator ==
performs an equality check only for value types. It throws on reference types (objects/arrays).