Truly declarative language?

后端 未结 19 2617
梦毁少年i
梦毁少年i 2021-02-04 01:26

Does anyone know of a truly declarative language? The behavior I\'m looking for is kind of what Excel does, where I can define variables and formulas, and have the formula\'s re

19条回答
  •  天命终不由人
    2021-02-04 02:02

    In Mathematica, you can do this:

    x = 10;     (* # assign 30 to the variable x *)
    y = 20;     (* # assign 20 to the variable y *)
    z := x + y; (* # assign the expression x+y to the variable z *)
    Print[z];
    (* # prints 30 *)
    x = 50;
    Print[z];
    (* # prints 70 *)
    

    The operator := (SetDelayed) is different from = (Set). The former binds an unevaluated expression to a variable, the latter binds an evaluated expression.

提交回复
热议问题