static:
type range = array[1 .. 100, bool]
var doors: range;
for i in doors.low() .. doors.high():
doors[i] = false
proc toggle(b: var bool) {.inline.} = b = if b: false else: true
for i in doors.low() .. doors.high():
for j in countup(i, 100, i):
doors[j].toggle()
for i, door in doors:
echo i, " is", (if door: "open" else: "closed"), "."
The line above complains:
... Error: execution of an external compiler program 'gcc -c -w -I/home/user0/.choosenim/toolchains/nim-0.18.0/lib -o /home/user0/devel/atom/nim/app/
src/nimcache/app_hundreddoors.o /home/user0/devel/atom/nim/app/src/nimcache/app_hundreddoors.c' failed with exit code: 1
... /home/user0/devel/atom/nim/app/src/nimcache/app_hundreddoors.c: In function ‘app_hundreddoorsInit000’:
... /home/user0/devel/atom/nim/app/src/nimcache/app_hundreddoors.c:115:38: error: ‘doors_w1Wm3phlUyGhRDq4wvpsuQ’ undeclared (first use in this function
)
... door_gIfeUZM6XK9aj8VoS9asjlLA = doors_w1Wm3phlUyGhRDq4wvpsuQ[(i)- 1];
... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
... /home/user0/devel/atom/nim/app/src/nimcache/app_hundreddoors.c:115:38: note: each undeclared identifier is reported only once for each function it
appears in
Is is this a compiler issue?
Like this:
const doors = block:
type range = array[1 .. 100, bool]
var doors: range
for i in doors.low() .. doors.high():
doors[i] = false
proc toggle(b: var bool) {.inline.} = b = not b #if b: false else: true
for i in doors.low() .. doors.high():
for j in countup(i, 100, i):
doors[j].toggle()
doors
for i, door in doors:
echo i, " is ", (if door: "open" else: "closed"), "."
Unrelated, but you don't need to inline the toggle proc since it's running in the nim VM and doesn't need much premature optimization. Also that type alias can be fairly confusing since range is already a type in Nim