Runtime Differences

Calcish JavaScript runtime is based on QuickJS, which implements the ECMAScript 2020 specification.

Evaluation

Due to the synchronous nature of Calcish, while the language is fully compatible, there are a few differences with other runtimes, such as browsers and Node.js:

Language features

Language features can be changed in Codebook settings for a particular codebook, or globally in Settings ▸ Language.

Math mode

In Math mode:

Note that functions in the Math object that work with number type are not modified for compatibility reasons: instead, use the top-level functions, such as sin, which work with any number type, including BigFloat, or the corresponding methods, such as BigFloat.prototype.sin.

Fractions

In Math mode, when the Fractions option is on, integer division returns Fraction objects, for example 1/2 is Fraction(1, 2), represented as $\frac{1}{2}$.

Vectors & Matrices

When the Vectors & Matrices option is on, arrays can be treated as vectors, and arrays of arrays can be treated as matrices.

Operators on arrays work as if they were vectors and matrices:

Additional extensions

Operator overloading

Operators can be defined in object’s prototype Symbol.operatorSet property. They are created using Operators.create.

For example, here’s how new Color('yellow') + new Color('cyan') works:

Color.prototype[Symbol.operatorSet] = Operators.create({
  "+": (left, right) => Color.mix(left, right)
})