I was cleaning up my chess game, which includes replacing var default values by consts generated at compile time.
For the code below output of echo is zero for all values, while I expected low(int16). What may be wrong?
const
MaxDepth = 15
const
InvalidScore = low(int16)
type
Guide = tuple
v: int16
si:int8
di:int8
HashLine = array[-MaxDepth..MaxDepth, Guide]
HashResult = tuple
age: int # set to zero for last access, increase for each played move
score: HashLine # exact values
floor: HashLine # lower bounds
proc genHashResultAllZeroConst: HashLine =
for i in mitems(result): i.v = InvalidScore
const
HashResultAllZero = genHashResultAllZeroConst()
proc initHR(hr: var HashResult) =
hr.age = 0
hr.score = HashResultAllZero
hr.floor = HashResultAllZero
for i in -15..15:
echo hr.score[i].v
echo hr.floor[i].v
var hr: HashResult
initHr(hr)
I guess it is a compiler bug.
proc genHashResultAllZeroConst: HashLine =
for i in mitems(result):
i.v = InvalidScore
echo i.v
echo result.repr
const
HashResultAllZero = genHashResultAllZeroConst()
does show low(int16) on the echo in the loop but the echo afterwards shows an empty array. This behavior changes if HashResultAllZero is changed from const to let. So mitems() does not seem to really work here.
I guess it is a compiler bug. ... So mitems() does not seem to really work here.
I think so too. The following seems to work OK:
proc genHashResultAllZeroConst: HashLine =
for ix in result.low .. result.high:
result[ix].v = InvalidScore
Thanks.
Should I add that example to Nim's github issue tracker?