Shen
About

Shen is a portable functional programming language by Mark Tarver. It is the successor to the award-winning Qi language, with the added goal of being highly portable across platforms.

More information is available on the official website.

Pattern Matching
(define filter
  _ []       -> []
  F [X | Xs] -> [X | (filter F Xs)] 
                where (F X)
  F [_ | Xs] -> (filter F Xs))

(define element?
  _ []      -> false
  X [X | _] -> true
  X [_ | Y] -> (element? X Y))
Backtracking
(define walk
  _ []      <- (fail)
  F [X | _] -> X where (F X)
  F [_ | Y] -> (walk F Y))
Lambda Calculus Consistency
(define y-combinator
  F -> ((/. X (X X))
        (/. X (F (/. Y ((X X) Y))))))
Lazy Evalution
(let F (freeze (output "Hello!"))
  (thaw F))

> "Hello!"
Optional Type Checking
(tc +)

(define map
  {(A --> B) --> (list A) --> (list B)}
  _ []       -> []
  F [X | Xs] -> [(F X) | (map F Xs)])

(map (+ 1) ["a" "b" "c"])

> type error
Configurable Type Rules
(datatype maybe-type

  _____________________
    none : (maybe A);

         X : A;
  _____________________
  (some X) : (maybe A);

      M : (maybe A);
  _____________________
     (unwrap M) : A;)
Integrated Logic Engine
(defprolog member
  X [X | _] <-- ;
  X [_ | Y] <-- (member X Y);)

(prolog?
  (member X [1 2 3])
  (member X [3 4 5])
  (return X))

> 3
Built-in Compiler-Compiler
(define bit?
  B -> (element? B [0 1]))

(defcc <b>
  B <b> := [B | <b>] where (bit? B);
  B     := [B] where (bit? B);)
Unique Macros
(defmacro infix-macro
  [X + Y] -> [+ X Y]
  [X * Y] -> [* X Y])

There are implementations of Shen for most platforms. Some have fallen out of date and could use support to reach Certified status and stay current.

An implementation is considered Certified if it passes the test suite included with the kernel sources.

To port Shen to a new platform, see the porting guide. You can submit a pull request to get it added here.

Platform URL
Active Ports
Common Lisp Common Lisp (by Mark Tarver)
Scheme tizoc/shen-scheme
Experimental ports (Windows testing needed)
Go pyrex41/shen-go (bytecode VM, kernel 41.2) — fork of tiancaiamao/shen-go
LuaJIT pyrex41/shen-lua (kernel 41.2)
Rust pyrex41/shen-rust (tree-walker + bytecode VM + AOT-compiled kernel, kernel 41.2)
Julia pyrex41/shen-julia (kernel 41.2)
Swift pyrex41/shen-swift (kernel 41.2)
Inactive Ports
Common Lisp Shen-Language/shen-cl
C otabat/shen-c
CLR rkoeninger/ShenSharp
Emacs Lisp deech/shen-elisp
Erlang sborrazas/shen-erl
Go tiancaiamao/shen-go
Haskell mthom/shentong
Java otabat/shen-jvm
Ruby gregspurrier/shen-ruby
Truffle ragnard/shen-truffle
Wasp Lisp doublec/shen-wasp
JavaScript rkoeninger/ShenScript
JavaScript gravicappa/shen-js
C++ wehu/ShenCPP
Clojure hraberg/shen.clj
Java hraberg/Shen.java
Python gravicappa/shen-py
Python yminer/pyshen

Bifrost is an experimental cross-implementation test harness and command-line front door for Shen. It can run the same program or expression on a selected port, compare behavior across ports, and report conformance differences.

Ratatoskr is an experimental tree-shaker for Shen programs. It removes unreachable kernel code and builds standalone artifacts for supported hosts, including Common Lisp, LuaJIT, Go, JavaScript, Rust, Julia, Scheme, and Swift.

Both projects are under active development and need broader testing, especially on Windows. Please treat their current port matrix and standalone-artifact support as experimental and report portability issues in their repositories.

The Shen Open Source Kernel is authored in Shen itself and hosted on GitHub. Bug reports and suggested enhancements are welcome!