Angel \”Java\” Lopez on Blog

January 9, 2010

Refactoring AjLisp: a lisp interpreter written in C#

Filed under: AjLisp, C Sharp, Open Source Projects — ajlopez @ 11:47 am

These days I was working on reimplementing the core of my open source AjLisp lisp interpreter. I wrote about the previous version in my 2008 post:

AjLisp: a Lisp interpreter in .NET

The work is in progress. You can download the current code from:

http://code.google.com/p/ajlisp/source/browse/#svn/trunk/AjLisp

(there are two other implementations in that repository, work in progress: AjScheme, an Scheme-like lisp, and AjSharpure, following Clojure ideas). I should write more about these implementations. This post is the initial one in a series about this new AjLisp. It’s a short introduction to the current status of the project.

The main change in the new version: the interpreter can manage native objects and values. The alternative was to point to such objects using a wrapper, a class that implements SymbolicExpression or something similar. But I choose to point and manage direct native object and values. So, I changed the primitives and related classes to receive objects instead of IExpression. Now, there is an interface IExpression, that is defined:

    public interface IExpression
    {
        object Evaluate(ValueEnvironment environment);
    }

The ValueEnvironment (I’m planning to rename it to BindingEnvironment, and to derive from it an interface IBindingEnvironment) keeps nested association of names to values:

There is an interface IFunction:

    public interface IFunction
    {
        object Apply(List arguments, ValueEnvironment environment);
    }

that it should be implemented by any form expression (the head of a list to evaluate).

There are two main classes that represent the core types in AjLisp: identifiers and lists:

All the project was built using Test-Driven Development, so I could change the previous versions with courage: I had my battery of tests ready to help me in the refactoring process. This is the current status:

I should write about:

– ValueEnvironment implementation

– Native objects and values management

– List type and evaluation

– Identifier evaluation

– Implemented primitives

– Lexer and Parser

– Numeric operations

– Rational numbers (AjLisp can manage integral numerator/denominator pairs)

Currently, after the wisdom gained developing these projects (AjLisp, AjScheme, AjSharpure), I’m writing a minimal core AjCoreLisp, to show what are the minimal primivites we need to create a Lisp interpreter. Armed with such implementation, I would like to explore compilation alternatives (Dynamic Language Runtime is my first candidate). It could be overwhelming to me do such exploration based on a “bigger” interpreter like AjLisp. First, I’ll try to compile an interpreter with few primitives.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: