ell

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: Apache-2.0 Imports: 23 Imported by: 2

README

ell

ℒ (ell) is a LISP dialect, with semantics similar to Scheme, but adds Keywords, Structs, user-defined Types, and other features.

Getting started

The reference version of Ell is written in Go. If you have Go installed on your machine, you can install Ell easily:

go get github.com/boynton/ell/...

This installs the self-contained binary into $GOPATH/bin/ell. Ell loads its library files from locations defined by the ELL_PATH environment variable. If that variable is not defined, the default path is ".:$HOME/lib/ell:$GOPATH/src/github.com/boynton/ell/lib".

If you have a .ell file in your home directory, it will get loaded and executed when running ell interactively.

$ ell
[loading /Users/lee/.ell]
ell v0.2
?

The ? prompt is the Read-Eval-Print-Loop (REPL) for ell, waiting for your input. Entering CTRL-D will end the REPL and exit back to the shell.

Primitive types

Ell defines a variety of native data types, all of which have an external textual representation. This data notation is called EllDN, and is a superset of JSON.

? 5.2
= 5.2
? "five"
= "five"
? true
= true
? null
= null
? [1, 2, 3]
= [1 2 3]
? {"x": 1, "y": 2}
= {"x" 1 "y" 2}

The basic JSON types are supported as you would expect. Although JSON-compatible format is accepted for vectors (JSON arrays) and structs (JSON objects), the canonical form for both does not include separating commas.

EllDN also introduces keywords, types, symbols, and lists to the syntax.

Keywords are symbolic identifiers that end in a colon (':'), and types are symbolic identifiers surrounded by angle brackets ('<' and '>'). Both are self-evaluating, but used for different purposes:

? foo:
= foo:
? <string>
= <string>

Symbols are identifiers that form variable references in Ell, so are interpreted differently. Lists are ordered sequences, and form the syntax for function (or macro) calls in Ell:

? length				; a reference to the `length` variable
= #[function length]
? (length "foo")        ; a function call to the length function
= 3

Most types evaluate to themselves. Since symbols and lists do not evaluate to themselves, they must be quoted to be taken literally:

? x
 *** [error: Undefined symbol: x]
? 'x
= x
? (f 23)
 *** [error: Undefined symbol: f]
? '(f 23)
= (f 23)

The vector and struct elements are also evaluated, so you sometimes need to quote them, too (as that is more convenient than quoting every interior item):

? [1 two 3]
 *** [error: Undefined symbol: two] 
