System library of Babel-17

Part of Babel-17 is already written in Babel-17. There are around 200 lines of Babel-17 collected in the system library of Babel-17 which are used to implement messages to objects of built-in types. For example, Babel-17 translates the code

c.take n

where c is an object of type list, vector, set or map into a call

coll_take c n

of the system library function coll_take, where coll_take has the following implementation:

Writing as much code as possible of the library in Babel-17 itself makes its implementation more portable and also easier to understand, because all issues relating to concurrency, laziness, exceptions etc. are dealt with automatically.

Above code is also a good starting point to learn Babel-17. It employs many important concepts and language constructs. When you fully understand above example, you are well on your road to become a Babel-17 expert. It also employs the try … catch expression which is new and has not been available in v0.21 . The code

try
  b
catch
  case p1 => b1
  ...
  case pn => bn
end

is similar in meaning to

match
  begin
    b
  end
case (exception p1) =>  b1
...
case (exception pn) =>  bn
case v => v
end

The main difference between above two code fragments is that in the try-version, the argument b is a statement which can participate in linear scope. The argument of match is a simple expression, though, and therefore there are no variables in linear scope.

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: