Break is over

Things are heating up, especially here in Germany. There is much to do for the phlegmatic programmer these days, but first he needs to finish writing his Babel-17 paper.

It would be nice to have a running Babel-17 implementation to accompany the paper. To achieve this, there will soon be a new spec of Babel-17, Babel-17 v0.21. This spec will be stripped off the module system that was described in Babel-17 v0.2, because the phlegmatic programmer still needs more experience in purely functional structured programming before deciding on a module system. A complete implementation of Babel-17 v0.21 will help to gain this experience.

Babel-17 v0.21 will provide for the possibility to derive an object from other objects. Let’s say you have two objects aObj and bObj:

val aObj = object
  def a = 10
end

val bObj = object
  def b = 20
end

You could derive a third object from these two like this:

val cObj = object +(aObj, bObj)
  def c = 30
end

The above is equivalent to:

val cObj = object
  def a = 10
  def b = 20
  def c = 30
end

Object composition like illustrated above looks simple enough, but as always, the devil is in the details.
Consider we changed the definition of aObj to be:

val aObj = object
  def b = 100
end

What would cObj.b then evaluate to, 100 or 20 ? Babel-17 resolves this question by giving messages in bObj precedence over messages in aObj . Therefore the following would evaluate to true:

cObj.b == 20

Now, instead of the above, imagine we instead changed aObj to:

val aObj = object
  def a = this
  def b = 100
end

The value of cObj.b would still be 20. But what would be the value of cObj.a.b ?
If your guess is 100, then you are right. If you compose objects via +, then a “this” that appears in the message definition of a parent still refers to that parent after composition. If you want that “this” points to the composed object, you have to compose objects via *. Therefore, with

val cObj = object *(aObj, bObj)
  def c = 30
end

the expression cObj.a.b would actually evaluate to 20.

Advertisements

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


%d bloggers like this: