shen

A port of the Shen programming language for Chicken Scheme.

  1. shen
    1. Shen
    2. Egg Author
    3. Shen Documentation
    4. Egg Source Code
    5. Chicken Shen Usage
      1. Starting the REPL from a terminal
    6. Calling Shen from Scheme
    7. Example Shen Code
      1. Symbols
      2. Basic List processing
      3. Procedures
      4. YACC
      5. Prolog
      6. Type System
      7. Calling Scheme from Shen
    8. About this egg
      1. License
      2. Dependencies
      3. Versions

Shen

Shen is a hosted language that comes with a macro system, optional type system based on sequent calculus, pattern matching, λ calculus consistency, optional lazy evaluation, an integrated Prolog and compiler-compiler.

This egg comes with a standalone binary chicken-shen that provides a REPL and a library to use Shen inside Scheme.

Egg Author

David Ireland (djireland79 at gmail dot com)

Shen Documentation

The best source of information for Shen programming is The Book of Shen, Logic, Proof and Computation and the Shen web site .

Egg Source Code

Chicken-Shen

Chicken Shen Usage

Usage for the standalone binary for running a REPL or loading a file or string is here:

$ chicken-shen -h
 
Usage: shen [options] [...args...]
  -h, --help          : Prints help and exits
  -l, --load <file>   : Loads Shen <file>
  -e, --eval <string> : Evaluates <string>
  -r, --repl          : Run the REPL, even if -l or -e are provided
Any additional arguments are passed to the Shen system in
the variable shen-chicken.*argv*

Starting the REPL from a terminal

$ chicken-shen -r
Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, Shen 21.1
running under Scheme, implementation: Chicken
port 0.1 ported by David Ireland

(0-) 

Calling Shen from Scheme

[procedure] (run-shen)

Runs the REPL inside Chicken Scheme

[procedure] (read-file FILE)

Reads and loads a Shen file

[procedure] (read-from-string STRING)

Reads and loads a string containing Shen code.

 (import (prefix shen shen:))
 
 ;;; Load file example
 (shen:read-file "foo.shen")

 ;;; Evaluate string
 (shen:read-from-string "(define foo 0 -> 1 1 -> 0)")
 (shen:read-from-string "(foo 0)") ;;; Should return 1
 

Example Shen Code

Symbols

Unlike Chicken Scheme symbols are implicitly quoted thus no ' is needed.

(0-) HI
HI

Basic List processing

Lists in Shen are enclosed with [ ] for example:

(12-) [1 2 3]
(13-) (head [1 2 3])
1
(14-) (cons 1 [])
[1]
(15-) [1 2 | [3]]
[1 2 3]

Procedures

Procedures are defined using a pattern matching. For example:

(define factorial
        0 -> 1
        X -> (* X (factorial (- X 1))))
(define total
        [] -> 0
        [X | Y] -> (+ X (total Y)))
(define triples
        [] -> []
        [W X Y | Z] -> [[W X Y] | (triples Z)])

YACC

Shen has an internal YACC (yet another compiler compiler)

(defcc <binary?>
X <binary?> := true where (element? X [0 1]);
X := true where (element? X [0 1]);
<e> := false;)

Prolog

Shen also has an embedded Prolog for logic programming

(defprolog member
xxX [X | _] <--;
xxX [_ | Y] <-- (member X Y);)

Type System

The type system is optional and disabled by default. It can be enabled using:

 
(0-) (tc +)
true

(1+) 5
5 : number

(2+) "ABC"
"ABC" : string

(3+) (+ 1 1)
2 : number

and off with:

 
(4+) (tc -)
false : boolean

(5-) 5
5

(6-) "ABC"
"ABC"

(7-) (+ 1 1)
2

Calling Scheme from Shen

Calling native Chicken procedures is done by prefixing 'lisp' to the procedure name. An example of calling Chicken's print is given below.

Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, Shen 21.1
running under Scheme, implementation: Chicken
port 0.1 ported by David Ireland

(0-) (lisp.print "Hello World")
Hello World
#<unspecified>

(1-)

About this egg

License

BSD Clause 3

Dependencies

srfi-1 srfi-13

Versions