The Synchronous Blog

A blog about reactive programming languages.

Reactivity in LuaGravity

with 3 comments

The reactivity in LuaGravity is achieved with implicit method invocation. So what?

Suppose we have the following class definition:

MyClass = class {
   function init (self, name)
       self._name = name
   end
   function ping (self)
       print('ping', self._name)
   end
   function pong (self)
       print('pong', self._name)
   end
}

That is, a simple class with a property name and two methods: ping and pong.

Now we create three objects and link some of their methods:

a = MyClass('a')
b = MyClass('b')
c = MyClass('c')

LINK(a.ping, b.pong)
LINK(b.pong, c.ping)
LINK(c.ping, a.pong)

Then, a simple call to a.ping yields in:

> a.ping()
ping    a
pong    b
ping    c
pong    a

That simple! A method is implicitly called in reaction to a call in another condition method.
Comparing to event-driven programming, there’s no need to define or post events, it’s all made implicitly. Much less verbosity.


The reactive variables of LuaGravity (shown here and here) override Lua’s default behavior for attribution.

So that

b = a
a = 2

Is equivalent to

LINK(a.update, b.update)
a.update(2)

Variables are, instead, special objects with an update method.

The parameter in a method call is propagated through its link chain as in a pipeline.
This way the value 2 is also passed to b.update.


A simple example of using LuaGravity in multimedia applications would go like this:

LINK(video1.start, video2.start)
LINK(video3.stop,  video4.start)

The first link makes video1 and video2 play in parallel, while the second link makes video3 and video4 play in sequence.

By overloading the operators + and * one could just write:

video1 + video2  -- play in parallel
video3 * video4  -- play in sequence

In LuaGravity, event definition is implicit, event posting is implicit and event linking may also be implicit (through operator overloading).

Given the amount of times the word implicit appears in this text, could LuaGravity be considered an implicit implicit invocation system?

Advertisements

Written by francisco

September 1, 2008 at 12:05 am

3 Responses

Subscribe to comments with RSS.

  1. “The parameter in a method call is propagated through its link chain as in a pipeline.”

    Is the parameter allowed to be changed inside a method call? The link chain would be much more useful if state changes and computation results are propagated through it. This information is not implicit in your text. :)

    P.S.: Quite good syntax, by the way.

    Alexandre

    September 5, 2008 at 11:33 am

  2. You are right, it’s not implicit. :)
    The return value of each method in the chain is passed as a parameter to the next method.
    So, it’s possible (and common) that the information in a dataflow is changed from one end to the other as in filters.

    francisco

    September 5, 2008 at 3:57 pm

  3. […] The LINK reactivity primitive was already presented in this post. LINK makes the use of event-driven paradigm easier, avoiding all the bureaucracy of events […]


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: