Because the "p" in
Because it reduces to the following, and the attempt to concatenate a Boolean value will trigger an error:
false .. 123
One (the first one). More than one branch of an
if is never executed. The first branch when a true test expression is executed, and after that, the
if is exited.
for N = 10, 2, −2 do print(N) end
function TypedToString(Val) return type(Val) .. ": " .. tostring(Val) end
function SumProd(A, B) return A + B, A * B end
It will print the following:
6 10 25
SumProd(3, 3) returns
6, 9, which is adjusted to one value.
SumProd(5, 5) returns
10, 25, and both values are used.
North America. (The
F is local—assigning to it has no effect on the global
For the functions returned to be closures (and thus have private state),
Dots needs to be local. Because it's global, all the functions returned share the same state, so they all do the same thing. The fix is simply this:
function MakeDotter(N) local Dots = "" for I = 1, N do Dots = Dots .. "." end return function(Str) return Str .. Dots end end
As mentioned earlier, forgetting to make a variable local is a common source of bugs.
To figure this sort of thing out, work from left to right: figure ...