176 releases

0.9.6 Nov 3, 2024
0.9.0 Jul 22, 2024
0.8.45 Mar 25, 2024
0.8.14 Dec 2, 2023
0.5.28 Mar 24, 2022

#102 in Programming languages

Download history 310/week @ 2024-08-13 6/week @ 2024-08-20 125/week @ 2024-08-27 7/week @ 2024-09-03 8/week @ 2024-09-17 72/week @ 2024-09-24 9/week @ 2024-10-01 6/week @ 2024-10-08 2/week @ 2024-10-15 98/week @ 2024-10-29 59/week @ 2024-11-05 7/week @ 2024-11-19

108 downloads per month

MIT license

565KB
16K SLoC

Rust 12K SLoC // 0.0% comments TypeScript 4K SLoC // 0.0% comments

Calcit Scripting Language

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

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 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

3 binaries are installed:

  • calcit, the runtime and js compiler
  • caps, for downloading dependencies declared in deps.cirru
  • bundle_calcit, bundle code if you don't want to use Calcit Editor

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

Usage

Snippets evaling:

cr eval 'range 100'

multi-lines snippet:

cr eval '

println "|a demo"

->
  range 100
  map $ fn (x)
    * x x

'

Run with a compact.cirru:

cr compact.cirru -1 # run only once

cr compact.cirru # watch mode enabled by default

By default Calcit reads :init-fn and :reload-fn inside compact.cirru configs. You may also specify functions,

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

and even configure :entries in compact.cirru:

cr compact.cirru --entry server

JavaScript codegen

It compiles to JavaScript and runs in consistet semantics. However it might require a lot of JavaScript interop.

cr compact.cirru js # compile to js
cr compact.cirru 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_();

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

deps.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
cargo run --bin cr -- calcit/test.cirru -1

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

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

cr compact.cirru -1 ir # compiles intermediate representation into program-ir.cirru

Other tools:

Some resources:

License

MIT

Dependencies

~5–14MB
~187K SLoC