Category Archives: AjLisp

End Of Iteration 2014w03

Previous Post
Next Post

Great week extending interpreters.


My Erlang implementation as interpreter in C#

I added multi-functions, that is, functions with the same name and arity, but with different argument matching conditions. And I started to write a minimal Process, to have threads running functions. Next steps: implement process mailboxes.


I was working on my C# implementation

I started to add Java Dot Notation, to access native types and objects. So, I grabbed some code from RubySharp/PythonSharp/AjSharp to access .NET types and objects, and wrapped functions to invoke properties, methods and constructors.


More work on implementing Akka-like actor model in C#

I should refactor mailbox implementation. After a bit of design, I decided to have a worker thread by actor, consuming a concurrent queue. ActorRef could add message to the queue.

RuScript, ScaScript and SimpleGrammar

I updated the version of SimpleGrammar

to fix a bug detected consuming the library from RuScript:

I’m using SimpleGrammar in

my Scala-like interpreter in JavaScript (I just implemented only a minimal parser).


I was working in two non-public projects, and updating old PHP personal sites. I moved the code generated for Sinatra

to use a modular instead of classic approach.

More fun is comming.

Keep tuned!

Angel “Java” Lopez

End Of Iteration 2013w51

Previous Post
Next Post

My main outcome for this week:


I was working on my Erlang interpreter written in C#:

I improved the match algorithm, incorporating more use cases and resolving them using Test-Driven Development. The REPL is working:

Other works

I updated my PHP projects, removing old short tags notation:

I refactor internal implementation of:

I worked on three non-public projects.

Keep tuned!

Angel “Java” Lopez

End Of Iteration 2013w50

Previous Post
Next Post

After a series of weeks preparing talks, this week was the exception. No talk, no course to prepare or give. So, I could dedicate the time to code!


I started to refactor the code:

Past week, I migrated the tests to simpleunit. Now, I was splitting a big module in submodules/files, and refactoring the tests to use those modules. I should complete the compilation for browser: the reason to have only one big file was to easy use from browser. Now, I now how to “browserfy” my code.


My Erlang interpreter written in C#:

Past week I added arithmetic operations. Now, I improved the internal implementation, have a better matching, and added more arithmetic operations.

I was working on removing short tags from my PHP projects and

I also worked on three non-public projects, in C#. More fun is coming.

Keep tuned!

Angel “Java” Lopez

End Of Iteration 2013w27

Previous Post
Next Post

An intense week ended. I worked on:


A new implementation of my lisp interpreter, this time trying to compile to JavaScript.


Minor fix, a missing reference in solution without test. Now, it compiles with msbuild from the command line


Minor updates, to be ready for my Sunday post (Spanish)


Only the first test and implementatio (parse an integer, a variable), but I was invited by @mgiglesias to give a talk at PHP Conferences 2013, Argentina. Big people are coming, and great speakers. I will give a talk about PHP and Node.js, for example, calling Node.js from PHP. One thing I want to show, is a PHP compiler to JavaScript that runs on Node.js/Express. It’s using my SimpleGrammar project, from the source.


Minor addition: the capacity of parsing a word, like ‘for’, ‘while’.


Good progress. Having a recursive parser, guided by rules, defined by C# code. All is in place, I need to add a bit of tweaks. I could publish it as Nuget package. But first, I should write same samples. And dog fooding: use it in my own projects.


I updated my in-memory cube. Then, I switched to a customer private project.

AjLisp in Python

Lisp interpreter in Python, only a minor addition, define special form with test.

Talk Introduction to Python

I gave a talk at local Microsoft User Group (Buenos Aires) about Python. My slides:

Work in progress:

More JavaScript, Node.js, Python, Ruby, C# work is coming.

Keep tuned!

Angel “Java” Lopez

Lisp: Links, News And Resources (2)

Previous Post

More links and resource about one my favorites programming languages:

My implementations in C#, three flavors (classic, scheme-like, clojure-like (WIP)) in Ruby in JavaScript in Java

Ruby talks to AutoLISP · davidbl/acadhelper Wiki

The Emacs Problem | Irreal

How Emacs changed my life
By Yukihiro "Matz", Ruby creator

cl-dcf – Common Lisp DSL Compiler Framework – Google Project Hosting

Clojure inventor Hickey now aims for Android In an interview, Clojure founder Rich Hickey discusses future of the functional JVM language, including his mobile aspirations

BiwaScheme Blackboard
BiwaScheme Blackboard is a sandbox for BiwaScheme, a R6RS Scheme interpreter written in JavaScript.
You can edit, run and save Scheme code in your browser.

Can Your Programming Language Do This? – Joel on Software
…Without understanding functional programming, you can’t invent MapReduce, the algorithm that makes Google so massively scalable. The terms Map and Reduce come from Lisp and functional programming. …

mtravers / heroku-cl-example
Example use of Heroku Common Lisp Buildpack

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and Java

Calico Scheme – IPRE Wiki
Calico Scheme is a new implementation of a Scheme-based language for Calico. It implements many core Scheme functions, but also adds some functionality to bring it into line with the other modern languages like Python and Ruby.

Multics Emacs History/Design/Implementation

Lisp REPL in Vendetta Online
Vendetta Online has a Lisp environment (using SBCL) which controls much of its NPC behavior and will soon be in charge of generating player and NPC missions. Partly in order to get around some thread-safety issues, and partly for convenience we built an REPL into a secret chat channel. (it only responds to developer accounts)
Vendetta Online is a MMORPG (massively multiplayer online role-playing game) from Guild Software Inc

European Lisp Symposium

IT Software Community – John W. Verity – LISP Is Back, and It’s Baaaaad!

Why I love Common Lisp and hate Java « Piece of mine

Why I love Ruby (Part 1)
Ruby was also developed slowly, and thoughtfully, from the ground up, using the best-of-the-best from multiple programming paradigms, and from the best-of-breed languages from each of those paradigms … (Smalltalk, Lisp, Perl)

What I want from my Common Lisp vendor and the Common Lisp community

fogus: Lisp in 32 lines of Ruby

ahefner: Fun with Lisp: Just Intonation and Microtonality

ahefner: Lispm archaeology: Compiler Protocols

Web, games, languages ~

luciolang/lucio – GitHub
Lucio is a Lisp-like language running on Ruby
for those of you younger readers or find lisp exotic and never know anything about it, you might try

Emacs Lisp Basics
A guide to the CHICKEN compilation process – The Chicken Scheme wiki
Homoiconic and “unrestricted” self modifying code + Is lisp really self modifying?
Readable s-expressions and sweet-expressions home page: Infix and fewer parentheses in Lisp-like languages
Many people find Lisp s-expressions hard to read as a programming notation. I’ve developed Lisp programs for decades, and though I can read s-expressions well, I remain dissatisfied with their syntactic limitations.

Eleven Theses on Clojure

M-expression – Wikipedia, the free encyclopedia
In computer programming, M-expressions (or meta-expressions) were intended to be the expressions used to write functions in the Lisp programming language. Data to be manipulated using M-expressions was to be written using S-expressions. M-expressions were used for the original theoretical language in early papers about Lisp, but the first working implementation of Lisp interpreted encodings of M-expressions as S-expressions, and M-expressions were never actually implemented.

My Links

Keep tuned!

Angel “Java” Lopez

AjLisp in Ruby (2) Context with Name and Values

Previous Post

One of the first classes I implemented in AjLispRb is the environment. This time I called it a context: a dictionary where to save name/values, to store the atom values. The code:

module AjLisp
class Context
    def initialize(parent = nil)
        @parent = parent
        @values =
    def getValue(name)
        if @values.has_key?(name)
            return @values[name]
        if @parent != nil
            return @parent.getValue(name)
        return nil
    def setValue(name, value)
        @values[name] = value

The class was coded using TDD, the first tests at test/test_context.rb. Some tests:

def test_not_defined_is_nil
    context =
def test_set_and_get_value
    context =
    context.setValue(:foo, "bar")
    assert_equal("bar", context.getValue(:foo))
def test_get_value_from_parent
    parent =
    parent.setValue(:foo, "bar")
    context =
    assert_equal("bar", context.getValue(:foo))

