Truly declarative language?

后端 未结 19 2174
梦毁少年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:01

    You might find this video (from the Commercial Users of Functional Programming website) interesting and worthwhile viewing. If you've got pretty technophobic users this may be a good approach for you.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-04 02:02

    react is an OCaml frp library. Contrary to naive emulations with closures it will recalculate values only when needed

            Objective Caml version 3.11.2
    
    # #use "topfind";;
    # #require "react";;
    # open React;;
    # let (x,setx) = S.create 10;;
    val x : int React.signal = <abstr>
    val setx : int -> unit = <fun>
    # let (y,sety) = S.create 20;;
    val y : int React.signal = <abstr>
    val sety : int -> unit = <fun>
    # let z = S.Int.(+) x y;;
    val z : int React.signal = <abstr>
    # S.value z;;
    - : int = 30
    # setx 50;;
    - : unit = ()
    # S.value z;;
    - : int = 70
    
    0 讨论(0)
  • 2021-02-04 02:06

    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, ...

    0 讨论(0)
  • 2021-02-04 02:07

    In F#, a little verbosily:

    let x = ref 10
    let y = ref 20
    
    let z () = !x + !y
    
    z();;
    y <- 40
    z();;
    
    0 讨论(0)
  • 2021-02-04 02:07

    You can mimic it in Ruby:

    x = 10
    y = 20
    z = lambda { x + y }
    z.call    # => 30
    z = 50
    z.call    # => 70
    

    Not quite the same as what you want, but pretty close.

    0 讨论(0)
提交回复
热议问题