From: Dan Zwell Date: 2007-08-18T01:44:31+09:00 Subject: Re: wishing of reactive programming in ruby 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