• Stars
    star
    106
  • Rank 324,051 (Top 7 %)
  • Language
    Dart
  • Created over 6 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast Lisp interpreter in Dart

Lisp in Dart

This is a small Lisp interpreter in Dart. In 2015 (H27), I wrote the first version in Dart 1.9. It had been presented under the MIT License at http://www.oki-osk.jp/esc/dart/lisp.html (broken link) until the spring of 2017 (H29). In 2018 (H30), I slightly modified it to match Dart 2.0 and made the repository in GitHub.

Now in 2019 (R1), I found the old hack in Sym class

  @override int get hashCode => name.hashCode;

which had once accelerated the interpreter is effective again in Dart 2.5. So I included the hack in Sym class again. In addition, I made use of BigInt because int does not have inifinite-precision in Dart 2.0 and later.

See IMPLEMENTATION-NOTES.md for other details of the implementation.

How to use

It runs in Dart 2.5 and later.

$ dart lisp.dart
> "hello, world"
"hello, world"
> (+ 5 6)
11
> (exit 0)
$

You can give it a file name of your Lisp script.

$ dart lisp.dart examples/fib15.l
987
$

If you put a "-" after the file name, it will begin an interactive session after running the file.

$ dart lisp.dart examples/fib15.l -
987
> (fib 0)
1
> (fib 1)
1
> (fib 2)
2
> (exit 0)
$ 

Examples

There are five files ending with .l under the examples folder. These run also in Emacs Lisp and Common Lisp. You may find the Lisp in Dart comparably fast to Emacs Lisp which is written in C.

$ ./lisp.dart examples/qsort.l
(1 1 2 3 3 4 5 5 5 6 7 8 9 9 9)
$ 
$ emacs -batch -l examples/qsort.l

(1 1 2 3 3 4 5 5 5 6 7 8 9 9 9)
$ 
$ clisp examples/qsort.l

(1 1 2 3 3 4 5 5 5 6 7 8 9 9 9)
$ 
$ ./lisp.dart examples/fact100.l 
93326215443944152681699238856266700490715968264381621468592963895217599993229915
608941463976156518286253697920827223758251185210916864000000000000000000000000
$
  • fib15.l calculates Fibonacci for 15.

  • eval-fib15.l calculates Fibonacci for 15 on a meta-circular Lisp evaluator.

$ ./lisp.dart example/eval-fib15.l
987
$ 
  • eval-eval-fib15.l calculates Fibonacci for 15 on a meta-circular Lisp evaluator on a meta-circular Lisp evaluator.

The examples of eval-fib15.l and eval-eval-fib15.l are inspired by https://github.com/zick/ZickStandardLisp.

There is one more example:

  • interp_in_isolate.dart runs a Lisp interpreter in another isolate of Dart. You can embed an interpreter within your Flutter app in the same way.
$ dart examples/interp_in_isolate.dart
=> 11
=> 1
=> (1)

License

This is under the MIT License. See lisp.dart.

More Repositories

1

lisp-in-cs

A Lisp interpreter in C# 7
C#
84
star
2

lisp-in-go

A Common Lisp-like Lisp-1 in Go with TCO and partially hygienic macros
Go
36
star
3

lisp-in-typescript

A Common Lisp-like Lisp-1 in TypeScript with TCO and partially hygienic macros
TypeScript
32
star
4

cyg-git

Use Cygwin's Git from Go and VSCode
C
18
star
5

little-scheme

A meta-circular interpreter of a subset of Scheme
Scheme
14
star
6

little-scheme-in-typescript

A Scheme interpreter with first-class continuations in circa 800 lines of TypeScript code
TypeScript
13
star
7

little-scheme-in-python

A Scheme interpreter with first-class continuations in circa 500 lines of Python code
Python
11
star
8

little-scheme-in-dart

A Scheme interpreter with first-class continuations
Dart
9
star
9

little-scheme-in-java

A Scheme interpreter with first-class continuations in circa 900 lines of Java 8/11
Java
9
star
10

linq-in-go

LINQ to Objects in Go by generic higher order functions
Go
6
star
11

tiny-http-proxy

Tiny HTTP Proxy in Python
Python
6
star
12

little-scheme-in-crystal

A Scheme interpreter in Crystal with first-class continuations
Crystal
4
star
13

scheme-in-go

An experimental Scheme in Go
Go
3
star
14

little-scheme-in-ruby

A Scheme interpreter in Ruby with first-class continuations
Ruby
3
star
15

little-scheme-in-cs

A Scheme interpreter with first-class continuations in circa 900 lines of C# 8
C#
3
star
16

arc-in-java

An Arc interpreter with first-class continuations
Java
3
star
17

l2lisp-in-java

An experimental Lisp interpreter in Java
Java
3
star
18

little-scheme-in-go

A Scheme interpreter with first-class continuations in circa 800 (+ 600) lines of Go code
Go
2
star
19

l2lisp-in-python

An experimental Lisp interpreter in Python 2 & 3
Python
2
star
20

goarith

A package for general numeric arithmetic in Go
Go
1
star
21

ply-algol60

Algol 60 interpreter in Python with PLY
Python
1
star
22

little-scheme-in-php

A Scheme interpreter in PHP 7 with first-class continuations
PHP
1
star
23

little-scheme-in-kotlin

A Scheme interpreter in Kotlin with first-class continuations
Kotlin
1
star
24

little-scheme-in-lisp

A Scheme interpreter in Common Lisp with first-class continuations
Common Lisp
1
star