malarkey

package module
v0.0.0-...-964aff0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: MIT Imports: 7 Imported by: 0

README

mal-arkey - "Make a Lisp" in Go

CI Go Report Card

Mal is a Clojure inspired Lisp interpreter

Mal-arkey is a complete Mal implementation in Go aiming for readability and simplicity. It passes all non-optional tests and can self-host Mal.

> make repl
Mal [Mal-arkey]
user> (defmacro! when (fn* [test & body] `(if ~test (do ~@body))))
#<function>
user> (let* [name "Mal-arkey"] (when (not (nil? name)) (println "Begin" (str name "!"))))
Begin Mal-arkey!
nil
Usage
  • make repl to start a Mal-arkey REPL.
  • make bin to build binaries that can be copied into the kanaka/mal test harness. My setup is at elh/mal.

Documentation

Overview

Package malarkey implements an interpreter for Mal-arkey, a tiny Lisp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(s Value, readably bool) string

Print returns a string representation of the given value.

func Tokenize

func Tokenize(input string) []string

Tokenize splits a input text into tokens.

Types

type Env

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

Env is a map of symbols to bound values.

func BuiltinEnv

func BuiltinEnv() *Env

BuiltinEnv creates a new default built-in function env.

func NewEnv

func NewEnv(outer *Env, bindSymbols []Value, bindValues []Value) *Env

NewEnv creates a new environment with the given outer environment.

func (*Env) Get

func (e *Env) Get(symbol string) (Value, error)

Get returns the value bound to the given symbol in the environment.

func (*Env) Set

func (e *Env) Set(symbol string, value Value)

Set binds a symbol to a value in the current environment.

type FunctionTCO

type FunctionTCO struct {
	AST     Value
	Params  []Value
	Env     *Env
	Fn      func(args ...Value) Value
	IsMacro bool
}

FunctionTCO is a `fn*`-defined function that can be evaluated in a TCO style.

type Reader

type Reader struct {
	Tokens   []string
	Position int
}

Reader reads tokens.

func (*Reader) Next

func (r *Reader) Next() string

Next returns the next token and advances the reader.

func (*Reader) Peek

func (r *Reader) Peek() string

Peek returns the next token without advancing the reader.

type Value

type Value struct {
	Type string
	Val  interface{}
}

Value is a mal value with explicit type. Types: * "list" - []Value * "vector" - []Value * "hash-map" - map[string]Value * "symbol" - string * "string" - string * "integer" - int64 * "float" - float64 * "boolean" - bool * "nil" - nil * "atom" - int. atom id (`atoms` idx) hack to dig myself out of non-pointer vals. i liked the bias to immutability * "function" - func(args ...Value) Value * "function-tco" - {

  • AST: Value
  • Params: Value
  • Env: *Env
  • Fn: func(args ...Value) Value
  • IsMacro bool }

func Eval

func Eval(expr Value, env *Env) Value

Eval evaluates an expression in the given environment.

func Read

func Read(input string) Value

Read parses input text into an AST.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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