Code Monkey home page Code Monkey logo

lisp-in-dart's Introduction

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.

lisp-in-dart's People

Contributors

nukata avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.