Re: Nim syntax Quiz

2018-03-21 Thread Allin
Some musings; Beware, I edited title and original post to better reflect the point of the thread. \-- When I first installed Nim 0.13, I accepted that there will be "wtf-moments" because I knew that it is work-in-progress. When press release of 1.0 will eventually hit the fan, I surely hope

Re: Nim syntax Quiz

2018-03-21 Thread lightness1024
Hey I have another good one in the category "ignore the compiler and just go back to the code". import db_mysql, tables type XchgSym = tuple[xchg: string, sym: string] var xchg_symbol2id = initTable[XchgSym, int]() # real code: #let id =

Re: Nim syntax Quiz

2018-03-21 Thread Araq
Unfair quoting IMO, I said > Or better yet, you ask a beginner who can read a tutorial again to look at > some valid syntax. **I 'm not a fan of pathos.** A friendlier tone would have produced a friendlier answer. But I'm changing this to "just always be nice anyway", trying to listen to

Re: Nim syntax Quiz

2018-03-21 Thread lightness1024
I'm also a beginner and I'm also exasperated by error messages just like you. Let's take C#, it's a language that was designed on purpose to be beginner friendly, and the compiler outputs messages that are incredible and spot on. This makes it frustration-free, and that's one key to adoption.

Re: how to read/write object from/to binary file?

2018-03-21 Thread cblake
While doofenstein makes some good points especially about fragility with regard to adding new fields and old data files, there is some real efficiency charm to a "just memory map and go" pure binary native data approach. It's not always fun to be parsing data files again and again. So, I would

Re: how to read/write object from/to binary file?

2018-03-21 Thread doofenstein
Because it's very dangerous. Simply having a compiler which puts structures in another layout or adding a field to the object is enough to render all your previously generated files useless. If you just want to save and load data, I would rather serialise

Re: OrderedTable is not an ordered table

2018-03-21 Thread cblake
Thanks for the compliments. You should probably learn about backward shift deletion. It's a little tricky the first time you see it, but ultimately it's better than tombstones and a bunch of ad hoc garbage collection rules. You can look at `lib/pure/collections/tables.nim`. There are really

Re: How to (de)serialize inherited object?

2018-03-21 Thread c0ntribut0r
Probably there's no easy solution of this task [Same for c++ on Stack Overflow](https://stackoverflow.com/questions/3268801/how-do-you-de-serialize-a-derived-class-from-serialized-data) [Comprehensive guide](https://isocpp.org/wiki/faq/serialization#serialize-inherit-no-ptrs)

Re: how to read/write object from/to binary file?

2018-03-21 Thread luntik2012
Thank you, it works. It strange that there is no possibility to make some cast from string of seq[byte] directly to object

Re: How to (de)serialize inherited object?

2018-03-21 Thread c0ntribut0r
It would be too easy! import streams, nesm serializable: type TA = object of RootObj TB = object of TA f: int var a: ref TA b: ref TB new(b) a = b echo stringify(serialize(a))

Re: OrderedTable is not an ordered table

2018-03-21 Thread lightness1024
@cblake omg such a concentration of goodness in this answer, thank you for the tombstone warning. If I understand what you mean, I gave it some thought at the time, and concluded it would be an idea to "garbage collect" if some metric goes red, which is the solution google dense map appears to

Re: How to (de)serialize inherited object?