Initially, I used strings for names, but now I’m using Ruby symbols like :foo. I have a test that ensures the independence of parent and child context values:

def test_override_value_from_parent
    parent =
    parent.setValue(:foo, "bar")
    context =
    context.setValue(:foo, "bar2")
    assert_equal("bar2", context.getValue(:foo))
    assert_equal("bar", parent.getValue(:foo))

Each context can have a parent. There is a top context, defined in lib/ajlisp.rb:

module AjLisp
@context =
@context.setValue :quote, FPrimitiveQuote.instance
@context.setValue :first, PrimitiveFirst.instance
@context.setValue :rest, PrimitiveRest.instance
@context.setValue :cons, PrimitiveCons.instance
@context.setValue :list, PrimitiveList.instance
@context.setValue :lambda, FPrimitiveLambda.instance
@context.setValue :flambda, FPrimitiveFLambda.instance
@context.setValue :mlambda, FPrimitiveMLambda.instance
@context.setValue :let, FPrimitiveLet.instance
@context.setValue :define, FPrimitiveDefine.instance
@context.setValue :do, FPrimitiveDo.instance
@context.setValue :if, FPrimitiveIf.instance
@context.setValue :definef, FPrimitiveDefinef.instance
@context.setValue :definem, FPrimitiveDefinem.instance
@context.setValue :+, PrimitiveAdd.instance
@context.setValue :-, PrimitiveSubtract.instance
@context.setValue :*, PrimitiveMultiply.instance
@context.setValue :/, PrimitiveDivide.instance
def self.context
    return @context
# ...

New context are created in many primitives. At the begin, there is a top context like:

If you have a defined form that returns the second element of a list:

(define second (a) (first (rest a)))

now you have a top context with the new slot:

