Truly declarative language?

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

    This F# code should do the trick. You can use lazy evaluation (System.Lazy object) to ensure your expression will be evaluated when actually needed, not sooner.

    let mutable x = 10;
    let y = 20;
    
    let z = lazy (x + y);
    x <- 30;
    
    printf "%d" z.Value
    

提交回复
热议问题