Why does the Lua interactive interpreter stop letting me type things in? -
i writing program find standard deviation of data set. don't have proper lua editor testing interactive interpreter.
in code below, seems work until diffsqrd function. after call function, interpreter stops letting me type in. have close , start on again. have tested function itself, without code before , works fine.
i tried saving whole thing .lua file , running dofile did same thing. nothing, , can no longer type interpreter. going on?
--a function see if file exists function file_exists(file) local f=io.open(file, "r") if f f:close() end return f ~= nil end --get lines file, returns empty --list/table if file not exist function lines_from(file) if not file_exists(file) return {} end lines = {} line in io.lines(file) lines[#lines + 1] = line end return lines end --put .rec file array y_positions=lines_from([[z:\octupole stuff\programming\y_p_test.rec]]) --functions find standard deviation of array. --total, average, difference squared. stop here because --minimum code required cause problem. function total(a) local sum=0 i,v in ipairs(a) sum = sum + v end return sum end function average(a) if #a==0 mean=0 else mean=total(a)/#a end return mean end function diffsqrd(a) local diff={} in ipairs(a) diff[i]=(a[i]-average(a))^2 end return diff end --use diffsqrd function on .rec file. yd=diffsqrd(y_positions) print(yd[1])
Comments
Post a Comment