Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-15 Thread dawkot
If you don't want to allocate a seq (like you do when you invoke pairs), you can use enumerate from [https://nim-lang.org/docs/manual.html#macros-for-loop-macro](https://nim-lang.org/docs/manual.html#macros-for-loop-macro)

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread freeflow
Aha: success for myKey, myValue in readFile(day02PathAndName).split(',').pairs(): result[myKey.int64]=myValue.parseInt Run

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread freeflow
It might be more productive if I advise you that I spent several days perusing the nim documentation before I admitted defeat and asked a question here. @Solitude's comments highlighted something that is not adequately referenced when you read the for loop section of the manual.

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread freeflow
I'll have to wait until my knowledge of nim improves before I can that. In the meantime I'm using let mySeq:seq[string]=readFile(day02PathAndName).split(',') for myKey, myValue in mySeq: result[myKey.int64]=myValue.parseint.int64 Run

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread Araq
Seems to be a use-case for Nim's csv parser, [https://nim-lang.org/docs/parsecsv.html](https://nim-lang.org/docs/parsecsv.html)

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread sky_khan
Sorry for being lazy earlier and for my poor English. What I meant was this: import strutils var file = """ Hello,World Key,Value """ for line in file.split("\n"): # iterator returns string var data = line.split(",") # proc returns s

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread SolitudeSF
invoke items/pairs iterator explicitly

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread freeflow
On further reading it seems there is a split proc and a split iterator. The former returns a sequence of substrings. The code I have seems to be using the iterator version. How would I indicate to nim to use the proc rather than the iterator version of split?

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-13 Thread SolitudeSF
there is no split iterator that returns two values at a time. you're confusing it with sequence and implicit pairs. you have to keep track of the indexes on your own here.

Re: Newbie question: Why am I getting the too many variables error on my loop index variable?

2020-01-12 Thread sky_khan
if that "split(',')" is from strutils, it returns seq[string], not tuple. I guess you need to use something like this: for line in readFile(day02PathAndName): var data = line.split(',') if data.len() == 2: myKey = data[0] myValue = data[1] result.