Angel \”Java\” Lopez on Blog

January 21, 2014

End Of Iteration 2014w03

Filed under: AjErl, AjLisp, C Sharp, Iteration, JavaScript, NodeJs, Open Source Projects — ajlopez @ 6:25 pm

Previous Post
Next Post

Great week extending interpreters.

AjErl

My Erlang implementation as interpreter in C#

https://github.com/ajlopez/AjErl

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.

AjLisp

I was working on my C# implementation

https://github.com/ajlopez/AjLisp

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.

Aktores

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

https://github.com/ajlopez/Aktores

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

https://github.com/ajlopez/SimpleGrammar

to fix a bug detected consuming the library from RuScript:

https://github.com/ajlopez/RuScript

I’m using SimpleGrammar in

https://github.com/ajlopez/ScaScript

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

Others

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

https://github.com/ajlopez/AjGenesisNode-Sinatra

to use a modular instead of classic approach.

More fun is comming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

December 24, 2013

End Of Iteration 2013w51

Filed under: AjErl, AjLisp, C Sharp, Iteration, JavaScript, Open Source Projects, PHP — ajlopez @ 5:04 pm

Previous Post
Next Post

My main outcome for this week:

AjErl

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

https://github.com/ajlopez/AjErl

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:
https://github.com/ajlopez/AjConsorSite
https://github.com/ajlopez/Inmob

I refactor internal implementation of:
https://github.com/ajlopez/AjLispJs
https://github.com/ajlopez/SimpleYaml

I worked on three non-public projects.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

December 17, 2013

End Of Iteration 2013w50

Filed under: AjErl, AjLisp, C Sharp, Iteration, JavaScript, NodeJs, Open Source Projects — ajlopez @ 4:54 pm

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!

AjLispJs

I started to refactor the code:

https://github.com/ajlopez/AjLispJs

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.

AjErl

My Erlang interpreter written in C#:

https://github.com/ajlopez/AjErl

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 https://github.com/ajlopez/AjConsorSite and https://github.com/ajlopez/Inmob

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

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

November 19, 2013

July 8, 2013

End Of Iteration 2013w27

Previous Post
Next Post

An intense week ended. I worked on:

SimpleLisp

https://github.com/ajlopez/SimpleLisp

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

Mass

https://github.com/ajlopez/Mass

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

TddOnTheRocks

https://github.com/ajlopez/TddOnTheRocks

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

PageJs

https://github.com/ajlopez/PageJs

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.

SimpleGrammar

https://github.com/ajlopez/SimpleGrammar

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

GrammGen

https://github.com/ajlopez/GrammGen

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.

Memolap

https://github.com/ajlopez/Memolap

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

AjLisp in Python

https://github.com/ajlopez/AjLispPython

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:

https://github.com/ajlopez/TalkPythonIntro

Work in progress:

https://github.com/ajlopez/AprendiendoPython
https://github.com/ajlopez/ProgrammingLanguagesSamples

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

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
@ajlopez

June 5, 2012

May 20, 2012

April 10, 2012

Lisp: Links, News And Resources (2)

Filed under: AjLisp, Functional Programming, Links, Lisp, Programming Languages — ajlopez @ 1:23 pm

Previous Post

More links and resource about one my favorites programming languages:

My implementations
http://ajlopez.wordpress.com/category/ajlisp/
http://code.google.com/p/ajlisp/ in C#, three flavors (classic, scheme-like, clojure-like (WIP))
https://github.com/ajlopez/AjLispRb in Ruby
https://github.com/ajlopez/AjLispJs in JavaScript
https://github.com/ajlopez/AjLispJv in Java

Ruby talks to AutoLISP · davidbl/acadhelper Wiki
https://github.com/davidbl/acadhelper/wiki/Ruby-talks-to-AutoLISP

The Emacs Problem | Irreal
http://irreal.org/blog/?p=384

How Emacs changed my life
http://www.slideshare.net/yukihiro_matz/how-emacs-changed-my-life
By Yukihiro "Matz", Ruby creator

cl-dcf – Common Lisp DSL Compiler Framework – Google Project Hosting
http://code.google.com/p/cl-dcf/

Clojure inventor Hickey now aims for Android
http://www.techworld.com.au/article/419328/clojure_inventor_hickey_now_aims_android/?fp=16&fpid=1 In an interview, Clojure founder Rich Hickey discusses future of the functional JVM language, including his mobile aspirations

BiwaScheme Blackboard
http://blackboard.biwascheme.org/
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
http://www.joelonsoftware.com/items/2006/08/01.html
…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
https://github.com/mtravers/heroku-cl-example
Example use of Heroku Common Lisp Buildpack

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and Java
http://www.amazon.com/dp/0136070477

Calico Scheme – IPRE Wiki
http://calicoproject.org/Calico_Scheme
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
http://www.multicians.org/mepap.html

Lisp REPL in Vendetta Online
http://www.a1k0n.net/2005/11/04/lisp-repl-vendetta-online.html
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)
See http://www.vendetta-online.com/
http://www.vendetta-online.com/h/help.html
Vendetta Online is a MMORPG (massively multiplayer online role-playing game) from Guild Software Inc

European Lisp Symposium
http://european-lisp-symposium.org/

IT Software Community – John W. Verity – LISP Is Back, and It’s Baaaaad!
http://www.itsoftwarecommunity.com/author.asp?doc_id=238067&section_id=1624

Why I love Common Lisp and hate Java « Piece of mine
http://kuomarc.wordpress.com/2012/01/27/why-i-love-common-lisp-and-hate-java/

Why I love Ruby (Part 1)
http://duckpunching.github.com/2011/02/26/why-i-love-ruby-part-1.html
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
http://groups.google.com/group/comp.lang.lisp/msg/4563e504dba92253?pli=1

fogus: Lisp in 32 lines of Ruby
http://blog.fogus.me/2012/01/25/lisp-in-40-lines-of-ruby/

ahefner: Fun with Lisp: Just Intonation and Microtonality
http://ahefner.livejournal.com/19604.html

ahefner: Lispm archaeology: Compiler Protocols
http://ahefner.livejournal.com/19280.html

Web, games, languages ~ jlongster.com
http://jlongster.com/2012/01/16/outlet-gets-a-personality.html

luciolang/lucio – GitHub
https://github.com/luciolang/lucio
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
https://plus.google.com/113859563190964307534/posts/Xw8M6WMeaDn

Emacs Lisp Basics
http://xahlee.org/emacs/elisp_basics.html
A guide to the CHICKEN compilation process – The Chicken Scheme wiki

http://wiki.call-cc.org/chicken-compilation-process
Homoiconic and “unrestricted” self modifying code + Is lisp really self modifying?

http://stackoverflow.com/questions/8490616/homoiconic-and-unrestricted-self-modifying-code-is-lisp-really-self-modifyin
Readable s-expressions and sweet-expressions home page: Infix and fewer parentheses in Lisp-like languages

http://www.dwheeler.com/readable/index.html
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
http://www.tbray.org/ongoing/When/200x/2009/12/01/Clojure-Theses

M-expression – Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/M-expression
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
http://delicious.com/ajlopez/lisp

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

December 15, 2011

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 = Hash.new
    end
    
    def getValue(name)
        if @values.has_key?(name)
            return @values[name]
        end
        
        if @parent != nil
            return @parent.getValue(name)
        end
        
        return nil
    end
    
    def setValue(name, value)
        @values[name] = value
    end
end
end

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

def test_not_defined_is_nil
    context = AjLisp::Context.new
    assert_nil(context.getValue(:foo))
end
def test_set_and_get_value
    context = AjLisp::Context.new
    context.setValue(:foo, "bar")
    assert_equal("bar", context.getValue(:foo))
end
def test_get_value_from_parent
    parent = AjLisp::Context.new
    parent.setValue(:foo, "bar")
    context = AjLisp::Context.new(parent)
    assert_equal("bar", context.getValue(:foo))
end

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 = AjLisp::Context.new
    parent.setValue(:foo, "bar")
    context = AjLisp::Context.new(parent)
    context.setValue(:foo, "bar2")
    assert_equal("bar2", context.getValue(:foo))
    assert_equal("bar", parent.getValue(:foo))
end

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

module AjLisp
@context = Context.new
@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
end
# ...
end

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

http://www.ajlopez.com

http://twitter.com/ajlopez

December 2, 2011

AjLisp in Ruby (1) Structure, Classes and Tests

Filed under: AjLisp, Lisp, Programming Languages, Ruby, Test-Driven Development — ajlopez @ 10:57 am

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:

https://github.com/ajlopez/AjLispRb

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

http://kanemar.com/2006/03/04/screencast-of-test-driven-development-with-ruby-part-1-a-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:

http://guides.rubygems.org/

I have pending readings:

http://speakerdeck.com/u/pat/p/cut-polish-a-guide-to-crafting-gems
http://blog.thepete.net/2010/11/creating-and-publishing-your-first-ruby.html

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.new
@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
end
def self.evaluate(context, item)
    if item.is_a? List or item.is_a? NamedAtom
        return item.evaluate(context)
    end

    return item
end
end

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 = AjLisp::List.new("foo")
        assert_equal("foo", list.first)
        assert_nil(list.rest)
    end

    def test_create_with_first_and_rest
        rest = AjLisp::List.new("bar")
        list = AjLisp::List.new("foo", rest)
        assert_equal("foo", list.first)
        assert_not_nil(list.rest)
        assert_equal("bar", list.rest.first)
        assert_nil(list.rest.rest)
    end

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

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
    end

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

    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 = NamedAtom.new first.to_s
            end

            return List.new first, make(array)
        end 

        return nil
    end
end
end

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 = StringSource.new "atom"
        lexer = Lexer.new source
        token = lexer.nextToken

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

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

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

http://www.ajlopez.com

http://twitter.com/ajlopez

Older Posts »

The Shocking Blue Green Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 65 other followers