Skip to content


Subversion checkout URL

You can clone with
Download ZIP
神.clj | Shen for Clojure. Shen is a portable functional programming language by Mark Tarver.
Clojure Shell
branch: master
Failed to load latest commit information.
docs @ bdbfd5b Marginalia for 0.1.4
shen Downgrading to Shen 8
src/shen Fixing bug introduced in boolean?
test/shen Fix for Mark's bug where a named fn returns a lamba which should be e…
.gitignore Launch script should use right Clojure version
.gitmodules added gh-pages as submodule
README Shen 4.1
README.markdown Remove Gittip link from this, as I don't expect to spend much time here
build Shen 5.0
dist 0.1.4 + docs
license.txt Initial commit
project.clj Clojure 1.5.0
shen.clj Launch script should use right Clojure version


神.clj | Shen for Clojure

Shen is a portable functional programming language by Mark Tarver that offers

  • pattern matching,
  • λ calculus consistency,
  • macros,
  • optional lazy evaluation,
  • static type checking,
  • an integrated fully functional Prolog,
  • and an inbuilt compiler-compiler.

See also:

This Clojure Port

[shen.clj "0.1.6"] | Marginalia

Is a work in progress. Passes the Shen 6.0 test suite.

Uses Leiningen 2 to build. The script build is used for full, repeatable builds.

To run the REPL:

Standalone release

java -jarshen.clj-0.1.6-standalone.jar


lein trampoline run

# If shen.clj already exists, for readline support:
lein repl

# java:
java -cp lib/clojure-1.4.0.jar:shen.clj-0.1.6.jar shen



Shen 2010, copyright (C) 2010 Mark Tarver, version 7.1
running under Clojure, implementation: Clojure 1.4.0 [jvm 1.8.0-ea]
port 0.1.6 ported by Håkan Råberg

(0-) (define super
       [Value Succ End] Action Combine Zero ->
         (if (End Value)
             (Combine (Action Value)
                      (super [(Succ Value) Succ End]
                             Action Combine Zero))))

(1-) (define for
       Stream Action -> (super Stream Action do 0))

(2-) (define filter
       Stream Condition ->
         (super Stream
                (/. Val (if (Condition Val) [Val] []))

(3-) (for [0 (+ 1) (= 10)] print)

(4-) (filter [0 (+ 1) (= 100)]
             (/. X (integer? (/ X 3))))
[0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60... etc]

The Shen Test Suite

The Shen test suite is now running, slowly but surely:

[... loads of output ...]
passed ... 146
failed ...0
pass rate ...100%


run time: 16.713 secs

The suite can be run via:

yes | lein trampoline run -m shen.test

The benchmarks can be run via:

JAVA_OPTS="-Xss6m" lein run -m shen.benchmarks
  • Performance is not a goal for 0.1.x, but some tuning has been made to ease development.


神, define, prolog? and defprolog macros

Instead of using Shen's reader, you can embed Shen directly in Clojure using these macros. For simplicity, all Shen code lives and is evaluated in the shen namespace for now (this will likely change).

; shen.test/
(define for
  Stream Action -> (super Stream Action do 0))

; shen.test/printer
 (cons 1 2))
"[1 | 2]"

 (@p 1 2))
"(@p 1 2)"

; shen.test/partials
 ( X Y (+ X Y)) 2))

As can be seen λ stands in for /. in Shen to avoid Clojure reader macros. @p, @s and @v are converted from Clojure deref to their Shen symbols. Characters, like \;, will also be converted to symbols.

Note that [] in Shen are lists, and not Clojure vectors. A Clojure vector with a count of 2 is used to represent a cons pair internally.

See shen.test for more examples.

Shen calling Clojure


Shen code can (but this is not very tested) access clojure.core, which is required as c:

    (for [0 (+ 1) (= 10)] print)))
Shen FFI

Shen FFI can be used for (basic) interaction with Clojure from Shen:

(load "ffi.shen")
(ffi clj (@p shen->clj send-clj) (@p clj->shen receive-clj))

; Clojure map entries as Shen lists
(call-ffi clj *clojure-version*)
[[:major | 1] [:minor | 4] [:incremental | 0] [:qualifier | nil]]

; Calling Java
(call-ffi clj (System/currentTimeMillis))

More advanced mixing and requiring of Clojure packages isn't supported yet.


This port, while aiming to conform closely (and hopefully fully) to the Shen specification, has its primary goal to enable Shen's power in real world Clojure code.

  • Shen / Clojure interop:
    • Shen packages as namespaces?
    • Hiding Shen internal names.
    • Bringing smaller parts of Shen goodness back into Clojure: predicate dispatch, pattern matching, prolog. Maybe even the type system.
    • Ensuring Shen can call Clojure/Java properly.
  • Future / Questions
    • More TCO than implicit recur for KLambda?
    • Making Shen as lazy as its host?
    • Existing Shen libraries and portability?
    • ClojureScript.
    • overwrite.clj - rewriting more parts of Shen into Clojure if interop or performance requires it.
  • Shen in 15 minutes as smoke test for the REPL

The other port, Shen to Clojure


Shen, Copyright © 2010-2012 Mark Tarver

shen.clj, Copyright © 2012 Håkan Råberg

YourKit is kindly supporting open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications. Take a look at YourKit's leading software products: YourKit Java Profiler and YourKit .NET Profiler.

Something went wrong with that request. Please try again.