When to use call-by-name and call-by-value?

后端 未结 5 1828
悲哀的现实
悲哀的现实 2021-02-03 13:15

I understand the basic concept of call-by-name and call-by-value, and I have also looked into handful number of examples. However, I am not very clear about when to use call-by-

5条回答
  •  盖世英雄少女心
    2021-02-03 13:50

    When a call-by-name parameter is used more than once in a function, the parameter is evaluated more than once.

    As the parameter being passed in should be a pure function call per Functional Programming, each evaluation within the called function will always generate the same result. Therefore, call-by-name would be more wasteful than the conventional call-by-value.

提交回复
热议问题