Skip to content

Commit

Permalink
Rename tiny lisp to minimalisp
Browse files Browse the repository at this point in the history
  • Loading branch information
bakku committed Dec 5, 2020
1 parent 9d83397 commit 8125b13
Show file tree
Hide file tree
Showing 26 changed files with 171 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Executables

cmd/tl/tl*
cmd/mlisp/mlisp*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
go build -o cmd/tl/tl cmd/tl/main.go
go build -o cmd/mlisp/mlisp cmd/mlisp/main.go

test:
go test ./...
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Tiny Lisp
# Minimalisp

After reading [Crafting Interpreters](www.craftinginterpreters.com) Tiny Lisp is my small take
After reading [Crafting Interpreters](www.craftinginterpreters.com) Minimalisp is my small take
on writing a programming language from scratch. It mimicks the approach of the *jlox* implementation
and uses a tree-walking approach to interpret source code.

## Compiling

To compile Tiny Lisp just execute:
To compile Minimalisp just execute:

```
make
```

Golang must be installed, of course. This will create a `tl` executable in the `cmd/tl` folder.
Golang must be installed, of course. This will create an `mlisp` executable in the `cmd/mlisp` folder.

## Usage

Tiny Lisp can be used either as a REPL or for running simple scripts. Here is an example of Tiny Lisp code:
Minimalisp can be used either as a REPL or for running simple scripts. Here is an example of Minimalisp code:

