xlisp

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

README

Xlisp

Simple lisp written in go using Sabre. Xlisp is a DSL for tview library.

Usage

  1. xlisp for REPL
  2. xlisp -e "(+ 1 2 3)" for executing string
  3. xlisp sample.lisp for executing file.

Documentation

Xlisp is highly inspired by Clojure with their syntax and semantics but it's implemented in Go programming language. Some of the functions from clojure have been implemented in xlisp.

Example

First you have to compile the xlisp.

$ make

Then, you can run this example using bin/xlisp example/sample.lisp

(def app (tview/new-app))
(def text-view (tview/new-textview))

(def sample-text "Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.
                 Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.
                 Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps. Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line")

(text-view.SetWordWrap true)
(text-view.SetBorder true)
(text-view.SetTitle "This is just an example")
(text-view.SetText sample-text)
(app.SetRoot text-view true)

; main loop
(app.Run)

Then it will fill up your terminal with box and texts. You can ctrl + c to cancel the application.

terminal

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppSetBeforeDrawFunc added in v0.7.0

func AppSetBeforeDrawFunc(scope sabre.Scope) interface{}

func AppSetInputCapture added in v0.7.0

func AppSetInputCapture(scope sabre.Scope) interface{}

func BindAll

func BindAll(scope sabre.Scope) error

BindAll binds all core functions into the given scope.

func Case

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

Case implements the switch case construct.

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 ListAddItem added in v0.7.0

func ListAddItem(scope sabre.Scope) interface{}

TODO wrap all functions in tview library that requires callback

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

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 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 Random added in v0.7.0

func Random(max int) int

func Read added in v0.7.0

func Read(prompt string) (string, error)

Reads from stdin and returns string

func ReadFile added in v0.7.0

func ReadFile(name string) (string, error)

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 Shuffle added in v0.7.0

func Shuffle(seq sabre.Seq) sabre.Seq

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(to sabre.Type, val sabre.Value) (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 Any

type Any interface{}

func Add

func Add(args ...Any) Any

Add adds given floating point numbers and returns the sum.

func Divide

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

Divide returns the product of given numbers.

func Multiply

func Multiply(first Any, args ...Any) Any

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

func Sub

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

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

type Atom added in v0.7.0

type Atom struct {
	Val sabre.Value
	// contains filtered or unexported fields
}

func (*Atom) Eval added in v0.7.0

func (a *Atom) Eval(_ sabre.Scope) (sabre.Value, error)

func (*Atom) GetVal added in v0.7.0

func (a *Atom) GetVal() sabre.Value

func (*Atom) String added in v0.7.0

func (a *Atom) String() string

func (*Atom) UpdateState added in v0.7.0

func (a *Atom) UpdateState(scope sabre.Scope, fn sabre.Invokable) (sabre.Value, error)

type Xlisp

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

xlisp instance

func New

func New() *Xlisp

returns new xlisp instance

func (*Xlisp) Bind

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

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

func (*Xlisp) BindGo

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

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

func (*Xlisp) CurrentNS

func (slang *Xlisp) CurrentNS() string

CurrentNS returns the current active namespace.

func (*Xlisp) Eval

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

Eval evaluates the given value in Slang context.

func (*Xlisp) Parent

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

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

func (*Xlisp) ReadEval

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

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

func (*Xlisp) ReadEvalStr

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

ReadEvalStr reads the source and evaluates it in Slang context.

func (*Xlisp) Resolve

func (slang *Xlisp) 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 (*Xlisp) SwitchNS

func (slang *Xlisp) 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