March 15, 2011

Koz: 100% event driven programming language

Vision
Koz is an object oriented programming language that is purely event driven. Koz is pronounced as chaos, but can also be pronounced as cause. The philosophy behing koz is that chaos is ordened by means of cause and effect. Separation of concerns by language design: no direct object to object interactions. A system would consist of a number of autonomous objects that only act on the occurence of events (triggers) in their context. Objects never explicitely connect with other objects.  

The basic idea
The main idea is that Objects only act when triggered by events effected by objects in its proximity. No direct invokations. Everything is strictly causal. The result of an action always is an event. Events can trigger other actions to run, local (scope) statements to execute and other objects to act. There is no need for loops or conditional statements. Just a list of unordered statements. Each statement has an identified trigger and and identified effect. During runtime, the order of statement execution is determined. The compiler or VM (or interpreter, as this could well be a dynamic scripting language) should be able to determine unreachable statements (never executed because it will never be triggered).

Primary mechanism
The primary mechanism of koz is based on triggers and effects. A trigger is the occurrance of an event. A statement can only be executed if it is triggered by an event that occurred within the scope of the statement. Scoping is similar to other programming languages (blocks). There are two scope types in Koz: block ({ }) and action (compare to class method). A block or action is finished when certain conditions are met. It results in an event (for instance Action.end) into its surrounding scope (context)

Objects can be aggregates of other objects. An aggregate scopes the events of the objects inside.A trigger is bound to an event type, never to a specific event instance.

Syntax (BNF)
predifinedEvent = init|changed|disposed|...
definedEvent = predefinedEvent | identifier
trigger = definedEvent | definedEvent identifier
variable = type identifier {(trigger(,trigger)* : expression;)+}

Predefined events:
scope-init
scope-end

About variables:
no direct mutations, only through predefined triggers
predefined events: init, changed, disposed

Example
The example below counts the lines that are entered in standard input. To do so, each line is added to a List object. Notice how the trigger System.in.lineEntered changes the state of myList. the new line is added to the list by using the + operator. Also notice how the variable lineCounter is set to 0 (zero) through the occurance of the init event, and the myList.disposed event. And each time the event myList.changed occurs, the value of lineCounter is set to the size of myList.


List myList {
  System.in.lineEntered line: self + line;
};
int lineCounter {
  myList.changed: myList.size;
  init, myList.disposed: 0
};


No comments: