Skip to content

deech/shen-elisp

Repository files navigation

Shen Elisp

Shen Elisp

This is an implemenatation of the Shen programming language in Elisp. The end goal is to provide:

  1. an easy way to play with Shen with no other installation hassle (assuming you use Emacs).
  2. a first-class development experience when writing Shen. The idea is that an editor that understands the code can be much more helpful than one that does not. To this end the roadmap involves a full gamut of source code introspection and debugging tools.

Installation

This port is completely self-contained. However since it leans heavily on the relatively new lexical-binding feature Emacs 24.3 or above is required.

Also note the installation will emit a large number of byte-compiler warnings. Nothing to worry about but they are annoying and my attempts to silence them have thus far failed.

Manual Download and Setup

Download shen-elisp onto your system somewhere.

;; add this to your init file in an appropriate location
(add-to-list 'load-path "~/path/to/shen-elisp/")
(require 'shen-elisp)
(require 'shen-repl)

You should really byte-compile the code; running the following snippet should do it:

(byte-recompile-directory "~/path/to/shen-elisp/" 0 t)

Quelpa

To install the package directly from Github using `quelpa` tool:

(quelpa
   '(shen-elisp
      :repo "deech/shen-elisp"
      :fetcher github
      :files ("shen*.el"))
   :upgrade 't)

Since this is alpha software the :upgrade 't at the end always pulls the latest version.

If you are a Spacemacs user you can do the following:

  1. Add the following to the dotspacemacs-additional-packages variable:
dotspacemacs-additional-packages '(
                                   (shen-elisp
                                    :location (recipe :repo "deech/shen-elisp"
                                                      :fetcher github
                                                      :files ("shen*.el"))
                                    :upgrade 't)
                                   )
  1. SPC : spacemacs/emacs-reload
  2. Invoke shen/repl after installation has completed.

It also uses the `quelpa` tool underneath.

Running

Once the package is installed the Shen REPL should start with:

M-x shen/repl

Getting Started

To get started here is a sample REPL session showing how to

  • define a function,
  • toggle typechecking
  • evaluate an expression and
  • load a sample file

This session assumes a file called add.shen in the tmp directory containing:

(define add
  { number --> number }
  X -> (+ X 1))
Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, Shen 19.2
running under Elisp, implementation: Elisp
port 1.7 ported by Aditya Siram

(0-) (define say-hello-to Name -> (@s "Hello " Name))
say-hello-to

(1-) (say-hello-to "World")
"Hello World"

(2-) (tc +)
true

(3+) (map (/. X (+ 1 X)) [1 2 3])
[2 3 4] : (list number)

(4+) (load "/tmp/add.shen")

add : (number --> number)
run time: 0 secs

typechecked in 93 inferences
loaded : symbol

(5+) (add 1)
2 : number

(6+) (add "some string")

type error

To learn more about Shen see the the website.

Caveats

The port is still alpha so some REPL features which you might expect are not available. This is being addressed. Starting with the most unpleasant:

  • multi-line definitions are not allowed in the REPL. If you hit Return before completing a function definition, for example, the REPL spits out a cryptic error with a list of bytes.
  • Ctrl-G does not work. This leaves the REPL in a state where the only thing you can do is delete the buffer, followed by M-x shen/repl. Any functions/datatypes defined in the REPL, however are saved.
  • When expressions/functions etc are compiled to Elisp the byte-compiler spits out warnings that may steal focus away from the REPL.
  • The REPL still emits Elisp errors on occasion.
  • comments are not supported in the REPL.

Documentation

This port is a literate program written using org-babel so the complete source is documented in shen-elisp.org. It has also been exported to shen-elisp.html for easy browsing.