Schooner - An embeddable r7rs scheme

Schooner is a sandboxed Scheme interpreter you embed in an Elixir app (like Lua/Luerl but with more parentheses). It targets r7rs-small minus its mutable operations — no set!, set-car!, vector-set!, etc. — which keeps the value model immutable and friendly to BEAM idioms. The host hands a script source to Schooner.eval/2, gets back a tagged Elixir term, and resource-bounds the work with the standard process tools (:max_heap_size, Task.shutdown/2).

alias Schooner.Host

env =
  Schooner.Environment.new(
    libraries: [
      Host.library(
        primitives: [
          {"shout", 1, fn [msg] ->
             text = msg |> Host.to_string!(op: "shout") |> String.upcase()
             Host.string(text <> "!")
           end}
        ]
      )
    ]
  )

Schooner.eval(~s|(import (scheme base)) (shout (string-append "hello, " "world"))|, env)
# => {:ok, "HELLO, WORLD!"}

It implements most of r7rs-small, the deviations are listed in the documentation.

8 Likes

As someone who grew up with Maclisp and John McCarthy I find this unreasonably exciting. And much more of a mental model that works for me than Lua. Thanks for making this happen - I’ll be sure to give it a spin on something. In fact I’ll just have to invent something so I can use it :slight_smile:

I still think the Moonual is one of the best technical manuals ever written. It was my reference during many late night session on the System-M Multics system. Multics, Maclisp and Emacs were probably why I got hooked on computing.

5 Likes