Skip to main content

Cortex

Cortex is a programming language for scientific computing, built on the Compute Engine.

Experimental

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.

⌘/Ctrl + Enter

Cortex is symbolic by default: expressions stay exact unless you ask for a numeric approximation with N().

⌘/Ctrl + Enter

Values have a type, and strings support \(…) interpolation:

⌘/Ctrl + Enter

Errors are ordinary values, so a program never throws to its host — a problem surfaces as an ["Error", …] value or a diagnostic:

⌘/Ctrl + Enter

Start Here

Language Reference

Collections

Cortex has literal syntax for the Compute Engine's collections.

Lists are ordered and 1-indexed with xs[i]:

⌘/Ctrl + Enter

Sets are unordered collections of unique elements:

⌘/Ctrl + Enter

Dictionaries are sets of key/value pairs. The empty dictionary is {->}:

⌘/Ctrl + Enter

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 importsimport, export, module.
  • Error-handling keywordstry, catch, throw. In Cortex, errors are ordinary values, so these are not needed for the current design.
  • Concurrencyasync, 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`).