Advertisement

programming language idea

Started by July 02, 2010 03:48 AM
13 comments, last by RivieraKid 14 years, 4 months ago
It seems that you just want a function. If you want something that looks like less of a function call, feel free to wrap it up in class:

class Program {    class ReactiveVariable<T> {        Func<T> function;        public ReactiveVariable(Func<T> function) {            this.function = function;        }        public static implicit operator T(ReactiveVariable<T> rv){            return rv.function();        }        public override string ToString() {            return this.function().ToString();        }    }    static void Main(string[] args) {        var x = 5;        var y = 10;        var z = new ReactiveVariable<int>(() => x * y);                    Console.WriteLine(z); // z == 50                    x = 2;        Console.WriteLine(z); // z == 20                    y = 5;        Console.WriteLine(z); // z == 10        // Implicit conversions work too.        int i = z;        Console.WriteLine(i);                }}

Edit: Once converted to a regular int you do of course lose the magic of the function call, so I'd be tempted to stick with the function call or at least make the conversion operator explicit.

[Edited by - benryves on July 2, 2010 9:52:24 AM]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

I am aware of the WPF and Silverlight binding syntax (i am a SL developer) but they are just classes which wrap up events.

Xaml just binds to the PropertyChanged event and uses reflection to Get the properties. Its an ugly hack. Dependency properties are there to support xaml.

JavaFX is what I was looking for. Thank you.

benryves, in your example z only re-evaluates when you invoke it explicitly.
Advertisement
There is a language called Eden which works in a similar way.

http://www2.warwick.ac.uk/fac/sci/dcs/research/em/software/eden/

It does, in fact, work in the way you describe -- like cells in a database. The software is available for download and will apparently compile on Linux.
If the variable gets re-evaluated long before I use it, why should I care?

Also, what happens if I do:

var x = 5
rvar y(x) = x++

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

it could be a function (like an event handler) or it could be onscreen.

stack overflow exception

This topic is closed to new replies.

Advertisement