Hey all,
I very new to Nim and was writing a tiny command line todo application to get my bearings. Here's a link to a code snippet When I run this code, I get this error and I'm not sure how to circumvent it:
Traceback (most recent call last)
todo.nim(17) todo
todo.nim(11) formatTodos
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Any help would be much appreciated, thanks!You can't add to a Nil. Firstly initialize it.
proc formatTodos(list: TodoList): string =
result = ""
for todo in list.items():
result.add("Todo: " & todo.desc)
result.add("\n")
(insert Viccini saying: "you fell for one of the classic blunders ....") ;-)
There was talk of making "seq" and other "array like" variables to auto initialise to stop this happening.
Not sure if that will make Nim 1.0 or if it will happen at all (or maybe the default "not nil" will be the solution)
I use "not nil" wherever I can, too, but it's kind of a losing battle, since all the other code wants nillable types, so you have to add a lot of converters/checking code/etc, which kinda defeats the purpose :-)