Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
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?
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?
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?
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?
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?
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 seq[string] # but there is no version of split you can use as "for myKey, myValue in" if data.len() == 2: echo data[0]," = ", data[1] Run
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
invoke items/pairs iterator explicitly
Re: Newbie question: Why am I getting the too many variables error on my loop index variable?
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?
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?
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... else: echo "Error in input: ", line Run
Newbie question: Why am I getting the too many variables error on my loop index variable?
I'm currently having a bash at using nim by converting my efforts for Advent of Code from VBA to nim. Unfortunately I've got stuck when trying to iterate over the input from a file and push that input into an OrderedTable. proc GetDay02Program(): OrderedTable[int64,int64] = for myKey, myValue in readFile(day02PathAndName).split(','): result[myKey.int64]=myValue.parseint.int64 Run ''' In the code above the myKey variable is flagged and the error message is 'wrong number of variables'. I'm a bit perplexed as the reading I've done indicates that my for statement is as expected. I'd appreciate being enlighteded as to why iI'm getting the error.