Skip to content
The Lisp interpreter that can be embedded within a scala application.
Scala
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
src
.gitignore
LICENSE.txt
README.md
build.sbt
scalastyle-config.xml

README.md

sclsp

The Lisp interpreter that can be embedded within a scala application.

Features

  • Can replace the default parser with your owns.

  • Can add your own operators that are implemented by scala on the interpreter.

    • By default, available operators are in below.
    CLICK HERE TO EXPAND
    • lambda
    • car
    • cdr
    • cons
    • list
    • quote
    • '
    • define
    • if
    • ==
    • <=
    • <
    • >
    • >=
    • +
    • -
    • *
    • /
    • and
    • or
    • not
    • eq?
    • atom?
    • begin
    • exit
    • print
    • set!
    • while
  • Can replace the default data store for variables with your owns.

  • Lexical closure.

  • If interpretation is stopped by an error, the result object provides reason, stack trace, and position in code.

Usage

  • Specs
  • Sample codes
    • This samples contain
      • A simple example of embedding sclsp in a scala application.
      • A sample of REPL implementation.
      • Implementing a JavaScript subset by replace the default sclsp parser with the JavaScript parser.
      • An example of an implementation of sharing variables with remote process.

Getting started

Adding dependency in your project

Write this lines in your build.sbt.

resolvers += "Sclsp Maven Repository" at "http://yukihito.github.io/sclsp"
libraryDependencies += "com.yukihitoho" % "sclsp_2.12" % "0.1"

Use interpreter in your code.

Import the DefaultInterpreter.

import com.yukihitoho.sclsp.implementations.DefaultInterpreter

Prepare a string that contains the source code.

  val src: String =
    """
      |(begin
      |  (define factorial
      |    (lambda (n)
      |      (if (eq? n 1)
      |        1
      |        (* n (factorial (- n 1))))))
      |  (factorial 5))
    """.stripMargin

Specify the source code and the file name to Interpreter#interpret.

println(DefaultInterpreter.interpret(src, "a-dummy-file-name.scm"))

Run your app, then you will see the output like below.

Right(NumberValue(120.0))

A simple sample code about this section is here.

If you need more examples, check Specs or Sample codes.

You can’t perform that action at this time.