Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
JsAssoc can accept various K types for a key, which is something that I happily used.
However this usually leads to subtle bugs: JS converts all keys to strings, so
1 conversion to string might be not always unique for some types(e.g. objects)
2 when you iterate, the key is actually a cstring, which means the Nim type system leads you to a probable error in this case
e.g. if you have int, int
var b = JsAssoc[int, cstring]{4: cstring"e"}
for a, _ in b:
# a
a can easily seem like an int, but it's a cstring, a lot of operations on it will work in the same way even if it's cstring, but sooner or later this leads to a weird bug
Basically we need to limit K to types that are easily <=> with cstring, like int and make special pairs for those types, so we automatically insert a conversion to K. (the V value type should remain the same)
JsAssoc can accept various K types for a key, which is something that I happily used. However this usually leads to subtle bugs: JS converts all keys to strings, so
1 conversion to string might be not always unique for some types(e.g. objects) 2 when you iterate, the key is actually a cstring, which means the Nim type system leads you to a probable error in this case
e.g. if you have int, int
a can easily seem like an int, but it's a cstring, a lot of operations on it will work in the same way even if it's cstring, but sooner or later this leads to a weird bug
Basically we need to limit K to types that are easily
<=>
with cstring, like int and make specialpairs
for those types, so we automatically insert a conversion toK
. (theV
value type should remain the same)Thoughts? Should I make a PR?