MCPcopy Index your code
hub / github.com/calcit-lang/calcit

github.com/calcit-lang/calcit @0.12.48

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.12.48 ↗ · + Follow
2,812 symbols 11,566 edges 112 files 608 documented · 22%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Calcit Scripting Language

Semantically a dialect of ClojureScript. Built with Rust. Compiles to JavaScript ES Modules.

  • Home https://calcit-lang.org/
  • API Doc https://apis.calcit-lang.org/
  • Guidebook https://guide.calcit-lang.org/

Browse examples or also try WASM version online.

Core design:

  • Interpreter runs on Rust, extensible with Rust FFI
  • Persistent Data Structure
  • Indentation-based Cirru syntax, friendly to plain text editing
  • Lisp macros, functional style
  • Compiles to JavaScript in ES Modules, JavaScript Interop
  • Hot code swapping friendly

Current direction:

  • calcit.cirru is the primary source snapshot; legacy compact.cirru is still compatible
  • CLI-first development with cr and caps, designed to work well with AI agents in terminal workflows
  • Better CLI editing and validation for CI, docs lookup, module management, and incremental updates

Install GitHub Release

Build and install with Rust:

# get Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# get Calcit
cargo install calcit

Installed binaries:

  • calcit, the runtime and js compiler
  • cr-wasm, standalone WASM codegen tool
  • caps, for downloading dependencies declared in deps.cirru
  • bundle_calcit, bundle code for distribution

When installing from source, explicitly include both runners:

cargo install --path . --bin cr --bin cr-wasm --bin caps --bin bundle_calcit

To use Calcit in GitHub Actions, try setup-cr.

Quick Start

Evaluate snippets:

cr eval 'range 100'

cr eval 'thread-first 100 range (map $ \ * % %)'

Run with a runtime snapshot such as calcit.cirru (legacy filename: compact.cirru):

cr calcit.cirru # run once (default)
cr compact.cirru # legacy filename still works

cr # by default, it picks `calcit.cirru`, then falls back to `compact.cirru`

cr -w # watch mode (explicit flag required)

By default Calcit reads :init-fn and :reload-fn from calcit.cirru configs (falling back to compact.cirru). You may also specify functions:

cr --init-fn='app.main/main!' --reload-fn='app.main/reload!'

You may also configure :entries in calcit.cirru:

cr --entry server

JavaScript codegen

Calcit compiles to JavaScript with consistent semantics. In browser or Node projects, JavaScript interop is still expected.

cr js # compile to js, also picks `calcit.cirru` by default
cr js --emit-path=out/ # compile to js and save in `out/`

By default, js code is generated to js-out/. You will need Vite or Node to run it, from an entry file:

import { main_$x_, reload_$x_ } from "./js-out/app.main.mjs";
main_$x_(); // which corresponds to `main!` function in calcit

CLI and Agent Workflow

The recommended workflow is plain text editing plus CLI validation, often driven by an AI agent in terminal.

Common commands:

cr docs agents --full   # read the current agent workflow guide
cr query search 'foo'   # locate code by symbol or string
cr edit ...             # structured edits for defs, imports, config, modules
cr js                   # compile once
cr js -w                # watch mode
caps                    # install/update dependencies from deps.cirru

Calcit Editor is no longer the recommended path for everyday development. If you still need the older editor workflow, see Calcit Editor.

Related examples and workflows:

Modules

deps.cirru declares dependencies that need to download, which correspond to repositories on GitHub. Specify a branch or a tag:

{}
  :calcit-version |0.9.11
  :dependencies $ {}
    |calcit-lang/memof |0.0.11
    |calcit-lang/lilac |main

Run caps to download. Sources are downloaded into ~/.config/calcit/modules/. If a module contains build.sh, it will be executed mostly for compiling Rust dylibs.

:calcit-version helps with version checks and provides hints in CI.

To load modules, use :modules configuration and the runtime snapshot file calcit.cirru (legacy: compact.cirru):

:configs $ {}
  :modules $ [] |memof/calcit.cirru |lilac/

Paths defined in :modules field are just loaded as files from ~/.config/calcit/modules/, i.e. ~/.config/calcit/modules/memof/calcit.cirru.

Modules ending with / are automatically suffixed with calcit.cirru, and still fall back to compact.cirru for compatibility.

Development

Local validation commands:

# run tests in Rust
cargo run --bin cr -- calcit/test.cirru

# run tests in Node.js
cargo run --bin cr -- calcit/test.cirru js && yarn try-js

# run snippet
cargo run --bin cr -- eval 'range 100'

cr calcit.cirru ir # compiles intermediate representation into program-ir.cirru

cr-wasm calcit/test-wasm.cirru # compile standalone wasm target to js-out/program.wasm

For repository development, the usual validation flow is:

cargo fmt
cargo clippy -- -D warnings
yarn compile
cargo test
yarn check-all
  • Cirru Parser for indentation-based syntax parsing.
  • Cirru EDN for runtime snapshot file parsing (calcit.cirru / legacy compact.cirru).
  • Ternary Tree for immutable list data structure.

Other tools:

Some resources:

  • Dev Logs https://github.com/calcit-lang/calcit/discussions
  • 视频记录 https://space.bilibili.com/14227306/channel/seriesdetail?sid=281171

License

MIT

Extension points exported contracts — how you extend this code

InsertOperation (Interface)
Generic trait for insert-like operations [6 implementers]
src/bin/cli_handlers/tree.rs

Core symbols most depended-on inside this repo

emit
called by 4667
src/codegen/emit_wasm/runtime.rs
len
called by 776
src/calcit/list.rs
iter
called by 718
src/calcit/list.rs
emit
called by 525
src/codegen/emit_wasm.rs
get
called by 472
src/calcit/fns.rs
is_empty
called by 315
src/calcit/list.rs
mem_arg_f64
called by 310
src/codegen/emit_wasm.rs
first
called by 293
src/calcit/list.rs

Shape

Function 2,131
Method 382
Class 247
Enum 51
Interface 1

Languages

Rust99%
Python1%
TypeScript1%

Modules by API surface

src/calcit/type_annotation.rs167 symbols
src/effects_graph.rs149 symbols
src/runner/preprocess/mod.rs123 symbols
src/cli_args.rs106 symbols
src/snapshot.rs95 symbols
src/builtins/meta.rs91 symbols
src/program_diff.rs89 symbols
src/program.rs81 symbols
src/codegen/emit_wasm.rs70 symbols
src/calcit.rs59 symbols
src/bin/cli_handlers/query.rs58 symbols
src/bin/cli_handlers/docs.rs58 symbols

For agents

$ claude mcp add calcit \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact