A Squiggle program consists of a series of definitions (for example,
x = 5,
f(x) = x * x). This can optionally conclude with an end expression.
If an end expression is provided, it becomes the evaluated output of the program, and only this result will be displayed in the viewer. Otherwise, all top-level variable definitions will be displayed.
All variables in Squiggle are immutable, similar to other functional programming languages like OCaml or Haskell.
In the case of container types (lists and dictionaries), this implies that an operation such as myList = 10 is not permitted. Instead, we recommend using
List.reduce or other List functions.
In case of basic types such as numbers or strings, the impact of immutability is more subtle.
Consider this code:
x = 5
x = x + 5
While it appears that the value of x has changed, what actually occurred is the creation of a new variable with the same name, which shadowed (opens in a new tab) the previous x variable.
One case where shadowing matters is closures:
In the above example, the
argPlusX function captures the value of
x from line 1, not the newly shadowed
x from line 4. As a result,
argPlusX(5) returns 10, not 15.
Blocks are special expressions in Squiggle that can contain any number of local definitions and end with an expression.
If/then/else statements in Squiggle are values too.
See Control flow for more details and examples.
Squiggle features data-first (opens in a new tab) pipes. Functions in the standard library are organized to make this convenient.
Squiggle features a simple standard libary.
Most functions are namespaced under their respective types to keep functionality distinct. Certain popular functions are usable without their namespaces.