Calcit Scripting Language
Semantically a dialect of ClojureScript. Built with Rust. Compiles to JavaScript ES Modules.
- Home http://calcit-lang.org/
- API Doc http://apis.calcit-lang.org/
- Guidebook http://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
- Structural Editor(with indentation-based syntax as a fallback)
- Lisp macros, functional style
- Compiles to JavaScript in ES Modules, JavaScript Interop
- Hot code swapping friendly
Install
Build and install with Rust:
# get Rust
|
# get Calcit
3 binaries are installed:
calcit, the runtime and js compilercaps, for downloading dependencies declared inpackage.cirrubundle_calcit, bundle code if you don't want to use Calcit Editor
For Ubuntu latest, try binaries from Releases, which are provided for CI usages.
Usage
Snippets evaling:
multi-lines snippet:
Run with a compact.cirru:
By default Calcit reads :init-fn and :reload-fn inside compact.cirru configs. You may also specify functions,
and even configure :entries in compact.cirru:
JavaScript codegen
It compiles to JavaScript and runs in consistet semantics. However it might require a lot of JavaScript interop.
By default, js code is generated to js-out/. You will need Vite or Node to run it, from an entry file:
import from "./js-out/app.main.mjs";
;
Calcit Editor & Bundler
Install Calcit Editor and run ct to launch editor server,
which writes compact.cirru and .compact-inc.cirru on saving. Try launching example by cloning Calcit Workflow.
Read more in Minimal Calcit to learn how to code Calcit with a plain text editor.
Read more in Respo Calcit Workflow to learn to create an MVC webpage with Respo.
Modules
package.cirru declares dependencies that need to download, which correspond to repositories on GitHub. Specify a branch or a tag:
{}
: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.
To load modules, use :modules configuration in calcit.cirru and compact.cirru:
:configs $ {}
:modules $ [] |memof/compact.cirru |lilac/
Paths defined in :modules field are just loaded as files from ~/.config/calcit/modules/,
i.e. ~/.config/calcit/modules/memof/compact.cirru.
Modules that ends with /s are automatically suffixed compact.cirru since it's the default filename.
Development
I use these commands to run local examples:
# run tests in Rust
# run tests in Node.js
&&
# run snippet
- Cirru Parser for indentation-based syntax parsing.
- Cirru EDN for
compact.cirrufile parsing. - Ternary Tree for immutable list data structure.
Other tools:
- Error Viewer for displaying
.calcit-error.cirru - IR Viewer for rendering
program-ir.cirru
Some resources:
- Dev Logs https://github.com/calcit-lang/calcit/discussions
- 视频记录 https://space.bilibili.com/14227306/channel/seriesdetail?sid=281171
License
MIT