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