```clojure
(defvar names '(1 2 3 4))
Expand Down
22 changes: 11 additions & 11 deletions Specification.org
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#+TITLE: Tiny Lisp Specification
#+TITLE: Minimalisp Specification

This document serves as a small specification for Tiny Lisp. It explains all features of the language and highlights its grammer. Tiny Lisp is not really an actual Lisp since it lacks common Lisp features such as macros. It only uses Lisp syntax. Whether that justifies having /Lisp/ in its name is a different question.
This document serves as a small specification for Minimalisp. It explains all features of the language and highlights its grammer. Minimalisp is not really an actual Lisp since it lacks common Lisp features such as macros. It only uses Lisp syntax. Whether that justifies having /Lisp/ in its name is a different question.

* Features

Tiny Lisp tries to keep keywords and special syntax to a minimum. It is furthermore a dynamically typed language.
Minimalisp tries to keep keywords and special syntax to a minimum. It is furthermore a dynamically typed language.

** Comments

Similar to many other Lisps, Tiny Lisp uses semicolons for comments.
Similar to many other Lisps, Minimalisp uses semicolons for comments.

#+BEGIN_SRC clojure
; This is a comment
#+END_SRC

** Expressions

Naturally, Tiny Lisp uses prefix notation and S-expressions. In Tiny Lisp everything is an expression.
Naturally, Minimalisp uses prefix notation and S-expressions. In Minimalisp everything is an expression.

#+BEGIN_SRC clojure
(+ 1 (- 2 1) (/ 4 2))
Expand All @@ -38,7 +38,7 @@ It is also possible to create an anonymous function.

** Defining variables

Tiny Lisp allows the definition of global and local variables.
Minimalisp allows the definition of global and local variables.

#+BEGIN_SRC clojure
; Global variable
Expand All @@ -51,7 +51,7 @@ Tiny Lisp allows the definition of global and local variables.

** Returning from a function

Tiny Lisp automatically returns the last expression of a function.
Minimalisp automatically returns the last expression of a function.

#+BEGIN_SRC clojure
(defun add-and-sub-one (n)
Expand All @@ -63,7 +63,7 @@ Tiny Lisp automatically returns the last expression of a function.

** Datatypes

Tiny Lisp knows strings, numbers, booleans, functions, and lists.
Minimalisp knows strings, numbers, booleans, functions, and lists.

#+BEGIN_SRC clojure
; numbers
Expand All @@ -85,7 +85,7 @@ Tiny Lisp knows strings, numbers, booleans, functions, and lists.
(defvar l '(1 2 3 4 5))
#+END_SRC

Furthermore, Tiny Lisp uses *nil*.
Furthermore, Minimalisp uses *nil*.

#+BEGIN_SRC clojure
; nothing
Expand All @@ -94,7 +94,7 @@ Furthermore, Tiny Lisp uses *nil*.

** Conditionals

In Tiny Lisp everything except /false/ and /nil/ is truthy.
In Minimalisp everything except /false/ and /nil/ is truthy.

#+BEGIN_SRC clojure
; Prints 'Yes!'
Expand All @@ -105,7 +105,7 @@ In Tiny Lisp everything except /false/ and /nil/ is truthy.

* Grammar

The root element of Tiny Lisp is a /program/ that is composed out of zero or more declarations.
The root element of Minimalisp is a /program/ that is composed out of zero or more declarations.

#+BEGIN_SRC
program → declaration* EOF
Expand Down
2 changes: 1 addition & 1 deletion ast.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tinylisp
package minimalisp

// Expression is the interface all types of expressions must fulfil.
type Expression interface {
Expand Down
16 changes: 8 additions & 8 deletions cmd/tl/main.go → cmd/mlisp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"os"
"strings"

"bakku.dev/tinylisp"
"bakku.dev/minimalisp"
"github.com/peterh/liner"
)

func main() {
if len(os.Args) > 2 {
fmt.Println("Usage: tl [script]")
fmt.Println("Usage: mlisp [script]")
} else if len(os.Args) == 2 {
runScript(os.Args[1])
} else {
Expand All @@ -29,21 +29,21 @@ func runScript(filename string) {

code := string(bytes)

scanner := tinylisp.NewScanner(code, os.Stdout)
scanner := minimalisp.NewScanner(code, os.Stdout)
tokens, ok := scanner.Scan()

if !ok {
return
}

parser := tinylisp.NewParser(tokens)
parser := minimalisp.NewParser(tokens)
expressions, err := parser.Parse()
if err != nil {
fmt.Println(err)
return
}

interpreter := tinylisp.NewInterpreter()
interpreter := minimalisp.NewInterpreter()
ret, err := interpreter.Interpret(expressions)
if err != nil {
fmt.Println(err)
Expand All @@ -53,7 +53,7 @@ func runScript(filename string) {
}

func startRepl() {
interpreter := tinylisp.NewInterpreter()
interpreter := minimalisp.NewInterpreter()
line := liner.NewLiner()
defer line.Close()

Expand All @@ -77,13 +77,13 @@ func startRepl() {

line.AppendHistory(code)

scanner := tinylisp.NewScanner(code, os.Stdout)
scanner := minimalisp.NewScanner(code, os.Stdout)
tokens, ok := scanner.Scan()
if !ok {
continue
}

parser := tinylisp.NewParser(tokens)
parser := minimalisp.NewParser(tokens)
expressions, err := parser.Parse()
if err != nil {
fmt.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion collection.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tinylisp
package minimalisp

// First returns the first element of a list.
type First struct{}
Expand Down
2 changes: 1 addition & 1 deletion env.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tinylisp
package minimalisp

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tinylisp
package minimalisp

import "fmt"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions func.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package tinylisp
package minimalisp

// infiniteArity is a constant which allows a function to have an infinite arity.
const infiniteArity = -1

// Function is a tiny lisp function
// Function is a minimalisp function
type Function interface {
Arity() int
Call(line int, interpreter *Interpreter, args []interface{}) (interface{}, error)
}

// TinyLispFunction is the standard function which is used in the tiny lisp interpreter.
type TinyLispFunction struct {
// MinimalispFunction is the standard function which is used in the minimalisp interpreter.
type MinimalispFunction struct {
name string
params []Token
body Expression
closure *Environment
}

// NewTinyLispFunction is a factory function to create a new function.
func NewTinyLispFunction(name string, params []Token, body Expression, closure *Environment) Function {
return &TinyLispFunction{name, params, body, closure}
// NewMinimalispFunction is a factory function to create a new function.
func NewMinimalispFunction(name string, params []Token, body Expression, closure *Environment) Function {
return &MinimalispFunction{name, params, body, closure}
}

// Arity returns the amount of params which are expected for a function call.
func (f *TinyLispFunction) Arity() int {
func (f *MinimalispFunction) Arity() int {
return len(f.params)
}

// Call calls the function.
func (f *TinyLispFunction) Call(line int, interpreter *Interpreter, args []interface{}) (interface{}, error) {
func (f *MinimalispFunction) Call(line int, interpreter *Interpreter, args []interface{}) (interface{}, error) {
env := NewEnvironmentWithEnclosing(f.closure)

for i, p := range f.params {
Expand All @@ -40,6 +40,6 @@ func (f *TinyLispFunction) Call(line int, interpreter *Interpreter, args []inter
return interpreter.execute(f.body, env)
}

func (f *TinyLispFunction) String() string {
func (f *MinimalispFunction) String() string {
return "<" + f.name + ">"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module bakku.dev/tinylisp
module bakku.dev/minimalisp

go 1.15

Expand Down
6 changes: 3 additions & 3 deletions interpreter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tinylisp
package minimalisp

import (
"fmt"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (i *Interpreter) visitIfExpr(ifExpr *IfExpr) (interface{}, error) {
}

func (i *Interpreter) visitDefunExpr(defunExpr *DefunExpr) (interface{}, error) {
fun := NewTinyLispFunction(defunExpr.Name.Lexeme, defunExpr.Params, defunExpr.Body, i.current)
fun := NewMinimalispFunction(defunExpr.Name.Lexeme, defunExpr.Params, defunExpr.Body, i.current)

if err := i.current.Define(defunExpr.Name, fun); err != nil {
return nil, err
Expand Down Expand Up @@ -151,7 +151,7 @@ func (i *Interpreter) visitLetExpr(letExpr *LetExpr) (interface{}, error) {
}

func (i *Interpreter) visitLambdaExpr(lambdaExpr *LambdaExpr) (interface{}, error) {
return NewTinyLispFunction("lambda", lambdaExpr.Params, lambdaExpr.Body, i.current), nil
return NewMinimalispFunction("lambda", lambdaExpr.Params, lambdaExpr.Body, i.current), nil
}

func isTruthy(val interface{}) bool {
Expand Down
4 changes: 2 additions & 2 deletions interpreter_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tinylisp_test
package minimalisp_test

import (
"testing"

. "bakku.dev/tinylisp"
. "bakku.dev/minimalisp"
)

func TestInterpret_ShouldCorrectlyInterpretCode1(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion io.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tinylisp
package minimalisp

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tinylisp
package minimalisp

import "fmt"

Expand Down
Loading

0 comments on commit 8125b13

Please sign in to comment.