[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

wishing of reactive programming in ruby

ashishwave

8/17/2007 2:31:00 PM

ruby integrates power of functional programming from lisp , purest OO
from smalltalk, prototype oriented power from self etc etc into one
single language

i just was wondering that whether the heavy developers/users of
reactive languages like kanaputs or reactive-C etc will ever get
reactive features in ruby.

in kanaputs, If the variable 'c' is defined as c = a + b; and if the
reactivity of 'c' is set (c.reactive = true;), then each time the
value of 'a' or 'b' changes then the value of 'c' is updated as the
result of the addition


bye :-)
Ashish
ashishwave@yahoo.com.

14 Answers

Trans

8/17/2007 4:18:00 PM

0



On Aug 17, 7:34 am, ashishwave <ashishw...@gmail.com> wrote:
> ruby integrates power of functional programming from lisp , purest OO
> from smalltalk, prototype oriented power from self etc etc into one
> single language
>
> i just was wondering that whether the heavy developers/users of
> reactive languages like kanaputs or reactive-C etc will ever get
> reactive features in ruby.
>
> in kanaputs, If the variable 'c' is defined as c = a + b; and if the
> reactivity of 'c' is set (c.reactive = true;), then each time the
> value of 'a' or 'b' changes then the value of 'c' is updated as the
> result of the addition

That's interesting --a form of rational programming (like Prolog).

But I think it is far outside the scope of Ruby's design.

T.


benjohn

8/17/2007 4:35:00 PM

0

>
>
> On Aug 17, 7:34 am, ashishwave <ashishw...@gmail.com> wrote:
>> ruby integrates power of functional programming from lisp , purest OO
>> from smalltalk, prototype oriented power from self etc etc into one
>> single language
>>
>> i just was wondering that whether the heavy developers/users of
>> reactive languages like kanaputs or reactive-C etc will ever get
>> reactive features in ruby.
>>
>> in kanaputs, If the variable 'c' is defined as c = a + b; and if the
>> reactivity of 'c' is set (c.reactive = true;), then each time the
>> value of 'a' or 'b' changes then the value of 'c' is updated as the
>> result of the addition
>
> That's interesting --a form of rational programming (like Prolog).
>
> But I think it is far outside the scope of Ruby's design.

I'm about to go home. Damn.

I've been very interested in reactive programming for about 10 years,
although I've never heard of it reffered to as such. The Empirical
Modelling group at Warwick University did a lot of work on it in a
language called EDEN. They called it Definative Programming (think
reactive is a much better name, as it happens).

It's entirely possible to build a library in an imperative language that
will provide reactive programming capabilities. I've previsouly used a
similar idea for a GUI application in C++, and it made implementation of
pretty complex change propagation very easy.

My recent thinking is that reactive programming shares a great deal with
software transactional memory, and could share a lot of infrastructure.

Something the Empirical Modelling group at Warwick found was that
Reactive Programming is also very useful for making systems that are
composable. They could often take a few models they'd built, and easily
combine them, make a few other changes, and come up with a new useful
model. This is curious because composability is also a strong advantage
of STM.

My personal opinion is that reactive programming is _the_ pattern for
building any kind of interactive software (ie - something that doesn't
just process a batch of data, but reacts to user initiated changes to
its state, or changes from an external system). As an approach, it's got
a lot of overlap with:

Model View Controller pattern and Observer, etc,
Spreadsheet change propagation,
Database Triggers and propagation.

Basically, you just don't need to think about the complexity that's
caused by propagating changes through a program. It really is pretty
dramatically cool :-)

Cheers,
Benjohn



Dan Zwell

8/17/2007 4:45:00 PM

0

ashishwave wrote:
> i just was wondering that whether the heavy developers/users of
> reactive languages like kanaputs or reactive-C etc will ever get
> reactive features in ruby.
>
> in kanaputs, If the variable 'c' is defined as c = a + b; and if the
> reactivity of 'c' is set (c.reactive = true;), then each time the
> value of 'a' or 'b' changes then the value of 'c' is updated as the
> result of the addition
>
>
> bye :-)
> Ashish
> ashishwave@yahoo.com.
>

