GithubHelp home page GithubHelp logo

perlisp's Introduction

PerLisp Build Status

This is a simple statically scoped Lisp interpreter, written in Perl. During the lecture "Structure and Interpretation of Programming Languages", held by Achim Clausing (WWU Münster, Germany), I needed to try out different things, so I wrote this.

DISCLAIMER This is not production ready. I use it to play around and I think there are many bugs lurking around. You have been warned! :-)

How to start?

Install PerLisp like a normal Perl distro:

$ perl Makefile.PL
$ make
$ make test
$ make install
$ make clean

Now you can call the perlisp script which starts a read eval print loop (see more details below):

$ perlisp

If you want to hack PerLisp, view the API docs via

$ perldoc PerLisp

If you don't want to install all that stuff, you can call the perlisp script from the project root directory:

$ cd ~/code/perlisp
$ perl perlisp

And it should just work. Now let's do some Lisp stuff!

PerLisp uses the bind operator to bind values to names, you have a lambda operator to create function values and the convenience operator define to bind a function to a name in one step. With the bound operator you get a list of all bound names. Most of them come from the init.perlisp file, which is loaded while the interpreter starts.

Start typing something like this:

(+ 17 25)
42
(define (square x) (* x x))
Function: (x) -> ( x x)*
(square 42)
1764

You can find more inspirations from PerLisp::Init and the tests, especially t/50-init.t, which shows some use cases for the init functions.

Some interesting stuff

  • Like Haskell, PerLisp fully supports autocurryfication, which means a function applied to too few arguments will return a function with parameters for the remaining arguments automagically. It's super-easy to define useful functions using autocurryfication in combination with some well known higher order functions:

(bind product (reduce * 1))
Function: (l) -> (cond (nil? l) 1 ( (car l) (reduce * 1 (cdr l))))*
(product (list 2 7 3))
42

  • PerLisp is able to interpret a simple Lisp interpreter written in Lisp which is able to run itself inside PerLisp. Amazing! And there's a test for it in t/61-lisplisp.t. However, to calculate even a simple expression in a three-level nested interpreter chain takes some time so you have to enable the test explicitly by setting the LISPLISP environment variable to a true value.

Interpreter details

The implementation is straight forward. PerLisp uses objects from the following classes to get you started with Lisp:

  • PerLisp::Lexer - generates a PerLisp::TokenStream from Lisp strings
  • PerLisp::Parser - generates PerLixp::Expr::* objects from a TokenStream
  • PerLisp::Expr::* - Lisp expressions
  • PerLisp::Context - objects which store value-name bindings
  • PerLisp::Operators - perl implementations of built-in operators
  • PerLisp::Init - a container package around the init script

View the code for more implementation details, I tried hard to make it very readable (even if you don't know much Perl).

Author, bug reports, license

Copyright (c) Mirko Westermeier, [email protected]

This software is released under the MIT license (view MIT-LICENSE for details).

If you found a bug, please contact me via mail or github. You can also use github's issue tracker. Please provide (failing) tests for your bugs, patches or feature requests.

perlisp's People

Contributors

memowe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

stuartskelton

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.