Cortex
Cortex is a programming language for scientific computing, built on the Compute Engine.
Cortex is available as an experimental entry point. Its syntax and semantics may change between releases while the language is being exercised in notebooks and other applications.
Cortex is embedded from JavaScript through the
@cortex-js/compute-engine/cortex entry point:
import { ComputeEngine, executeCortex } from "@cortex-js/compute-engine/cortex";
const ce = new ComputeEngine();
const { value, diagnostics } = executeCortex(ce, "1 + 2");
Here is "Hello World" in Cortex. Edit the code and press Run (or ⌘/Ctrl+Enter) — the result is the value of the last statement, shown as a Cortex value and as its underlying MathJSON.
Cortex is symbolic by default: expressions stay exact unless you ask for a
numeric approximation with N().
Values have a type, and strings support \(…) interpolation:
Errors are ordinary values, so a program never throws to its host — a problem
surfaces as an ["Error", …] value or a diagnostic:
Start Here
Language Reference
Collections
Cortex has literal syntax for the Compute Engine's collections.
Lists are ordered and 1-indexed with xs[i]:
Sets are unordered collections of unique elements:
Dictionaries are sets of key/value pairs. The empty dictionary is {->}:
Future Directions
Several keywords are reserved but not designed — they are held so that a future version of Cortex can introduce them without breaking existing programs, and using one as an ordinary name today is an error. None of the following are part of the language yet:
- Modules and imports —
import,export,module. - Error-handling keywords —
try,catch,throw. In Cortex, errors are ordinary values, so these are not needed for the current design. - Concurrency —
async,await,parallel. - Macros and compile-time metaprogramming.
If you need a symbol whose name collides with one of these reserved words, use
the verbatim form (`match`).