真正的声明性语言? [英] Truly declarative language?

查看:127
本文介绍了真正的声明性语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道一个真正的声明性语言吗?我正在寻找的行为与Excel所做的一样,我可以在其中定义变量和公式,并在输入更改时让公式的结果发生变化(无需再次自行设置答案)。

我正在寻找的行为最好用这个伪代码显示:

  X = 10 //定义和分配两个变量
Y = 20;

Z = X + Y //声明一个使用这两个变量的公式

X = 50 //改变一个输入变量

?Z //要求Z应该给70(50 + 20)

我试过了在很多语言如F#,python,matlab等中,但每次我尝试这个时,他们都会拿出30而不是70.从命令的角度来看,这是正确的,但如果你想要更多的行为明白我的意思了吗。

这只是一个非常简单的计算。当事情变得更加困难时,它应该自动处理像递归和memoization之类的东西。



下面的代码显然适用于C#,但它只是这么多的代码, m寻找更多的东西,没有任何'技术噪音'点

  class BlaBla {
public int X {get; set;} //在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;
//不能在这里定义任何内容
bla.X = 50; //这里有点没有意义,但我会尽力去做。
Console.Writeline(bla.Z); // 70,万岁!
}

这看起来好像很多代码,大括号和分号不加任何东西。

是否有语言/应用程序(Exel除外)能够做到这一点?也许我在所提到的语言中没有做到正确,或者我完全错过了这样做的应用程序。



我创建了一个语言/应用程序原型(以及其他一些东西),并正在考虑对其进行产品化。我简直不敢相信它还没有。不要浪费时间。

约束编程系统将为你做到这一点。
具有相关语言的CP系统示例包括
ECLiPSe ,SICSTUS Prolog / CP软件包,彗星,MiniZinc,...

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.

解决方案

Any Constraint Programming system will do that for you. Examples of CP systems that have an associated language are ECLiPSe, SICSTUS Prolog / CP package, Comet, MiniZinc, ...

这篇关于真正的声明性语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