? [1 'two 3]      ; you can quote just what needs to be quoted
= [1 two 3]
? '[1 two 3]      ; or just quote the whole thing
= [1 two 3]
? {x 2}
 *** [error: Undefined symbol: x]
? '{x 2}
= {x 2}
? {"x" two}
 *** [error: Undefined symbol: two]
? '{"x" two}
= {"x" two}

The complete list of primitive types in Ell is:

  • <null>
  • <boolean>
  • <character>
  • <number>
  • <string>
  • <blob>
  • <symbol>
  • <keyword>
  • <type>
  • <list>
  • <vector>
  • <struct>
  • <function>
  • <code>
  • <error>
  • <channel>

You can define additional types in terms of other types, this is discussed later.

Core expressions

  • _symbol_ - variable reference
  • (quote _expr_) - literal data
  • (do _expr_ ...) - expression sequencing
  • (if _predicate_ _consequent_ _antecedent_) - conditional
  • (_function_ _expr_ ...) - function call
  • (fn (_arg_ ...) _expr_ ...) - function creation
  • (set! _name_ _expr_) - sets the lexically apparent variable to the value
  • (def _name_ _expr_) - define value. At the top level, sets the global variable. Inside a function, creates a new frame with the binding.
  • (defmacro _name_ (_arg_) _expr_ ...) - define a new macro
Variables and literals

As mentioned before, most data items evaluate to themselves. But symbols and lists do not. When a symbol is interpreted, the closest lexical binding of that variable is looked up, starting from the innermost frame, and ending with the global environment.

? +
= #[function +]  		; the global binding for + is the addition function
? (defn f (x) (+ x 1))	; the x here is defined only inside the function
= #[function f]

The quote primitive is used to prevent the normal evaluation if its argument. It is the long form of the single quote reader macro, which actually just produces a quote form:

? (quote foo)
= foo
? 'foo ; a shorthand for the same thing
= foo
? (def x 23)
= 23
? x
= 23
? 'x
= x
Conditionals and sequencing

The primitive for conditionals is if, which takes a predicate, and if the predicate is true evaluates the consequent. An optional antecedent clause will be executed of the predicate is false.

? (if true 'yes)
= yes
? (if false 'yes)
= null
? (if false 'yes 'no)
= no

Sometimes more than one expression is needed in the place of one, largely for side-effects. This is what the do special form is for:

? (do (println "hello") 'blah)
hello
= blah
? (if true (do (println "it was true!") 1) (do (println "it wasn't true!") 0))
it was true!
= 1
Functions and lexical environments

A list is interpreted as a function call. For example, the following applies the + function to the arguments 2 and 3:

? (+ 2 3)
= 5

Ell provides a variety of primitive functions (like +). New functions are defined by the fn special form:

? (fn (x) (+ 1 x))
= #[function]

This creates an anonymous function that takes a single argument x and returns the sum of that and 1. This actually creates a closure over a new frame in the environment containing the variable x, and executes the body of the function in that lexical environment. The function returned is a first class object that itself can be passed around. All other binding forms can be defined in terms of this primitive, for example, consider the following:

(let ((x 23)) (+ 1 x))

The let special form is actually just a macro that generates the equivalent primitive form:

? (macroexpand '(let ((x 23)) (+ 1 x)))
= ((fn (x) (+ 1 x)) 23)

A function lives on with indefinite extent, closed over any variables in its lexical environment. For example:

? (def f (let ((counter 0)) (fn () (set! counter (inc counter)) counter)))
= #[function f]
? (f)
= 1
? (f)
= 2

In the above example, the primitive expression set! is also shown. It sets the value for the variable determined by its first argument (a symbol).

Normally, functions are defined at the top level, i.e. in the global environment, using the defn special form (which itself is just a macro):

? (defn f (x) (+ 1 x))
= #[function f]
? (f 23)
= 24

If def and defn are used inside a function, they create a new binding inside the function, rather than side-effect the global values for the symbols.

The defmacro primitive form allows the definition of new special forms (i.e. syntactic constructs used by the compiler).

? (defmacro blah (lst x) `(cons ~x ~lst))
= blah
? (blah '(1 2) 23)
= (23 1 2)
? (macroexpand '(blah '(1 2) 23))
= (cons 23 '(1 2))

This example shows the quasiquote macro, which simulates a simple quote, but allows escaped values to be inserted. In general ~x means "insert the current value of x here", and ~@x means "splice the list represented by x into the expression here".

Function argument binding forms

In addition to traditional lambda definitions, with explicit arguments and/or "rest" arguments, optional named arguments with defaults, and keyword arguments, are also supported:

? (defn f (x y) (list x y))
= #[function f]
? (f 1 2)
= (1 2)
? (defn f (x & rest) (list x rest))
= #[function f]
? (f 1 2)
= (1 (2))
? (f 1 2 3)
= (1 (2 3))
? (defn f args args)
= #[function f]
? (f 1 2 3)
= (1 2 3)
? (defn f (x [y]) (list x y))
= #[function f]
? (f 1 2)
= (1 2)
? (f 1)
= (1 null)
? (defn f (x [(y 23)]) (list x y))
= #[function f]
? (f 1)
= (1 23)
? (f 1 2)
= (1 2)
? (defn f (x {y: 23 z: 57}) (list x y z))
= #[function f]
? (f 1)
= (1 23 57)
? (f 1 2)                                                                                               
 *** Bad keyword arguments: [2] 
? (f 1 y: 2)
= (1 2 57)
? (f 1 z: 2)
= (1 23 2)
? (f 1 z: 2 y: 3)
= (1 3 2)

Defining new types

The type function returns the type of its argument:

? (type 5)
= <number>
? (type "foo")
= <string>
? (type <string>)
= <type>

Types are referred to symbolically, and also evaluate to themselves. They do not have to be defined to be referred to, as they are essentially just tags on data. A special syntax allows them to be read/written:

? <foo>
= <foo>	
? (type <foo>)
= <type>
? (type #<foo>"blah")
= <foo>
? (value #<foo>"blah")
= "blah"

New types can be introduced by attaching to other data objects. For example:

? (def x (instance <foo> "blah"))
= #<foo>"blah"
? (type x)
= <foo>
? (value x)
= "blah"

Some convenience macros for defining new types are provided:

? (deftype foo (o) (and (string? o) (< (length o) 5)))
= <foo>
? (foo "blah")
= #<foo>"blah"
? (foo "no way")                  
 *** [syntax-error: not a valid <foo>:  "no way"] [in foo]
? (foo? (foo "blah"))
= true
? (foo? "blah")
= false

It is defined in terms of a validation predicate. Once defined, the type is independent, and has no relation to any other type; there is no inheritance of types.

Defining a type that is a struct with certain fields is common enough that a dedicated macro is defined to make it simpler:

? (defstruct point x: <number> y: <number>)
= <point>
? (point)
 *** [validation-error: type <point> missing field x: {}] [in point] 
? (point x: 1 y: 2)
= #<point>{x: 1 y: 2}
? (def data {x: 1 y: 2})
= {x: 1 y: 2}
? (struct? data)
= true
? (point? data)
= false
? (def pt (point data))
= #<point>{x: 1 y: 2}
? (struct? pt)
= false
? (point? pt)
= true
? (value pt)
= {x: 1 y: 2}
? (type (value pt))
= <struct>
? (equal? data (value pt))
= true
? (identical? data (value pt)) ; not identical means a copy was made.
= false
? (point-fields)
= {x: <number> y: <number>}

To access fields of a struct, including any defined as above, the get function can be used, but since all fields have keywords as names, using a keyword as a function is more idiomatic:

? (x: pt)
= 1
? (y: pt)
= 2

Although to change the values, put! must be used on the value of the instance. Any such mutable operation is not encouraged, but sometimes necessary:

? (put! data x: 23)
= null
? data
= {x: 23 y: 2}
? (put! pt x: 23)
 *** [argument-error: put! expected a <struct> for argument 1, got a <point>] 
? (put! (value pt) x: 57)       
= null
? pt
= #<point>{x: 57 y: 2}

Defining methods on types

Ell provides generic method dispatch, supporting multimethods. This means any number of arguments to a function may be specialized, and dispatch can be based on all of them.

For example:

? (defgeneric add (x y))
= #[function add]
? (defmethod add ((x <string>) y) (string x "|other|" y))
= add
? (defmethod add ((x <number>) (y <number>)) (+ x y))
= add
? (defmethod add ((x <string>) (y <string>)) (string x "|string|" y))
= add
? (defmethod add ((x <list>) (y <list>)) (concat x y))
= add
? (defmethod add ((x <vector>) (y <vector>)) (apply vector (concat (to-list x) (to-list y))))
= add
? (add 1 2)
= 3
? (add "foo" "bar")
= "foo|string|bar"
? (add "foo" 'bar)
= "foo|other|bar"
? (add '(1 2) '(3 4))
= (1 2 3 4)
? (add [1 2] [3 4])
= [1 2 3 4]

Other features

Continuations

Full continuations (the same as in Scheme) are support via the callcc function. A few examples are in tests/continuation_test.ell, and a full coroutine scheduler that supports the structured parallel statement is in lib/scheduler.ell. Ell's catch macro and error function are built on continuations.

Socket server, web server

See tests/sockserver.ell and tests/sockclient for a simple example of a TCP server that uses framed messages, and tests/webserver.ell and tests/webclient.ell for example HTTP server/client written in Ell

Threads and Channels

Lightweight threads and asynchronous communication channels are also supported. See tests/channel_test.ell and their usage in tests/sockserver.ell

License

Copyright 2015 Lee Boynton

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const MaxFrameSize = 1000000

MaxFrameSize is an arbitrary limit to the tcp server framesize, to avoid trouble

Variables

View Source
var AnyType = Intern("<any>")

AnyType is a pseudo type specifier indicating any type

View Source
var Apply = &Object{Type: FunctionType}

Apply is a primitive instruction to apply a function to a list of arguments

View Source
var ArgumentErrorKey = Intern("argument-error:")

ArgumentErrorKey

View Source
var BlobType = Intern("<blob>")

BlobType is the type of all bytearrays

View Source
var BooleanType = Intern("<boolean>")

BooleanType is the type of true and false

View Source
var CallCC = &Object{Type: FunctionType}

CallCC is a primitive instruction to executable (restore) a continuation

View Source
var CallSymbol = Intern("call")
View Source
var ChannelType = Intern("<channel>")

ChannelType - the type of Ell's channel object

View Source
var CharacterType = Intern("<character>")

CharacterType is the type of all characters

View Source
var ClosureSymbol = Intern("closure")
View Source
var CodeType = Intern("<code>")

CodeType is the type of compiled code

View Source
var DefglobalSymbol = Intern("defglobal")
View Source
var DefmacroSymbol = Intern("defmacro")
View Source
var EmptyBlob = MakeBlob(0)

EmptyBlob - a blob with no bytes

View Source
var EmptyList = initEmpty()

EmptyList - the value of (), terminates linked lists

View Source
var EmptyString = String("")

EmptyString

View Source
var EmptyStruct = MakeStruct(0)

EmptyStruct - a <struct> with no bindings

View Source
var ErrorKey = Intern("error:")

ErrorKey - used to generic errors

View Source
var ErrorType = Intern("<error>")

ErrorType is the type of all errors

View Source
var False = &Object{Type: BooleanType, fval: 0}

False is the singleton boolean false value

View Source
var FuncSymbol = Intern("func")
View Source
var FunctionType = Intern("<function>")

FunctionType is the type of all functions

View Source
var GenfnsSymbol = Intern("*genfns*")
View Source
var GlobalSymbol = Intern("global")
View Source
var HTTPErrorKey = Intern("http-error:")

HttpErrorKey

View Source
var IOErrorKey = Intern("io-error:")

IOErrorKey

View Source
var InterruptKey = Intern("interrupt:")

InterruptKey

View Source
var JumpSymbol = Intern("jump")
View Source
var JumpfalseSymbol = Intern("jumpfalse")
View Source
var ListType = Intern("<list>")

ListType is the type of all lists

View Source
var LiteralSymbol = Intern("literal")
View Source
var LocalSymbol = Intern("local")
View Source
var MacroErrorKey = Intern("macro-error:")

MacroErrorKey

View Source
var MethodsKeyword = Intern("methods:")
View Source
var MinusOne = Number(-1)

MinusOne is the Ell -1 value

View Source
var Null = &Object{Type: NullType}

Null is Ell's version of nil. It means "nothing" and is not the same as EmptyList. It is a singleton.

View Source
var NullType = Intern("<null>")

NullType the type of the null object

View Source
var NumberType = Intern("<number>")

NumberType is the type of all numbers

View Source
var One = Number(1)

One is the Ell 1 value

View Source
var PopSymbol = Intern("pop")
View Source
var QuasiquoteSymbol = Intern("quasiquote")
View Source
var QuoteSymbol = Intern("quote")
View Source
var ReturnSymbol = Intern("return")
View Source
var SetlocalSymbol = Intern("setlocal")
View Source
var Spawn = &Object{Type: FunctionType}

Apply is a primitive instruction to apply a function to a list of arguments

View Source
var StringType = Intern("<string>")

StringType is the type of all strings

View Source
var StructSymbol = Intern("struct")
View Source
var StructType = Intern("<struct>")

VectorType is the type of all structs

View Source
var SyntaxErrorKey = Intern("syntax-error:")

SyntaxErrorKey

View Source
var TailcallSymbol = Intern("tailcall")
View Source
var TcpConnectionType = Intern("<tcp-connection>")
View Source
var True = &Object{Type: BooleanType, fval: 1}

True is the singleton boolean true value

View Source
var UndefineSymbol = Intern("undefine")
View Source
var UnquoteSymbol = Intern("unquote")
View Source
var UnquoteSymbolSplicing = Intern("unquote-splicing")
View Source
var UseSymbol = Intern("use")
View Source
var VectorSymbol = Intern("vector")
View Source
var VectorType = Intern("<vector>")

VectorType is the type of all vectors

View Source
var Version = "(development version)"

Version - this version of ell

View Source
var Zero = Number(0)

Zero is the Ell 0 value

Functions

func AddEllDirectory

func AddEllDirectory(dirname string)

func AsByteValue

func AsByteValue(obj *Object) (byte, error)

func AsFloat64Value

func AsFloat64Value(obj *Object) (float64, error)

func AsInt64Value

func AsInt64Value(obj *Object) (int64, error)

func AsIntValue

func AsIntValue(obj *Object) (int, error)

func AsRuneValue

func AsRuneValue(c *Object) (rune, error)

AsCharacter - return the native rune representation of the character object, if possible

func AsStringValue

func AsStringValue(obj *Object) (string, error)

AsStringValue - return the native string representation of the object, if possible

func BlobValue

func BlobValue(obj *Object) []byte

BlobValue - return native []byte value of the object

func BoolValue

func BoolValue(obj *Object) bool

BoolValue - return native bool value of the object

func ChannelValue

func ChannelValue(obj *Object) chan *Object

ChannelValue - return the Go channel object for the Ell channel

func Cleanup

func Cleanup()

func CloseChannel

func CloseChannel(obj *Object)

CloseChannel - close the channel object

func DefineFunction

func DefineFunction(name string, fun PrimitiveFunction, result *Object, args ...*Object)

Register a primitive function to the specified global name

func DefineFunctionKeyArgs

func DefineFunctionKeyArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, defaults []*Object, keys []*Object)

Register a primitive function with keyword arguments to the specified global name

func DefineFunctionOptionalArgs

func DefineFunctionOptionalArgs(name string, fun PrimitiveFunction, result *Object, args []*Object, defaults ...*Object)

Register a primitive function with optional arguments to the specified global name

func DefineFunctionRestArgs

func DefineFunctionRestArgs(name string, fun PrimitiveFunction, result *Object, rest *Object, args ...*Object)

Register a primitive function with Rest arguments to the specified global name

func DefineGlobal

func DefineGlobal(name string, obj *Object)

Bind the value to the global name

func DefineMacro

func DefineMacro(name string, fun PrimitiveFunction)

Register a primitive macro with the specified name.

func EncodeString

func EncodeString(s string) string

EncodeString - return the encoded form of a string value

func Equal

func Equal(o1 *Object, o2 *Object) bool

func Error

func Error(errkey *Object, args ...interface{}) error

Error - creates a new Error from the arguments. The first is an actual Ell keyword object, the rest are interpreted as/converted to strings

func ExpandFilePath

func ExpandFilePath(path string) string

func Fatal

func Fatal(args ...interface{})

func FindModuleByName

func FindModuleByName(moduleName string) (string, error)

func FindModuleFile

func FindModuleFile(name string) (string, error)

func Float64Value

func Float64Value(obj *Object) float64

Float64Value - return native float64 value of the object

func GetMacro

func GetMacro(sym *Object) *macro

GetMacro - return the macro for the symbol, or nil if not defined

func Has

func Has(obj *Object, key *Object) (bool, error)

func Identical

func Identical(o1 *Object, o2 *Object) bool

Identical - return if two objects are identical

func Init

func Init(extns ...Extension)

func InitPrimitives

func InitPrimitives()

InitEnvironment - defines the global functions/variables/macros for the top level environment

func Int64Value

func Int64Value(obj *Object) int64

Int64Value - return native int64 value of the object

func IntValue

func IntValue(obj *Object) int

IntValue - return native int value of the object

func IsBoolean

func IsBoolean(obj *Object) bool

func IsCharacter

func IsCharacter(obj *Object) bool

func IsCode

func IsCode(obj *Object) bool

func IsDefined

func IsDefined(sym *Object) bool

IsDefined - return true if the there is a global value defined for the symbol

func IsDirectoryReadable

func IsDirectoryReadable(path string) bool

IsDirectoryReadable - return true of the directory is readable

func IsError

func IsError(o interface{}) bool

func IsFileReadable

func IsFileReadable(path string) bool

IsFileReadable - return true of the file is readable

func IsFloat

func IsFloat(obj *Object) bool

func IsFunction

func IsFunction(obj *Object) bool

func IsInstance

func IsInstance(obj *Object) bool

instances have arbitrary Type symbols, all we can check is that the instanceValue is set

func IsInt

func IsInt(obj *Object) bool

func IsKeyword

func IsKeyword(obj *Object) bool

func IsList

func IsList(obj *Object) bool

func IsNull

func IsNull(obj *Object) bool

func IsNumber

func IsNumber(obj *Object) bool

func IsPrimitiveType

func IsPrimitiveType(tag *Object) bool

func IsString

func IsString(obj *Object) bool

func IsStruct

func IsStruct(obj *Object) bool

func IsSymbol

func IsSymbol(obj *Object) bool

func IsType

func IsType(obj *Object) bool

func IsValidKeywordName

func IsValidKeywordName(s string) bool

func IsValidStructKey

func IsValidStructKey(o *Object) bool

IsValidStructKey - return true of the object is a valid <struct> key.

func IsValidSymbolName

func IsValidSymbolName(name string) bool

func IsValidTypeName

func IsValidTypeName(s string) bool

func IsVector

func IsVector(obj *Object) bool

func ListEqual

func ListEqual(lst *Object, a *Object) bool

ListEqual returns true if the object is equal to the argument

func ListLength

func ListLength(lst *Object) int

func Load

func Load(name string) error

func LoadFile

func LoadFile(file string) error

func Macro

func Macro(name *Object, expander *Object) *macro

Macro - create a new Macro

func Main

func Main(extns ...Extension)

func Now

func Now() float64

func NumberEqual

func NumberEqual(f1 float64, f2 float64) bool

Equal returns true if the object is equal to the argument, within epsilon

func Pretty

func Pretty(obj *Object) string

func PrettyAll

func PrettyAll(obj *Object) string

func Print

func Print(args ...interface{})

func Println

func Println(args ...interface{})

func Put

func Put(obj *Object, key *Object, val *Object)

func RandomSeed

func RandomSeed(n int64)

func ReadEvalPrintLoop

func ReadEvalPrintLoop()

func Round

func Round(f float64) float64

Round - return the closest integer value to the float value

func Run

func Run(args ...string)

func RuneValue

func RuneValue(obj *Object) rune

RuneValue - return native rune value of the object

func SetFlags

func SetFlags(o bool, v bool, d bool, t bool, i bool)

SetFlags - set various flags controlling the runtime

func Sleep

func Sleep(delayInSeconds float64)

func SpitFile

func SpitFile(path string, data string) error

SpitFile - write the string to the file.

func StringLength

func StringLength(s string) int

StringLength - return the string length

func StringValue

func StringValue(obj *Object) string

StringValue - return native string value of the object

func StructEqual

func StructEqual(s1 *Object, s2 *Object) bool

Equal returns true if the object is equal to the argument

func StructLength

func StructLength(strct *Object) int

StructLength - return the length (field count) of the <struct> object

func Unput

func Unput(obj *Object, key *Object)

func Use

func Use(sym *Object) error

func VM

func VM(stackSize int) *vm

func VectorEqual

func VectorEqual(v1 *Object, v2 *Object) bool

VectorEqual - return true of the two vectors are equal, i.e. the same length and all the elements are also equal

func Write

func Write(obj *Object) string

func WriteAll

func WriteAll(obj *Object) string

Types

type Code

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

Code - compiled Ell bytecode

func (*Code) String

func (code *Code) String() string

type Extension

type Extension interface {
	Init() error
	Cleanup()
	String() string
}

type Object

type Object struct {
	Type *Object // i.e. <string>

	Value interface{} // the rest of the data for more complex things
	// contains filtered or unexported fields
}

Object is the Ell object: a union of all possible primitive types. Which fields are used depends on the variant the variant is a type object i.e. Intern("<string>"). For arbitrary embedded extension types, the Value field is an interface{}. It is used for Channels internally, but is generally useful for app-specific native types when extending Ell.

var KeywordType *Object // bootstrapped in initSymbolTable => Intern("<keyword>")

KeywordType is the type of all keywords

var SymbolType *Object // bootstrapped in initSymbolTable = Intern("<symbol>")

SymbolType is the type of all symbols

var TypeType *Object // bootstrapped in initSymbolTable => Intern("<type>")

TypeType is the metatype, the type of all types

func Blob

func Blob(bytes []byte) *Object

Blob - create a new blob, using the specified byte slice as the data. The data is not copied.

func Caar

func Caar(lst *Object) *Object

Caar - return the Car of the Car of the list

func Cadar

func Cadar(lst *Object) *Object

Cadar - return the Car of the Cdr of the Car of the list

func Cadddr

func Cadddr(lst *Object) *Object

Cadddr - return the Car of the Cdr of the Cdr of the Cdr of the list

func Caddr

func Caddr(lst *Object) *Object

Caddr - return the Car of the Cdr of the Cdr of the list

func Cadr

func Cadr(lst *Object) *Object

Cadr - return the Car of the Cdr of the list

func Car

func Car(lst *Object) *Object

Car - return the first object in a list

func Cdar

func Cdar(lst *Object) *Object

Cdar - return the Cdr of the Car of the list

func Cddddr

func Cddddr(lst *Object) *Object

Cddddr - return the Cdr of the Cdr of the Cdr of the Cdr of the list

func Cdddr

func Cdddr(lst *Object) *Object

Cdddr - return the Cdr of the Cdr of the Cdr of the list

func Cddr

func Cddr(lst *Object) *Object

Cddr - return the Cdr of the Cdr of the list

func Cdr

func Cdr(lst *Object) *Object

Cdr - return the rest of the list

func Channel

func Channel(bufsize int, name string) *Object

Channel - create a new channel with the given buffer size and name

func Character

func Character(c rune) *Object

Character - return a new <character> object

func Closure

func Closure(code *Code, frame *frame) *Object

func Compile

func Compile(expr *Object) (*Object, error)

Compile - compile the source into a code object.

func CompileFile

func CompileFile(name string) (*Object, error)

caveats: when you compile a file, you actually run it. This is so we can handle imports and macros correctly.

func Concat

func Concat(seq1 *Object, seq2 *Object) (*Object, error)

func Connection

func Connection(con net.Conn, endpoint string) *Object

func Cons

func Cons(car *Object, cdr *Object) *Object

Cons - create a new list consisting of the first object and the rest of the list

func Continuation

func Continuation(frame *frame, ops []int, pc int, stack []*Object) *Object

func CopyVector

func CopyVector(vec *Object) *Object

CopyVector - return a copy of the <vector>

func ErrorData

func ErrorData(err *Object) *Object

func Eval

func Eval(expr *Object) (*Object, error)

func Flatten

func Flatten(lst *Object) *Object

func Get

func Get(obj *Object, key *Object) (*Object, error)

Get - return the value for the key of the object. The Value() function is first called to handle typed instances of <struct>. This is called by the VM, when a keyword is used as a function.

func GetGlobal

func GetGlobal(sym *Object) *Object

GetGlobal - return the global value for the specified symbol, or nil if the symbol is not defined.

func GetKeywords

func GetKeywords() []*Object

GetKeywords - return a slice of Ell primitive reserved words

func Globals

func Globals() []*Object

Globals - return a slice of all defined global symbols

func Instance

func Instance(tag *Object, val *Object) (*Object, error)

func Int

func Int(n int64) *Object

func Intern

func Intern(name string) *Object

Intern - internalize the name into the global symbol table

func KeywordName

func KeywordName(t *Object) (*Object, error)

<keyword> -> <symbol>

func List

func List(values ...*Object) *Object

func ListFromValues

func ListFromValues(values []*Object) *Object

func Macroexpand

func Macroexpand(expr *Object) (*Object, error)

Macroexpand - return the expansion of all macros in the object and return the result

func Macros

func Macros() []*Object

Macros - return a slice of all defined macros

func MakeBlob

func MakeBlob(size int) *Object

MakeBlob - create a new blob of the given size. It will be initialized to all zeroes

func MakeCode

func MakeCode(argc int, defaults []*Object, keys []*Object, name string) *Object

MakeCode - create a new code object

func MakeError

func MakeError(elements ...*Object) *Object

func MakeList

func MakeList(count int, val *Object) *Object

func MakeStruct

func MakeStruct(capacity int) *Object

MakeStruct - create an empty <struct> object with the specified capacity

func MakeVector

func MakeVector(size int, init *Object) *Object

MakeVector - create a new <vector> object of the specified size, with all elements initialized to the specified value

func NewObject

func NewObject(variant *Object, value interface{}) *Object

NewObject is the constructor for externally defined objects, where the value is an interface{}.

func Number

func Number(f float64) *Object

Number - create a Number object for the given value

func Primitive

func Primitive(name string, fun PrimitiveFunction, result *Object, args []*Object, rest *Object, defaults []*Object, keys []*Object) *Object

func Random

func Random(min float64, max float64) *Object

func RandomList

func RandomList(size int, min float64, max float64) *Object

func Read

func Read(input *Object, keys *Object) (*Object, error)

Read - only reads the first item in the input, along with how many characters it read for subsequence calls, you can slice the string to continue

func ReadAll

func ReadAll(input *Object, keys *Object) (*Object, error)

ReadAll - read all items in the input, returning a list of them.

func Reverse

func Reverse(lst *Object) *Object

func SlurpFile

func SlurpFile(path string) (*Object, error)

SlurpFile - returnthe file contents as a string

func String

func String(s string) *Object

String - create a new string object

func StringCharacters

func StringCharacters(s *Object) []*Object

StringCharacters - return a slice of <character> objects that represent the string

func StringJoin

func StringJoin(seq *Object, delims *Object) (*Object, error)

func StringRef

func StringRef(s *Object, idx int) *Object

StringRef - return the <character> object at the specified string index

func StringSplit

func StringSplit(obj *Object, delims *Object) (*Object, error)

func Struct

func Struct(fieldvals []*Object) (*Object, error)

Struct - create a new <struct> object from the arguments, which can be other structs, or key/value pairs

func StructKeys

func StructKeys(s *Object) *Object

func StructValues

func StructValues(s *Object) *Object

func Symbol

func Symbol(names []*Object) (*Object, error)

func Symbols

func Symbols() []*Object

func Timestamp

func Timestamp(t time.Time) *Object

func ToBlob

func ToBlob(obj *Object) (*Object, error)

ToBlob - convert argument to a blob, if possible.

func ToCharacter

func ToCharacter(c *Object) (*Object, error)

ToCharacter - convert object to a <character> object, if possible

func ToInt

func ToInt(o *Object) (*Object, error)

ToInt - convert the object to an integer number, if possible

func ToKeyword

func ToKeyword(obj *Object) (*Object, error)

func ToList

func ToList(obj *Object) (*Object, error)

ToList - convert the argument to a List, if possible

func ToNumber

func ToNumber(o *Object) (*Object, error)

ToNumber - convert object to a number, if possible

func ToString

func ToString(a *Object) (*Object, error)

ToString - convert the object to a string, if possible

func ToStruct

func ToStruct(obj *Object) (*Object, error)

func ToSymbol

func ToSymbol(obj *Object) (*Object, error)

func ToVector

func ToVector(obj *Object) (*Object, error)

ToVector - convert the object to a <vector>, if possible

func TypeName

func TypeName(t *Object) (*Object, error)

<type> -> <symbol>

func Value

func Value(obj *Object) *Object

func Vector

func Vector(elements ...*Object) *Object

Vector - create a new <vector> object from the given element objects.

func VectorFromElements

func VectorFromElements(elements []*Object, count int) *Object

VectorFromElements - return a new <vector> object from the given slice of elements. The slice is copied.

func VectorFromElementsNoCopy

func VectorFromElementsNoCopy(elements []*Object) *Object

VectorFromElementsNoCopy - create a new <vector> object from the given slice of elements. The slice is NOT copied.

func (*Object) Error

func (lob *Object) Error() string

Error

func (*Object) String

func (lob *Object) String() string

type PrimitiveFunction

type PrimitiveFunction func(argv []*Object) (*Object, error)

PrimitiveFunction is the native go function signature for all Ell primitive functions

Directories

Path Synopsis
cmd
ell command

Jump to

Keyboard shortcuts

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