Archive for March 2011

Prolog promptI am tackling a third language from the book today. This is Prolog and we are not complete strangers. I remember using it at uni for some lab practices and I can remember we didn’t get along like a house on fire. I found Prolog strange and at odds with imperative mindset I held back then. Now that I am a bit older, I find the fact that language is a bit different appealing and intriguing and I look forward to see why was it designed in such manner and what benefits it’s approach brings.

Day 1 explains the very basic concepts behind the language. It explains its syntax which is very simple. Main constructs are atoms, variables, facts and rules.


parent(me, mother).
parent(brother, mother).
parent(mother, granddad).

grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
sibling(X, Y) :- \+(X = Y), parent(X, Z), parent(Y, Z).
% X, Y and Z are variables

No syntax highlighting is available – I guess that the “hip crowd” does not grok Prolog. Read on »

It is day 3 with Io and the subjects that we are tackling are DSLs (domain specific languages) with a help from metaprogramming and concurrency in Io.

As you can expect Io lends itself very naturally to defining DSLs due to its proverbial flexibility – after all the ability to change practically everything what it does, allows you to change the nature of Io to your specific problem domain.

In book this is explained through a simple example of defining a DSL in 13 lines of code that allows map definition in JSON like syntax. Homework 2 sets a similar but simpler goal of defining a syntax based on brackets that allows definition of lists. So here it is:

HW2: Create a list syntax that uses brackets

squareBrackets := method(
    call message arguments map(value,
        self doMessage(value)

aList := [1, 2, 30, "forty"]
aList println
aList at(3) println

Read on »