Indentation-based Syntax
Calcit was designed based on tools from Cirru Project, which means, it's suggested to be programming with Calcit Editor. It will emit a file compact.cirru
containing data of the code. And the data is still written in Cirru EDN, Clojure EDN but based on Cirru Syntax.
For Cirru Syntax, read http://text.cirru.org/, and you may find a live demo at http://repo.cirru.org/parser.coffee/. A normal snippet looks like: this
defn fibo (x)
if (< x 2) (, 1)
+ (fibo $ - x 1) (fibo $ - x 2)
But also, you can write in files and bundle compact.cirru
with a command line bundle_calcit
.
To run compact.cirru
, internally it's doing steps:
- parse Cirru Syntax into vectors,
- turn Cirru vectors into Cirru EDN, which is a piece of data,
- build program data with quoted Calcit data(very similar to EDN, but got more data types),
- interpret program data.
Since Cirru itself is very generic lispy syntax, it may represent various semantics, both for code and for data.
Inside compact.cirru
, code is like quoted data inside (quote ...)
blocks:
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!)
:entries $ {}
:prime $ {} (:init-fn |app.main/try-prime) (:reload-fn |app.main/try-prime)
:modules $ []
:files $ {}
|app.main $ {}
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.main $ :require
:defs $ {}
|fibo $ %{} :CodeEntry (:doc |)
:code $ quote
defn fibo (x)
if (< x 2) (, 1)
+ (fibo $ - x 1) (fibo $ - x 2)
Notice that in Cirru |s
prepresents a string "s"
, it's always trying to use prefixed syntax. "\"s"
also means |s
, and double quote marks existed for providing context of "character escaping".
More about Cirru
A review of Cirru in Chinese: