Shadowing occurs when one binding takes precedence over another, making the former binding invisible. Shadowing puts a hole in the scope of a binding.
f([]) = [] f(h::t) = (h*h)::f(t) when h > 10 f(h::t) = f(t) when h <= 10show an inside-out evaluation of expression f([4,12,15,6,11]). Assume that arithmetic is done as soon as possible.
f([4,12,15,6,11]) = f([12,15,6,11]) (since 4 <= 10) = 144::f([15,6,11]) (since 12 > 10 and 12*12=144) = 144::225::f([6,11]) (since 15 > 10 and 15*15=225) = 144::225::f([11]) (since 6 <= 10) = 144::225::121::f([]) (since 11 > 10 and 11*11=121) = 144::225::121::[] = 144::225::[121] = 144::[225,121] = [144,225,121]Remarks. Be sure to follow the rules exactly. Do not forget about the [] at the end.
Definition 1: does not use min.
smallest(n,[]) = n smallest(n,h::t) = smallest(n,t) when n <= h smallest(n,h::t) = smallest(h,t) when n > h
Definition 2: uses min.
smallest(n,[]) = n smallest(n,h::t) = smallest(min(n,h),t)
Two evaluations of the same expression in the same context must always yield the same value. This is because there are no variables that can be changed.