2018-03-21 Thread mashingan
Try [nesm](https://github.com/xomachine/NESM)

Re: how to read/write object from/to binary file?

2018-03-21 Thread c0ntribut0r
Have a look at this: import streams type MyType* = object somefield*: array[10, int16] var t1, t2: MyType t1.somefield[0] = 1 t2.somefield[0] = 2 var f = newFileStream("/tmp/tmp.mytype", fmWrite) if not f.isNil: f.write t1

Is there any way to create template with await?

2018-03-21 Thread slangmgh
We can create template with like this: template withFile(name: string, body: untyped) = let fh = open(name, ...) defer: close(fh) block: body But when template contain await, the compiler will complain the 'await' is undeclared identifier. The

Re: how to read/write object from/to binary file?

2018-03-21 Thread luntik2012
Sorry, it works correctly. But how to read it back? File contains several instances of MyType, so I need to take subpart of file. I've tried this let data = readFile("/tmp/tmp.mytype") let ololo = cast[MyType](data[0 ..

How to (de)serialize inherited object?

2018-03-21 Thread c0ntribut0r
Hello guys, Is there any way to serialize object including its runtime type data? Both [marshal](https://nim-lang.org/docs/marshal.html) and [msgpack4nim](https://github.com/jangko/msgpack4nim#ref-types) don't support it out-of-box. import streams, msgpack4nim type

Re: how to read/write object from/to binary file?

2018-03-21 Thread luntik2012
I do t.somefield[0] = 255 t.somefield[1] = 255 to check

how to read/write object from/to binary file?

2018-03-21 Thread luntik2012
I can do something like this: type MyType* = object somefield*: array[10, int16] var t: MyType var f = newFileStream("/tmp/tmp.mytype", fmWrite) if not fff.isNil: f.write t but result file contains garbage, size of file is 20 bytes. So question

Re: OrderedTable is not an ordered table

2018-03-21 Thread cblake
@lightness1024 - fair criticism of C++ STL. modulo prime reduction of the hash code to a table address/array index is slow because division is slow. In my tests using modulo can sometimes **triple** the entire lookup time for simple integer keys due to the slowness of division! I recommend you

How to call a macro from a template with a constructed identifier argument?

2018-03-21 Thread rpowers
I have a macro that creates a type and associated functions, and I'm calling that from a template. I want to use identifier construction to append a suffix to the template parameter, but the whole backticked AST (instead of the constructed identifier) gets passed in to the macro. Is there some

Re: OrderedTable is not an ordered table

2018-03-21 Thread lightness1024
@cblake - ok perfect. also naming things search-aware is important so I concur. The python's OrderedDict: I didn't know that, it's a good thing nim is not alone then. And in fact the presence of this is enough to not go and rename it. (less disturbance) In C++ the set/map is usually

Re: OrderedTable is not an ordered table

2018-03-21 Thread cblake
@lightness1024 - good point. Another argument in favor of "KeyOrderedTable" would be that it would probably show up in searches of the more generic "OrderedTable". I don't think Nim has a key-ordered collection (EDIT - in the stdlib) right now, but Araq has said he has a B-Tree waiting in the

Re: OrderedTable is not an ordered table

2018-03-21 Thread lightness1024
Hey that makes sense though. Maybe adding a SortedTable will be enough to solve this confusion. The mere presence of an OrderedTable and a SortedTable will pick reader's curiosity and will naturally force us to look into why there are two concepts that sounds similar.

Re: How to cross-compile a Nim executable for Android

2018-03-21 Thread mashingan
you forgot to link libm, add option `-lm` at very end.

Re: How to cross-compile a Nim executable for Android

2018-03-21 Thread alexsad
Hi finelly is works! I tried the way suggested Tetralux via make_standalone_toolchain.py and then clang. Simple echo works, but I tried simple pow from math and clang doesn't compile it: import math var a = pow(5.09, 2.33) clang -I

Re: OrderedTable is not an ordered table

2018-03-21 Thread Araq
An OrderedTable is an ordered table. But it is not a _sorted_ table. IMO, but I 'm not a native speaker.

OrderedTable is not an ordered table

2018-03-21 Thread lightness1024
I just read in the module tables: > OrderedTable is like Table but remembers insertion order Well.. lol, thank you very much but that's not what we expect. This is a "sequentially stable table", I suggest a rename to "SeqTable" maybe. In C++ a set or a map are ordered tables. In C# there are

Re: Wrong copy of sequences?

2018-03-21 Thread mratsim
You are not alone. Though in my case I wanted to remove copies when safe and it seemed like seq wrapped in objects always triggered copies. Anyway, relevant issues: * Return by let/const values [#6793](https://github.com/nim-lang/Nim/issues/6793) * Distinguish let/var in assignment