Hi,
in the documentation for Nim 2.0.4. I found unicode operators mentioned but there was the explanation of only one. Using the search bar to the left found nothing. What keyword beside "unicode operator" will lead me to the answer ? :)
Another question: Supporse I want to parse a csv file into an array for further exploration and processing. In the manual I read that the size of an array needs to be known at compile time. But compiling a new version of my program for each different csv file is a little.....overwhelming. ;)
Are there other "entities" called differently than "array" in Nim, which can be sized dynmically at runtime. How are they named (so I can search for these...) ?
Sequences are dynamically sized arrays (https://narimiran.github.io/nim-basics/#_sequences, https://nim-lang.org/docs/system.html#system-module-seqs).
I recommend you checking out a tutorial (like the one linked) to learn about fundamental Nim data types like sequences.
Unicode operators can be found in the manual here: https://nim-lang.org/docs/manual.html#lexical-analysis-unicode-operators
Hi doofenstein,
AH! "Sequences" is the magic word! THANKS! :)
The linked portion about Unicode operators was the one, which lead to my question, since I didn't found an explanation, (for example) "★" does or whethere "⊞" is optimized of integer arithmetic?
To expand upon the unicode operator thing:
It's a "do-it-yourself" kind of deal. You get to define the meaning of these operators, and they syntactically work like the pre-defined +, -, etc.
e.g.
func `∪`[T](a, b: set[T]): set[T] =
return a + b
func `∪=`[T](a: var set[T]; b: set[T]) =
a = a + b
echo {'a', 'b'} ∪ {'c', 'd'}
var x = {'e', 'f'}
x ∪= {'g', 'h'}
echo x
This will define a union operator with the symbol ∪, and also a shortcut for a = a ∪ b as a ∪= b. (Of course, you could also define it to do whatever else, but that sounds evil :P)
In contrast, the above syntax does not work with a regular function name:
func union[T](a, b: set[T]): set[T] =
return a + b
func `union=`[T](a: var set[T]; b: set[T]) =
a = a + b
# echo {'a', 'b'} union {'c', 'd'} # won't compile
echo {'a', 'b'}.union {'c', 'd'} # you'd have to do this instead.
var x = {'e', 'f'}
# x union= {'g', 'h'} # this doesn't work either
x.union = {'g', 'h'} # this does, but is very confusing in this context...
echo x
(Of course, the above dance is entirely redundant for sets, you can just use + to the same effect.)
So in short, nothing that you can't do without unicode; if you find the unicode version clearer, or feel compelled to turn Nim into APL, then Nim gives you the tools you need.
(In fact, I have never felt the need to use unicode operators. I'm also convinced that anything other than ASCII does not belong in program source code, but I know many people disagree.)