- In CBV, we need to evaluate loop which does not terminate so this does not terminate
- In CBN, we only need the first argument which it will readily return
Scala normally uses Call-By-Value because it is usually exponentially faster to compute. However, you can make a function use CBN by adding a => such as: {def constOne(x: Int, y: => Int) = 1}
If we call const(1+2, loop) we get const(3,loop) which evaluates to 1 since the parameter loop is CBN. On the other hand, if we call const(loop, 1+2), we will get an infinite cycle!
No comments:
Post a Comment