3 ms·
Ive found that Nim has an interesting way of doing string handling, as if it is some kind of Polish notational aspect. Take part of a CSV parser, for example:
by egberts1 4y ago
Ive found that Nim has an interesting way of doing string handling, as if it is some kind of Polish notational aspect.
Take part of a CSV parser, for example:
if @[ ‘,’ ].split(my_string)
- Tiberium 4y agoI think you just found someone's bad code, because first of all, an efficient CSV parser would not use `split` with `if` because then the program will have to split the whole string and store all split'd string in a sequence temporarily, but second of all, Nim has method call syntax (so-called UFCS in some other languages) - https://nim-lang.org/docs/manual.html#procedures-method-call-syntax https://nim-lang.org/docs/manual.html#procedures-method-call..., so the code you wrote can just be if my_string.split(@[',']) or even (because we only split by 1 char, we don't need a sequence): if my_string.split(',') That said, you didn't paste the whole string of code as this expression is non-sensical - Nim doesn't have the same "truthiness" as Python, so if you wanted to check if there's at least two strings as a result of a split, you'd write it as if my_string.split(',').len > 1: # do stuff