The top context has a new slot named second with a lambda value (lambda (a) (first (rest a))

When you invoke:

(second (quote (one two three)))

during the invocation a new context is created, its parent set to the top context, and having a new name/value pair:

That context is discarded after second evaluation (unless the context were referenced by recently created closure, details in upcoming post). When you define a simple value:

(define one 1)

the top context is modified, to have a new name/value pair:

Next topics: primitives and special form primitives, their invocation, closures, macros, native methods invocation.

Keep tuned!

Angel “Java” Lopez

AjLisp in Ruby (1) Structure, Classes and Tests

Next Post

I’m learning and practicing Ruby writing my AjLisp interpreter, as usual (early this year, I ported it to Javascript). TDD is my friend: write a test, run in red, code, run in green, refactor, and so on. My code, work in progress, is at:

Initially, I wrote a single file, following the great and simple example:

Notice that Ruby has a ‘test/unit’ package, already in place, ready to use, after installation. After some research, I spitted the file in production code, and test code. I want to build a gem (Ruby package), so I studied the tutorial:

I have pending readings:

My code is not a gem, yet. But it have some gem structure:

The lib contains a single file:

require 'ajlisp/list.rb'
require 'ajlisp/named_atom.rb'
require 'ajlisp/context.rb'
require 'ajlisp/string_source.rb'
require 'ajlisp/token.rb'
require 'ajlisp/lexer.rb'
require 'ajlisp/parser.rb'
require 'ajlisp/primitive.rb'
require 'ajlisp/primitive_first.rb'
require 'ajlisp/primitive_rest.rb'
require 'ajlisp/primitive_cons.rb'
require 'ajlisp/primitive_list.rb'
require 'ajlisp/primitive_closure.rb'
require 'ajlisp/fprimitive.rb'
require 'ajlisp/fprimitive_quote.rb'
require 'ajlisp/fprimitive_lambda.rb'
require 'ajlisp/fprimitive_flambda.rb'
require 'ajlisp/fprimitive_let.rb'
require 'ajlisp/fprimitive_closure.rb'
require 'ajlisp/fprimitive_define.rb'
require 'ajlisp/primitive_add.rb'
module AjLisp
@context =
@context.setValue "quote", FPrimitiveQuote.instance
@context.setValue "first", PrimitiveFirst.instance
@context.setValue "rest", PrimitiveRest.instance
@context.setValue "cons", PrimitiveCons.instance
@context.setValue "list", PrimitiveList.instance
@context.setValue "lambda", FPrimitiveLambda.instance
@context.setValue "flambda", FPrimitiveFLambda.instance
@context.setValue "let", FPrimitiveLet.instance
@context.setValue "define", FPrimitiveDefine.instance
@context.setValue "+", PrimitiveAdd.instance
def self.context
    return @context
def self.evaluate(context, item)
    if item.is_a? List or item.is_a? NamedAtom
        return item.evaluate(context)

    return item

I wrote some primitives (normal forms, and special forms: the latter don’t evaluate their parameters before apply, like quote or define). Notice that the additional files are in a subfolder ajlisp inside lib, why? Because when this code is installed as a gem, all lib file code could be include with require(‘thenameofrubyfile’). If I put other files than ajlisp.rb, i.e. list.rb or atom.rb, those file names could be required, and maybe a name collision with other gems could occur. Then, the recommended practice (see other gem code in your Ruby installation folder) is to put additional files below lib folder.

In the test folder there is a top test.rb file that includes other test files:

require 'ajlisp'
require 'test/unit'
require "test_list.rb"
require "test_named_atom.rb"
require "test_context.rb"
require "test_string_source.rb"
require "test_token.rb"
require "test_lexer.rb"
require "test_parser.rb"
require "test_primitive_first.rb"
require "test_primitive_rest.rb"
require "test_primitive_cons.rb"
require "test_primitive_list.rb"
require "test_primitive_closure.rb"
require "test_primitive_add.rb"
require "test_fprimitive_quote.rb"
require "test_fprimitive_lambda.rb"
require "test_fprimitive_let.rb"
require "test_fprimitive_closure.rb"
require "test_fprimitive_flambda.rb"
require "test_fprimitive_define.rb"
require "test_evaluate"

so you can run the tests from command line:

ruby –Ilib;test test\test.rb

If you have Windows, the runtest.cmd file contains this line.

Some test code:

require 'ajlisp'
require 'test/unit'
class TestList < Test::Unit::TestCase
    def test_create_with_first
        list ="foo")
        assert_equal("foo", list.first)

    def test_create_with_first_and_rest
        rest ="bar")
        list ="foo", rest)
        assert_equal("foo", list.first)

    def test_create_from_array
        list = AjLisp::List.make [1, "a", "foo"]
        assert_not_nil list
        assert_equal 1, list.first
        assert_equal "a",
        assert_equal "foo",

Every list is an object of this class, list.rb:

module AjLisp
class List
    attr_reader :first
    attr_reader :rest

    def initialize(first=nil, rest=nil)
        @first = first
        @rest = rest

    def evaluate(context)
        form = AjLisp::evaluate(context, @first)
        form.evaluate(context, self)

    def self.make(array)
        if array and array.length > 0
            first = array.shift

            if first.is_a? Array
                first = make(first)
            elsif first.is_a? Symbol
                first = first.to_s

            return first, make(array)

        return nil

The accessors first and rest are read-only. Thanks to the untyped nature of Ruby (like in Javascript) the implementation of this interpreter is straightforward, or without much code ceremony, at least.

In my new tests, I included the code into the AjLisp module, so I don’t need to write AjLisp:: prefix before referencing a class:

require 'ajlisp'
require 'test/unit'
module AjLisp
class TestLexer < Test::Unit::TestCase
    def test_get_atom_token
        source = "atom"
        lexer = source
        token = lexer.nextToken

        assert_not_nil token
        assert_equal "atom", token.value
        assert_equal TokenType::ATOM, token.type
        assert_nil lexer.nextToken
    def test_get_atom_token_with_spaces
        source = " atom "
        lexer = source
        token = lexer.nextToken

        assert_not_nil token
        assert_equal "atom", token.value
        assert_equal TokenType::ATOM, token.type
        assert_nil lexer.nextToken

Next topics: some implementation details, primitives vs fprimitives, context (nested environments with name/values), lambda and closures, lexer and parser.

Next steps: complete primitives (let, letrec, definef, do, if…), macro (mlambda, definem, macro expansion…)

Keep tuned!

Angel “Java” Lopez