An experimental core library supporting π-Calculus in Clojure
Clojure Makefile
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

張 zhang

Build Status Dependencies Status Clojars Project

An implementation of the Erlang process model in Clojure core.async

Table of Contents


The zhang project aims to create a very minimal library in Clojure, built on core.async, that, as closely as possible, implements the Erlang process model. It does not aim to provide any opionions about (and thus even less, any implementations for) either message structure or infrastructure necessary for supporting remote processes.

As such, zhang should be a general-purpose, low-level library for the JVM ideally suited for anyone who is interested in building systems with functions that offer capabilities of communication.

Desired features include:

  • quickly creating and destroying processes
  • safe "crashing" of a process
  • quickly sending messages between processes
  • support large numbers of processes
  • shared nothing
  • message passing
  • function mailboxes
  • ordered save queues
  • timeouts
  • pattern matching (core.match) and selective receive
  • process registration hooks (in order to support arbitrary publishing mechanisms)

How processes register with a publication mechanism and how they communicate with each other (either locally or remotely) is beyond the scope of the zhang library. As an example, the Clozhang library (which intends to use zhang) will provide implementation details for these -- it just needs an underlying process model amenable to its implementation goals.


Documentation for zhang is regularly generated and made available here:

Related documentation:






The zhang project came about, like so many software projects, through the time-honored process of yak-shaving. The particular yak that spawned zhang was associated with the Clojang project, which in turn was a yak-shaving response to Erlang's JInterface (in particular the desire to have a low-level Clojure-idiomatic wrapper for JInterface).

One of the issues that arose when working on Clozhang was the number of threads created when connecting nodes and the lack of light-weight (non-OS) processes for creating Clojure servers that communicate with Erlang processes. This limits the number of nodes that can be created and doesn't really allow programmers to fully explore the power of Erlang's processing model on the JVM. (In all fairness, this was never the intent of JInterface; instead, it is a Java translation of Erlang Ports, allowing basic interoperability between Java and Erlang programs.)

To work around this, we wanted to create servers in Clojure using the core.async library, which brings light-weight, non-OS processes to Clojure programmers. The core.async library was inspired by Tony Hoare's work on communicating sequential processes (CSP) originally described in a 1978 paper. That paper (and significant subsequent work) influenced the design of concurrency in the C# language as well as the concurrency model used in the Go programming language. Both of these heavily influenced the design and implementation of core.async in Clojure.

While CSP offers a time-honored and performance-proven approach for local process execution, it doesn't offer one for distribted execution. As such, Clojure doesn't have a native solution for distributed process execution and communication either. This is where the π-calculi come in.

[Add notes about the process calculi here.]

And this is the purpose of zhang: to provide one possible solution to just this gap.

Akka/Okku & Quasar/Pulsar


A Note on the Name

The zhang project takes it's name from Zhang Heng, who approximated π early in the first millennium (Han Dynasty). This is an obscure pun, since the Erlang process model could be, in some ways, interpreted as an approximation of the π-calculus. In addition to being a mathematician, Zhang Heng was also a poet, astronomer, and engineer -- a wonderful patron for a software project!


Copyright © 2016-2017 Duncan McGreggor

Distributed under the Apache License, Version 2.0.