Op 19 mrt. 2012, om 21:10 heeft Benoît Fleury het volgende geschreven:

> I was wondering if there is any language out there that lets you describe the 
> behavior of an "object" as a grammar.
> ...
> If we assume an object receive a tick event to represent time, and using a 
> syntax similar to ometa, we could write a simplistic behavior of an ant this 
> way:
> …

You may check out "Ants and Agents: a Process Algebra Approach to Modelling Ant 
Colony Behaviour"
http://www2.math.uu.se/~david/web/SumpterBlanchardBroomhead01.pdf


Object oriented languages may very well be extended with Process Algebra, or 
more particularly, with the Algebra of Communicating Processes (ACP).
You may regard ACP as a kind of generalization of Boolean algebra with "atomic 
actions". Operators + and · denote choice and sequence. The multiplication is 
therefore non-commutative, when actions are involved. The + operator is 
exclusive for actions: if an atomic action happens in one operand, then no 
action may happen any more in another operand.
Instead of 0 (false) and 1 (true) the neutral elements for choice and sequence 
are "deadlock" and an "empty process". 

So far, ACP is quite similar to grammar formalisms such as BNF. But there is 
more.
Starting from the 2 base operators + and · others may be specified by means of 
axioms, e.g. for

- normal parallelism
- and-parallelism
- or-parallelism
- interruption
- disruption  

I am working on extending Scala with ACP. Classes get process definitions in 
refinements that I call "scripts". Like methods these may have parameters. 
The ACP atomic actions correspond with code fragments in the base language. 
These code fragments may be have several execution modes, such as:

- a normal piece of code
- event handling code
- code in its own thread
- code in the GUI thread
- code with time constraints, either real time or simulation time
- code to run on specific processors

Communication between processes is through "shared" scripts, or . E.g. a 
typical communication may be defined by

  send, receive = {whatever}

Then 2 parallel callers of "send" and "receive" are needed in order to get 1 
script body executed; I'd coin the term "multicall". A bit of syntactic sugar 
yields communication over named channels.
Communication over named pipes becomes possible using another parallel operator 
comparable to the bar in Unix command shell language. Linda-style communication 
is also supported.

The grammar style appears to be convenient for specifying GUI controllers. 
E.g., the following script states that a user can give a certain command by 
clicking a "Start" button or by pressing the "s" key:

  startCommand = click(startButton) + key('s')

You could even define that "click" and "key" are implicit scripts, so that the 
definition would become

  startCommand = startButton + 's'

So the implicit scripts allow for adding a button and a character, and the 
result is intended to describe a command. The algebra is therefore now on both 
processes and data items. We may reason about such item definitions without a 
specific operationalization in mind. E.g. the implicit scripts "click" and 
"key" may be abstract; in one subclass they would implement user input actions; 
in another subclass they could be output actions: triggering the GUI events, 
rather than handling them. 

To end this blurp: my ACP extension is reasonably fast and easy to implement. 
The implementation as a DSL is currently about 2000 lines of Scala code, and 
this may grow to about 3000 (and hopefully shrink thereafter again). I will 
present a paper on extending next month at Scala Days 2012. For an abstract, 
see http://days2012.scala-lang.org/node/92. 
A non-final version of the paper is at 
http://code.google.com/p/subscript/downloads/detail?name=SubScript-TR2012.pdf
I would appreciate feedback here at the fonc list.

_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to