Pure Babel-17: Built-in Types

As you have seen in the previous post, the wish list for the features and properties of Babel-17 is quite long.

My ideas of how to combine all these different requirements are not firmly established yet, so let’s start with the easy stuff first: Pure Babel-17. Pure Babel-17 does not take the imperative features into account.

A word of warning: if later on I see that something said here or in later parts of the Babel-17 discussion does not fit together with features introduced later, I will freely edit stuff to get a consistent whole.

Like any other programming language, Babel-17 manipulates data. A unit of data is called an object. Every object has a type.

Pure Babel-17 knows the following two built-in simple types:

  • INTEGER : this is the type of all positive, zero, and negative integer numbers. Integer constants can be written down in decimal (10), binary (0b1010), hexadecimal (0xA or 0xa) and octal (0o12) notation.
  • STRING : this is the type of all legal Unicode strings. String constants are written between quotation marks (“Hello world!”). All valid unicode characters can appear between quotation marks except the backslash character, the quotation mark character, or a newline character. There are special character sequences to encode even these characters in a string.

There are four built-in composite types:

  • LIST: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] is the same as (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), but [0] is a list and (0) is just another notation for 0. Also, [ ] and ( ) both denote the empty list.
  • SET : {} is the empty set, and {0, 1, 2, 3} is the same set as {0, 1, 2, 0, 3}.
  • MAP : {->} is the empty map, and {0 -> 1, 3 -> 10} is the map that sends 0 to 1 and 3 to 10.
  • TAGEXPR: If T is a tagid, and p is an object, then T p  is a TAGEXPR. A tagid starts with a capital letter and continues with capital letters, digits or underscores. For example, BABEL_17 is a tagid, but BABEL-17 is not, neither is Babel17. Just writing T also gives you a TAGEXPR; it is a synonym for T ( ) .

Furthermore there is the FUNCTION type. FUNCTION literals are written like this: x => x*x. This particular literal for example can be used as square function on integers.

There are more ways to define functions. And while these are really ALL built-in types, it IS possible to define custom types. More about both topics will be said in later posts.


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: