slurp

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 8 Imported by: 1

README

Slurp

GoDoc Go Report Card Code Change

Slurp is a highly customisable, embeddable LISP toolkit for Go applications.

Why Slurp

I've just received word that the Emperor has dissolved the MIT computer science program permanently.

Slurp is for developers who want to design and embed an interpreted language inside of a Go program.

Slurp provides composable building-blocks that make it easy to design a custom lisp, even if you've never written an interpreter before. Since Slurp is written in pure Go, your new language can be embedded into any Go program by importing it — just like any other library.

NOTE: Slurp is NOT an implementation of a particular LISP dialect.

It provides pieces that can be used to build a LISP dialect or can be used as a scripting layer.

Slurp is designed around three core values:

  1. Simplicity: The library is small and has few moving parts.
  2. Batteries Included: There are no external dependencies and little configuration required.
  3. Go Interoperability: Slurp can call Go code and fully supports Go's concurrency features.

We hope that you will find Slurp to be powerful, useful and fun to use. We look forward to seeing what you build with it!

Features

  • Highly customizable, safe and powerful reader/parser through a read table (Inspired by Clojure) (See Reader)
  • Immutable datatypes including: nil, bool, string, int & float, character, keyword, symbol, list, vector & map.
  • Multiple number formats supported: decimal, octal, hexadecimal, radix and scientific notations.
  • Full unicode support. Symbols, keywords etc. can include unicode characters (Example: find-δ, π etc.) and 🧠, 🏃 etc. (yes, smileys too).
  • Character Literals with support for:
    1. simple literals (e.g., \a for a)
    2. special literals (e.g., \newline, \tab etc.)
    3. unicode literals (e.g., \u00A5 for ¥ etc.)
  • Full interoperability with Go: call native Go functions/libraries, and manipulate native Go datatypes from your language.
  • Support for macros.
  • Easy to extend. See Wiki.
  • Tiny & powerful REPL package.
  • Zero dependencies (outside of tests).

Usage

Slurp requires Go 1.14 or higher. It can be installed using go get:

go get -u github.com/spy16/slurp

What can you use it for?

  1. Embedded script engine to provide dynamic behavior without requiring re-compilation of your application (example).
  2. Business rule engine exposing specific, composable rules (example).
  3. To build DSLs.
  4. To build your own LISP dialect (example).

Refer ./examples for more usage examples.

Documentation

In addition to the GoDocs, we maintain in-depth tutorials on the GitHub wiki. The following pages are good starting points:

  1. Getting Started
  2. Customizing Syntax
  3. Customizing Evaluation

Documentation

Overview

Package slurp provides Interpreter that composes builtin implementations of Env, Analyzer and Reader that supports a working LISP dialect.

Index

Constants

This section is empty.

Variables

View Source
var ErrParseSpecial = errors.New("invalid special form")

ErrParseSpecial is returned when parsing a special form invocation fails due to malformed syntax.

Functions

func Func added in v0.2.0

func Func(name string, v interface{}) core.Invokable

Func converts the given Go func value to a slurp Invokable value. Panics if the given value is not of Func kind.

func Value added in v0.2.0

func Value(v interface{}) core.Any

Value converts the given arbitrary Go value into a slurp compatible value type with well defined behaviours. If no known equivalent type is found, then the value is returned as is.

Types

type Interpreter added in v0.2.0

type Interpreter struct {
	// contains filtered or unexported fields
}

Interpreter represents a Slurp interpreter session.

func New

func New(opts ...Option) *Interpreter

New returns a new slurp interpreter session.

func (*Interpreter) Bind added in v0.2.0

func (ins *Interpreter) Bind(vals map[string]core.Any) error

Bind can be used to set global bindings that will be available while executing forms.

func (*Interpreter) Eval added in v0.2.0

func (ins *Interpreter) Eval(form core.Any) (core.Any, error)

Eval performs syntax analysis of the given form to produce an Expr and evaluates the Expr for result.

func (*Interpreter) EvalStr added in v0.2.0

func (ins *Interpreter) EvalStr(s string) (core.Any, error)

EvalStr reads forms from the given string and evaluates it for result.

type Option

type Option func(ins *Interpreter)

Option values can be used with New() to customise slurp instance during initialisation.

func WithAnalyzer

func WithAnalyzer(a core.Analyzer) Option

WithAnalyzer sets the analyzer to be used by the slurp instance for syntax analysis and macro expansions. If nil, uses builtin analyzer with standard special forms.

func WithEnv added in v0.2.0

func WithEnv(env core.Env) Option

WithEnv sets the environment to be used by the slurp instance. If env is nil, the default map-env will be used.

Directories

Path Synopsis
Package builtin provides builtin value types and implementations of different Slurp core interfaces (e.g., Analyzer, Exprs etc.)
Package builtin provides builtin value types and implementations of different Slurp core interfaces (e.g., Analyzer, Exprs etc.)
Package core defines the core contracts of slurp.
Package core defines the core contracts of slurp.
examples
conj
Package main builds on `simple` to demonstrate a naive implementation of Clojure's conj.
Package main builds on `simple` to demonstrate a naive implementation of Clojure's conj.
Package reader implements a highly customizable and generic reader, reader-macros for primitive runtime types and reader-macro factories for collection types like vector, map, set.
Package reader implements a highly customizable and generic reader, reader-macros for primitive runtime types and reader-macro factories for collection types like vector, map, set.
Package repl provides facilities to build an interactive REPL using slurp.
Package repl provides facilities to build an interactive REPL using slurp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL