EnTerr
11 years agoRoku Guru
Puzzle: Invalid value for left-side of expression
I just shot myself in the foot in a rather fascinating way, I thought i'll share it as a puzzle.
I was sketching a stack object constructor as an example (don't ask why, that's besides the point):
And then i tested it:
I kept reading and reading, and re-reading #6 ` push: function(x): m.stk[m.ptr] = x: m.ptr = m.ptr + 1: end function,` and i could not see anything to justify the error. Took me a long while to find the cause.
Can you see the reason?
I was sketching a stack object constructor as an example (don't ask why, that's besides the point):
function Stack(n):
dim stack[n]
return {
stk: stack,
ptr: 0,
push: function(x): m.stk[m.ptr] = x: m.ptr = m.ptr + 1: end function,
pull: function(): m.ptr = m.ptr - 1: return m.stk[m.ptr]: end function
}
end function
And then i tested it:
BrightScript Debugger> s = Stack(100)Whaaat?
BrightScript Debugger> s.push(42)
Invalid value for left-side of expression. (runtime error &he4) in pkg:/source/main.brs(6)
I kept reading and reading, and re-reading #6 ` push: function(x): m.stk[m.ptr] = x: m.ptr = m.ptr + 1: end function,` and i could not see anything to justify the error. Took me a long while to find the cause.
Can you see the reason?