slang

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

README

Slang

Slang (short for Sabre Lang) is a tiny LISP built using Sabre.

Installation

  1. Download a release from Releases for your target platfomr.
  2. Extract files and add extraction path to PATH variable.

Usage

  1. slang for REPL
  2. slang -e "(+ 1 2 3)" for executing string
  3. slang -f "examples/simple.lisp" for executing file.

If you specify both -f and -e flags, file will be executed first and then the string will be executed in the same scope and you will be dropped into REPL. If REPL not needed, use -norepl option.

Documentation

Overview

Package slang (short for Sabre lang) provides a tiny LISP dialect built using factilities provided by Sabre. See New() for initializing Slang and using it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(args ...float64) float64

Add adds given floating point numbers and returns the sum.

func BindAll

func BindAll(scope sabre.Scope) error

BindAll binds all core functions into the given scope.

func Divide

func Divide(first float64, args ...float64) float64

Divide returns the product of given numbers.

func Gt

func Gt(base float64, args ...float64) bool

Gt returns true if the given args are monotonically decreasing.

func GtE

func GtE(base float64, args ...float64) bool

GtE returns true if the given args are monotonically decreasing or all equal.

func Implements

func Implements(v interface{}, t sabre.Type) (bool, error)

Implements checks if given value implements the interface represented by 't'. Returns error if 't' does not represent an interface type.

func Lt

func Lt(base float64, args ...float64) bool

Lt returns true if the given args are monotonically increasing.

func LtE

func LtE(base float64, args ...float64) bool

LtE returns true if the given args are monotonically increasing or are all equal.

func MacroExpand added in v0.4.0

func MacroExpand(scope sabre.Scope, f sabre.Value) (sabre.Value, error)

MacroExpand is a wrapper around the sabre MacroExpand function that ignores the expanded bool flag.

func MakeString

func MakeString(vals ...sabre.Value) sabre.Value

MakeString returns stringified version of all args.

func Multiply

func Multiply(args ...float64) float64

Multiply multiplies the given args to 1 and returns the result.

func Printf

func Printf(format string, args ...interface{}) error

Printf is an alias for fmt.Printf which ignores the return values.

func Println

func Println(args ...interface{}) error

Println is an alias for fmt.Println which ignores the return values.

func Realize

func Realize(seq sabre.Seq) *sabre.List

Realize realizes a sequence by continuously calling First() and Next() until the sequence becomes nil.

func Sub

func Sub(x float64, args ...float64) float64

Sub subtracts args from 'x' and returns the final result.

func ThreadFirst

func ThreadFirst(scope sabre.Scope, args []sabre.Value) (sabre.Value, error)

ThreadFirst threads the expressions through forms by inserting result of eval as first argument to next expr.

func ThreadLast

func ThreadLast(scope sabre.Scope, args []sabre.Value) (sabre.Value, error)

ThreadLast threads the expressions through forms by inserting result of eval as last argument to next expr.

func Throw

func Throw(scope sabre.Scope, args ...sabre.Value) error

Throw converts args to strings and returns an error with all the strings joined.

func ToType

func ToType(val sabre.Value, to sabre.Type) (sabre.Value, error)

ToType attempts to convert given sabre value to target type. Returns error if conversion not possible.

func TypeOf

func TypeOf(v interface{}) sabre.Value

TypeOf returns the type information object for the given argument.

Types

type Slang

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

Slang represents an instance of slang interpreter.

func New

func New() *Slang

New returns a new instance of Slang interpreter.

func (*Slang) Bind

func (slang *Slang) Bind(symbol string, v sabre.Value) error

Bind binds the given name to the given Value into the slang interpreter context.

func (*Slang) BindGo

func (slang *Slang) BindGo(symbol string, v interface{}) error

BindGo is similar to Bind but handles conversion of Go value 'v' to sabre Value type.

func (*Slang) CurrentNS

func (slang *Slang) CurrentNS() string

CurrentNS returns the current active namespace.

func (*Slang) Eval

func (slang *Slang) Eval(v sabre.Value) (sabre.Value, error)

Eval evaluates the given value in Slang context.

func (*Slang) Parent

func (slang *Slang) Parent() sabre.Scope

Parent always returns nil to represent this is the root scope.

func (*Slang) ReadEval

func (slang *Slang) ReadEval(r io.Reader) (sabre.Value, error)

ReadEval reads from the given reader and evaluates all the forms obtained in Slang context.

func (*Slang) ReadEvalStr

func (slang *Slang) ReadEvalStr(src string) (sabre.Value, error)

ReadEvalStr reads the source and evaluates it in Slang context.

func (*Slang) Resolve

func (slang *Slang) Resolve(symbol string) (sabre.Value, error)

Resolve finds the value bound to the given symbol and returns it if found in the Slang context and returns it.

func (*Slang) SwitchNS

func (slang *Slang) SwitchNS(sym sabre.Symbol) error

SwitchNS changes the current namespace to the string value of given symbol.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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