Powered by IPowerWeb.com
  home      projects    papers    reference    music    images    quotes    internet links   weblog © 2004 Mike Austin  
  e-mail me   something else
Projects : Inertia
without music, life would be an error
– nitzsche
 
 

Brief Overview

    Inertia is a programming language that has been brewing in my head for a few years now. It's a language based on objects, blocks (closures) and messages, with syntax and semantics borrowed from several languages -- refactored and stripped of extraneous symbols and other artifacts. There is nothing yet to download, I've only constructed prototypes and test implementations.

    Inertia's main goals are:

    • Make simple things very simple, but more complex things possible
    • Get rid of extraneous symbols and delimiters in the syntax, but...
    • Add a little syntactic sugar for collection access and assignment
    • Use higher order functions to allow native code to execute more often
    • Create a runtime in C++ which is very easy to use and extend

      Maybe not in the first versions, but I'd also like to incorporate these later on:

    • Pattern matching for method arguments -- for types and values
    • Predicate dispatching and support for DBC and metaprogramming
    • Coroutines, generators and thread support for multi-processor machines

Basic Syntax

    The syntax of Inertia is a mix between Python, Ruby and Self — anonymous blocks by indentation, and keyword messages:

    y = 45 sin     -- send message "sin" to 45, then
                   -- send message "y:0.70710" to "self"

    1..10 each: i  -- create range object with 1..10, then
      puts: i      -- send message "each:i[block]"

    if x in: 1,2,3 -- send message "in:[1,2,3]" to x
      puts: 'yes'  -- if true, execute block

    Every message can contain an anonymous block. Blocks can be written on the same line by using "|", which allows for a sort of meta-syntax – the following code contains two levels of blocks, one using "|" and one by indentation:

    1..255 each: i | thread:
      time = ping: '10.0.0.' + i
      list add: '10.0.0.' + i + ": " + time

    More examles:

    local i, j         -- local variables
    attr x, y = 0      -- object attributes
    const true = 1     -- constant literal
    enum style = Border, NoBorder, Dialog  -- enumeration

    object Button: Visual

      attr  x = 10, y = 10
      local title = 'Untitled'

      method title: string [String]
        self title = string

Language Features

    Predicate Dispatching

    method doit: str [length > 100]  -- method table is modified by
      puts: 'a long string'          -- invariants to remove lookup

    Multi-Methods

    method doit: str [String]
      puts: 'a long string'

    Pattern Matching

    method factorial: 0 | 1
    method factorial: n | n * factorial: n - 1

    Continuations

    method inverse: n
      while: 1 | yield 1 / n

Language Comparison

    The syntax of Inertia is a refactorization of other languages:

    Python

    filter( lambda x % 2 != 0 and x % 3 != 0, range(2, 25) )
    [x for x in range(2, 25) if x % 2 != 0 and x % 3 != 0
    ]

    Smalltalk

    (2 to: 25) select: [:i | i % 2 != 0 and: [x % 3 != 0]]

    Ruby (2..25).select { |i| i % 2 != 0 and i % 3 != 0 }
    Inertia 2..25 select: i | i % 2 != 0 and i % 3 != 0

Runtime Library

    I wanted the C++ runtime to be almost as easy to use as the language, so I created a dynamically typed system where one can use symbols (enumerated strings) for efficiency, or strings for simplicity. The virtual machine and object primitives are written in this system.

    Value n = 10, y = n (sin_);
    Value str = "Hello";
    str (replace_, "lo", "ium");
    Value MyObject = Object (clone_);
    MyObject (attr_, "aVariable", 10);
    MyObject (slot_, "myMethod", &aNativeFunction);

Detailed Examples

    object Matrix: Object

      local rows, cols
      local matrix = Array new: rows by: cols

      method init: rows by: cols
        rows, cols = rows, cols

      method *: other
        local result = Matrix new
        local sum = 0
        1..rows,1..cols each: i, j
          sum = 0
          1..cols each: k
            sum += matrix.i,k * other.k,j
            result.i,j = sum

    sub = string.1..5
    pos = string.'mike'

    File read: 'test.txt'
       eachLine: line | line print

 
News

I have written prototypes for the runtime, the virtual machine, multi-methods and the parser. I am still learning other languages, and will probably not work on the language as a whole until I feel comfortable with the direction of the language.

     

 

 
 
09162 hits since November 11, 2003 · Last modified: March 16, 2010