I haven't used reactive languages, but can't this be emulated by using
methods and instance variables?
To emulate:
c = a+b; c.reactive = true
use:
def c; @a+@b; end

Then you could pretend c was a variable. To reset the value, just
redefine c(). It would be simpler if all variables were methods, not
instance variables. If you wanted, you could write a wrapper for that,
so that set_reactive("c", "a + b") or set_reactive("c=a+b") would wrab a
call to class_eval or instance_eval that defined the method as "def c;
a() + b(); end". If you did this, however, you could never set a, b, or
c by simple assignment.

A big problem might be parsing the input. I could elaborate on some
suggestions. (I wrote code that converts standard arithmatic notation to
reverse polish notation, which is very easy to evaluate. You could also
do a simpler scheme like not allowing more than one operation.) Let me
know if you are interested. And let me know if I'm not grasping reactive
programming correctly--I've never used it.

Dan

James Gray

8/17/2007 5:17:00 PM

0

On Aug 17, 2007, at 11:44 AM, Francis Cianfrocca wrote:

> I've always been a partisan of loosely-coupled systems that use
> idempotent
> messaging. I'm still hopeful that such a thing will come to Ruby.

Are you aware of the Omnibus Concurrency Library?

http://rubyforge.org/projects/c...

> (This in fact was precisely the reason that the EventMachine
> library was developed, and it's still on the roadmap.)

To someone like me who has been looking at Erlang recently, this is
very interesting. Can you share and of your plans for how
EventMachine might evolve into this? I'm just curious.

James Edward Gray II


Robert Klemme

8/17/2007 8:11:00 PM

0

On 17.08.2007 18:44, Dan Zwell wrote:
> ashishwave wrote:
>> i just was wondering that whether the heavy developers/users of
>> reactive languages like kanaputs or reactive-C etc will ever get
>> reactive features in ruby.
>>
>> in kanaputs, If the variable 'c' is defined as c = a + b; and if the
>> reactivity of 'c' is set (c.reactive = true;), then each time the
>> value of 'a' or 'b' changes then the value of 'c' is updated as the
>> result of the addition
>>
>>
>> bye :-)
>> Ashish
>> ashishwave@yahoo.com.
>>
>
> I haven't used reactive languages, but can't this be emulated by using
> methods and instance variables?
> To emulate:
> c = a+b; c.reactive = true
> use:
> def c; @a+@b; end
>
> Then you could pretend c was a variable. To reset the value, just
> redefine c().

I guess there is one major drawback of your approach: it will break as
soon as systems grow to a reasonable size because whenever you access a
variable you have to reevaluate the complete formula. I guess any
implementation that offers reasonable performance will have to do some
kind of dependency tracking and caching of current values.

The interesting question is how could this be done in Ruby so it's
nicely integrated or a clean DSL? For seamless integration you would
have to be able to redefine (or hook into) variable access (which would
be a nice feature btw). You also would need enhanced code inspection in
order to be able to determine what other variables a variable depends on.

> It would be simpler if all variables were methods, not
> instance variables. If you wanted, you could write a wrapper for that,
> so that set_reactive("c", "a + b") or set_reactive("c=a+b") would wrab a
> call to class_eval or instance_eval that defined the method as "def c;
> a() + b(); end". If you did this, however, you could never set a, b, or
> c by simple assignment.

Yep. Interesting topic nevertheless.

Kind regards

robert

M. Edward (Ed) Borasky

8/18/2007 2:56:00 AM

0

Francis Cianfrocca wrote:
> On 8/17/07, James Edward Gray II <james@grayproductions.net> wrote:
>>
>>> (This in fact was precisely the reason that the EventMachine
>>> library was developed, and it's still on the roadmap.)
>> To someone like me who has been looking at Erlang recently, this is
>> very interesting. Can you share and of your plans for how
>> EventMachine might evolve into this? I'm just curious.
>
>
>
> Yes, I took a close look at the Erlang concurrency verbs (spawn, and the
> verbs for sending messages to Erlang "processes") and I sketched out an
> implementation of them above the standard EventMachine. I'd like to use
> Stomp for message-passing across "processes" that are in different OS-level
> processes or on different machines. When this gets done, current plans are
> to release it as EventMachine version 0.9.0.
>
> Any ideas, counterarguments, or offers to help?
>
Well, I'll certainly offer to *test* it. :)

Clifford Heath

8/18/2007 3:05:00 AM

0

benjohn@fysh.org wrote:
> I'm about to go home. Damn.
> They called it Definative Programming (think
> reactive is a much better name, as it happens).

A strongly related, but possibly even more advanced technique is called
Constraint Logic Programming, CLP. It's been around since around 1981
or earlier. Doing it with real numbers (so-called CLP/R) has a lot of
hardcore difficulties, but it's being used in high-end architectural
design packages, for example. In such tools, the formula for the size
of a beam required to span two walls and support a particular load is
dynamically recalculated as you vary the wall spacing, just to give you
an idea of why you might want such a language.

Clifford Heath.

Ezra Zygmuntowicz

8/18/2007 3:28:00 AM

0


On Aug 17, 2007, at 8:05 PM, Clifford Heath wrote:

> benjohn@fysh.org wrote:
>> I'm about to go home. Damn.
>> They called it Definative Programming (think
>> reactive is a much better name, as it happens).
>
> A strongly related, but possibly even more advanced technique is
> called
> Constraint Logic Programming, CLP. It's been around since around 1981
> or earlier. Doing it with real numbers (so-called CLP/R) has a lot of
> hardcore difficulties, but it's being used in high-end architectural
> design packages, for example. In such tools, the formula for the size
> of a beam required to span two walls and support a particular load is
> dynamically recalculated as you vary the wall spacing, just to give
> you
> an idea of why you might want such a language.
>
> Clifford Heath.
>


You will probably find this interesting: http://www.flapjax...

Cheers-
-- Ezra Zygmuntowicz
-- Founder & Ruby Hacker
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)



Simon Krahnke

8/18/2007 8:18:00 PM

0

* ashishwave <ashishwave@gmail.com> (2007-08-17) schrieb:

> in kanaputs, If the variable 'c' is defined as c = a + b; and if the
> reactivity of 'c' is set (c.reactive = true;), then each time the
> value of 'a' or 'b' changes then the value of 'c' is updated as the
> result of the addition

In a simple and slow implementation you can just put expression in a
string, and eval it everytime the value is needed.

mfg, simon .... l

Stefan Rusterholz

8/18/2007 9:58:00 PM

0

ashishwave wrote:
> ruby integrates power of functional programming from lisp , purest OO
> from smalltalk, prototype oriented power from self etc etc into one
> single language
>
> i just was wondering that whether the heavy developers/users of
> reactive languages like kanaputs or reactive-C etc will ever get
> reactive features in ruby.
>
> in kanaputs, If the variable 'c' is defined as c = a + b; and if the
> reactivity of 'c' is set (c.reactive = true;), then each time the
> value of 'a' or 'b' changes then the value of 'c' is updated as the
> result of the addition
>
>
> bye :-)
> Ashish
> ashishwave@yahoo.com.

Not the same, probably rather slow, but hey:

class Expression < BlankSlate
def initialize(&expression)
@expression = expression
end

def method_missing(*a, &b)
@expression.call.send(*a, &b)
end
end

a = 1
b = 2
c = Expression.new { a + b }
c + 3 # => 6
a = 5
c + 3 # => 10

Have fun ;-)

Regards
Stefan
--
Posted via http://www.ruby-....