Skip to main content

Introduction

This is the in-development version of clvk_tools for clvk, which implements, a LISP-like language for encumbering and releasing funds with smart-contract capabilities.

Set up

Set up your virtual environments

$ python3 -m venv venv
$ . ./venv/bin/activate (windows: venv\Scripts\activate.bat)
$ pip install -e .

If you run into any issues, be sure to check out this section of the wiki

Optionally, run unit tests for a sanity check.

$ pip install pytest
$ py.test tests

Quick examples

The language has two components: the higher level language and the compiled lower level language which runs on the clvk. To compile the higher level language into the lower level language use:

$ run '(mod ARGUMENT (+ ARGUMENT 3))'
(+ 1 (q . 3))

To execute this code:

$ brun '(+ 1 (q . 3))' '2'
5

The Compiler

Basic example

The high level language is a superset of clvk, adding several operators. The main supported operator is mod which lets you define a set of macros and functions, and an entry point that calls them. Here's an example.

(mod (INDEX)
     (defun factorial (VALUE) (if (= VALUE 1) 1 (* VALUE (factorial (- VALUE 1)))))
     (factorial INDEX)
     )

You can copy this to a file fact.clvk, then compile it with run fact.clvk and you'll see output like

(a (q 2 2 (c 2 (c 5 ()))) (c (q 2 (i (= 5 (q . 1)) (q 1 . 1) (q 18 5 (a 2 (c 2 (c (- 5 (q . 1)) ()))))) 1) 1))

You can then run this code with brun, passing in a parameter. Or pipe it using this bash quoting trick:

$ brun "`run fact.clvk`" "(5)"
120

This affirms that 5! = 120.

Auto-quoting of literals

Note that the 1 is not quoted. The compiler recognizes and auto-quotes constant values.

$ run 15
15
$ brun 15
FAIL: not a list 15

Known operators

Besides mod and defun, the compiler has a few more built-in operators:

@

Instead of evaluating 1 to return the arguments, you should use @ in the higher level language. This is easier for humans to read, and calling (f @) will be compiled to 2, etc.

    $ run '@' '("example" 200)'
    ("example" 200)
    
    $ run '(mod ARGS (f (r @)))'
    5

You generally won't need to use @; it's better to use mod and named arguments.

(if)

(if A B C) This operator is similar to lone condition in clvk i, except it actually does a lazy evaluation of either B or C (depending upon A). This allows you to put expensive or failing (like x) operator within branches, knowing they won't be executed unless required.

This is implemented as a macro, and expands out to ((c (i A (q B) (q C)) (a))).

(qq) and (unquote)

(qq EXPR) for expanding templates. This is generally for creating your own operators that end up being inline functions.

Everything in EXPR is quoted literally, unless it's wrapped by a unary unquote operator, in which case, it's evaluated. So

(qq (+ 5 (a))) would expand to (+ 5 (a))

But (qq (+ 5 (unquote (+ 9 10)))) would expand to (+ 5 19) because (+ 9 10) is 19.

And (qq (+ 5 (unquote (+ 1 (a))))) expands to something that depends on what (a) is in the context it's evaluated. (It'd better be a number so 1 can be added to it!)

If you have a template expression and you want to substitute values into it, this is what you use.

Macros

You can also define macros within a module, which act as inline functions. When a previously defined macro operator is encountered, it "rewrites" the existing statement using the macro, passing along the arguments as literals (ie. they are not evaluated).

A Simple Example

(mod (VALUE1 VALUE2)
     (defmacro sum (A B) (qq (+ (unquote A) (unquote B))))
     (sum VALUE1 VALUE2)
     )

When run, this produces the following output:

(+ 2 5)

Compare to the function version:

(mod (VALUE1 VALUE2)
     (defun sum (A B) (+ A B))
     (sum VALUE1 VALUE2)
     )

which produces

(a (q 2 2 (c 2 (c 5 (c 11 ())))) (c (q 16 5 11) 1))

There's a lot more going on here, setting up an environment where sum would be allowed to call itself recursively.

Inline functions

If you want to write a function that is always inlined, use defun-inline.

(mod (VALUE1 VALUE2)
     (defun-inline sum (A B) (+ A B))
     (sum VALUE1 VALUE2)
     )

This produces the much more compact output (+ 2 5).

Inline functions must not be recursive.

A More Complex Example

Here's an example, demonstrating how if is defined.

(mod (VALUE1 VALUE2)
     (defmacro my_if (A B C)
       (qq ((c
	    (i (unquote A)
	       (function (unquote B))
	       (function (unquote C)))
	    (a)))))
     (my_if (= (+ VALUE1 VALUE2) 10) "the sum is 10" "the sum is not 10")
     )

This produces

((c (i (= (+ 2 5) (q 10)) (q (q "the sum is 10")) (q (q "the sum is not 10"))) 1))

which is not much code, for how much source there is. This also demonstrates the general notion that macros (and inline functions) cause much less code bloat than functions. The main disadvantages is that macros are not recursive (since they run at compile time) and they're messier to write.

Metadata

Release files for clvk-tools 0.4.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clvk-tools 0.4.10
File Size Uploaded Provenance Actions
clvk_tools-0.4.10.tar.gz 67.8 kB With provenance Details for clvk_tools-0.4.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clvk-tools 0.4.10
File Interpreter ABI Platform Actions
clvk_tools-0.4.10-py3-none-any.whl Python 3 none any Details for clvk_tools-0.4.10-py3-none-any.whl

Total release size: 103.7 kB

Release files / clvk_tools-0.4.10.tar.gz

Download URL clvk_tools-0.4.10.tar.gz
Size 67.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c9a22acd4bd2e36152f83b407031de7991b31a2c9ce8174de8a4ae3f450dd331
BLAKE2b-256 checksum
How to use checksums
ba1dde990396249281dc63b31e1d9a37a8e0a1e152a4bc50bd1689358ab6f2c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / clvk_tools-0.4.10-py3-none-any.whl

Download URL clvk_tools-0.4.10-py3-none-any.whl
Size 35.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
312744c8936c381bebf2a29346913834677a014dabefda4a4976447de158ba89
BLAKE2b-256 checksum
How to use checksums
adc869d40575fe30fd5e9b74ae93a73ce70136765f696bf7399dab131cde8c9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Security for clvk-tools 0.4.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for clvk_tools-0.4.10.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.10 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page