The key is that before the expression matches the pattern, one Unevaluated layer is Unevaluated . From docs :
f[Unevaluated[expr]] works effectively by temporarily setting attributes that f does not argue its argument, then evaluating f[expr] .
Thus, in the first case, f[Unevaluated[1 + 1]] is evaluated as f[1 + 1] , but remains unappreciated during pattern matching, even if f has no Hold* attributes, and since nothing matches f[1 + 1] , the original expression (pre -pattern-matching) is returned not evaluated.
In the second case, f[Unevaluated[Unevaluated[1 + 1]]] is evaluated as f[Unevaluated[1 + 1]] in the matching pattern that matches the pattern for f , and then f[1 + 1] is evaluated recursively, and so this way you get f[2] .
In the third case, f[Unevaluated[Unevaluated[Unevaluated[1 + 1]]]] evaluates to f[Unevaluated[Unevaluated[Unevaluated[1 + 1]]]] , matches and recursively evaluates to f[Unevaluated[1 + 1]] and we will return to the first case.
In the fourth case, f[Unevaluated[Unevaluated[Unevaluated[Unevaluated[1 + 1]]]]] coincides with f[Unevaluated[Unevaluated[Unevaluated[1 + 1]]]] , recursively evaluates f[Unevaluated[Unevaluated[1 + 1]]] , and we return to the second case.
NTN!
source share