What is a 'thunk'?

后端 未结 10 923
日久生厌
日久生厌 2020-11-28 01:42

I\'ve seen it used in programming (specifically in the C++ domain) and have no idea what it is. Presumably it is a design pattern, but I could be wrong. Can anyone give a go

10条回答
  •  猫巷女王i
    2020-11-28 02:16

    This question has already been asked on SO, see:

    What is a 'thunk', as used in Scheme or in general?

    From what I can tell, it's akin to a lambda statement, where you may not want to return the value until you need to evaluate it; or it can also be compared to a property getter which by design executes some code in order to return a value while yet having the interface form that comes across more like a variable, but also has polymorphic behavior that can be swapped out whether by inheritance or by swapping out the function pointer that would evaluate and return a value at runtime based on compile-time or environmental characteristics.

提交回复
热议问题