Truly declarative language?

Posted by gjvdkamp on Stack Overflow See other posts from Stack Overflow or by gjvdkamp
Published on 2010-06-07T15:26:10Z Indexed on 2010/06/07 15:32 UTC
Read the original article Hit count: 265

Hi all,

Does anyone know of a truly declarative language? The behaviour I'm looking for is kind of what Excel does, where I can define variables and formulas, and have the formula's result change when the input changes (without having set the answer again myself)

The behaviour I'm looking for is best shown with this pseudo code:

X = 10     // define and assign two variables
Y = 20;

Z = X + Y  // declare a formula that uses these two variables

X = 50     // change one of the input variables

?Z         // asking for Z should now give 70 (50 + 20)

I've tried this in a lot of languages like F#, python, matlab etc, but every time i try this they come up with 30 instead of 70. Wich is correct from an imperative point of view, but i'm looking for a more declerative behaviour if you know what i mean.

And this is just a very simple calculation. When things get more difficult it should handle stuff like recursion and memoization automagically.

The code below would obviously work in C# but it's just so much code for the job, i'm looking for something a bit more to the point without all that 'technical noise'

class BlaBla{
    public int X {get;set;}  // this used to be even worse before 3.0
    public int Y {get;set;}
    public int Z {get{return X + Y;}}
}

static void main(){
   BlaBla bla = new BlaBla();
   bla.X = 10;
   bla.Y = 20;
   // can't define anything here
   bla.X = 50; // bit pointless here but I'll do it anyway. 
   Console.Writeline(bla.Z);// 70, hurray!
}

This just seems like so much code, curly braces and semicolons that add nothing.

Is there a language/ application (apart from Exel) that does this? Maybe I'm no doing it right in the mentioned langauges, or I've completely missed an app that does just this.

I prototyped a language/ application that does this (along with some other stuff) and am thinking of productizing it. I just can't believe it's not there yet. Don't want to waste my time.

Thanks in advance,

Gert-Jan

© Stack Overflow or respective owner

Related posts about programming-languages

Related posts about functional-programming