Best way to store/search/etc and an int-int data structure
I have a list of int-int, which I'm storing as a _seq_ of _(int,int)_ tuples (the first int being a hash value, so it's not like 0-1-2-3...) I have to test this structure for membership (whether an index - the first _int_ \- exists), look up a value (get the second _int_ for a specific first _int_ ), update a value, etc. Pretty much like a dictionary / hash table. Right now, this is how I'm doing it: proc getValueForKey(ctx: Context, hs: int): Value {.inline.} = var j = 0 while j
Different code produced when using a template?
OK, so, I'm a bit confused. I have this template: template initTopContextWith(pairs:seq[(int,Value)]) = shallowCopy(Stack[^1],pairs) Run which I'm calling/using from another _proc_. When I use the template, the produced code is: //shallowCopy(Stack[^1],pairs) //shallowCopy(Stack[^1],pairs) T22_ = (tySequence__27px9cXpFaJ4yUn1cSZAKaw**)0; T22_ = X5BX5D___q5FAoaedQCwl53m2ytrbgQsystem(Stack__WH1ut3OkOocLDQJpFMZt3w->data, (Stack__WH1ut3OkOocLDQJpFMZt3w ? Stack__WH1ut3OkOocLDQJpFMZt3w->Sup.len : 0), ((NI) 1)); //initTopContextWith(args) unsureAsgnRef((void**) (&(*T22_)), args); Run But when I directly include this one line of code in the calling proc, this is what I'm getting: //shallowCopy(Stack[^1],args) X5BX5Deq___sGWc2llByIT4Ipi0sFgxegsystem(Stack__WH1ut3OkOocLDQJpFMZt3w->data, (Stack__WH1ut3OkOocLDQJpFMZt3w ? Stack__WH1ut3OkOocLDQJpFMZt3w->Sup.len : 0), ((NI) 1), args); Run What is even move weird is that - in the second case - whatever this change in the code means, it slows down my program by an average 20%. Could you please shed... some light into the matter?
Re: Advent of Nim 2019 megathread
I'm in and learnin' Nim! [https://github.com/TheSpydog/AdventOfCode](https://github.com/TheSpydog/AdventOfCode)
Re: Bug or feature?
Ah, interesting. Thanks for explaining, makes sense.
Re: Bug or feature?
Global variable always deepCopy, local variable `let` assign using shallowCopy for value type, it is by design, not bug, not feature.
Re: Advent of Nim 2019 megathread
doin' it [https://github.com/exelotl/aoc2019](https://github.com/exelotl/aoc2019)
Re: Advent of Nim 2019 megathread
Good catch ;)
Re: Advent of Nim 2019 megathread
Decided to give this a proper try this year. Let's see how this goes. My repo is here: [https://github.com/dom96/aoc2019](https://github.com/dom96/aoc2019) Already found a bug in Nim heh: [https://github.com/nim-lang/Nim/issues/12788](https://github.com/nim-lang/Nim/issues/12788)
Re: Docker image for cross compiling
Looks like I misread it then - awesome work!
Re: Advent of Nim 2019 megathread
I'm kind of late to the party, but here goes. [https://github.com/liquid600pgm/aoc-2019](https://github.com/liquid600pgm/aoc-2019)
Bug or feature?
I came across a situation where using a `let` statement on a value object created a reference. I then correlated it with [this closed bug report](https://forum.nim-lang.org/a43!GG4hjurx). So, is this expected behavior?: Works as normal: var data: Table[string, string] data["key"] = "val" let oldData = data data.clear() echo $oldData # Echoes {"key": "val"} as expected Run Unexpected (uses `let`): proc doSomething(self: var Table[string, string]) = let data = self self.clear() echo $data # Echoes {} which isn't expected var data: Table[string, string] data["key"] = "val" data.doSomething() Run Works as normal (uses `var`): proc doSomething(self: var Table[string, string]) = var data = self self.clear() echo $data # Echoes {"key": "val"} as expected var data: Table[string, string] data["key"] = "val" data.doSomething() Run
Re: Advent of Nim 2019 megathread
Learning Nim as I do the Advent Of Code 2019. [https://github.com/gillesmag/advent-of-code-2019](https://github.com/gillesmag/advent-of-code-2019)
Question about multithreaded use of filestream.readLine() function
Hi, i currently use this code to divide work between worker threads: var linePtr: seq[pointer] for line in memSlices(memfiles.open($args["--inputFile"], mode = fmRead)): linePtr.add(line.data) let batchSize = (linePtr.len / parseInt($args["--cores"])).ceil().toInt() let f = system.open($args["--inputFile"]) {.push experimental: "parallel".} parallel: for i in 0..(parseInt($args["--cores"])-1): spawn worker(f, linePtr.at((batchSize * i)), batchSize) {.pop.} Run and this worker function: proc worker(fd: File, offset, size: int) {.thread.} = let fs = newFileStream(fd) fs.setPosition(offset) var i = 0 while i < size: echo i, " ", size, " ", fs.atEnd(), " ", fs.readLine() inc(i) Run now the thing is: the program throws after a random amount of lines an IOError; when i wrap the while-loop as follows: while i < size: try: echo i, " ", size, " ", fs.atEnd(), " ", fs.readLine() except IOError: echo i, " ", size, " ", fs.atEnd() inc(i) Run i see that fs.atEnd() returns true even if i shuld have lines left. Why is this happening and how do i crcumvent it? Also a little side question: i currently divide into chunks of size ceil(total_lines/core_count) this means the last chunk is bigger or smaller than the previous ones. Is it possible to use fs.atEnd() as in while i
Re: Advent of Nim 2019 megathread
badabing [https://github.com/SolitudeSF/adventOfCode](https://github.com/SolitudeSF/adventOfCode)
Re: Docker image for cross compiling
Isn't that just building Nim itself on different platforms? I didn't see anything in the official Docker images that are posted, [https://hub.docker.com/r/nimlang/nim](https://hub.docker.com/r/nimlang/nim), about being able to cross-compile your own Nim code.
Re: How to create a trojan and reverse shell with NIM
It's just for educational purposes as am trying to learn more about nim, the courses I took only applied it in python 2 but I thought I would find out help here in translating it In nim
Re: ``Table.take`` should be ``Table.pop`` -- discuss
An un-keyed `pop(Table): tuple[K,V]` more similar to `HashSet.pop` is mentioned in the PR commentary linked above. (I would personally just use the already-defined iterator than b3liever's inline expansion, but eh. Either way.) Totally suitable for another PR. I just wanted to keep the above one more focused.
Re: Docker image for cross compiling
This is already being done in the nightlies builds, except for OSX binaries. We are using Holy Build Box for older Linux builds and Dockcross for Arm builds. [https://github.com/nim-lang/nightlies](https://github.com/nim-lang/nightlies)/
Re: Docker image for cross compiling
This is now bumped to Nim version 1.0.4
Re: How to create a trojan and reverse shell with NIM
I would help him. He just needs to send me his IP and root password and I'll show him how.
Re: Advent of Nim 2019 megathread
I'm sticking to Nim this year too. [https://github.com/filipux/adventofcode2019](https://github.com/filipux/adventofcode2019)
Re: Advent of Nim 2019 megathread
As last year, I will use Nim and only Nim. [https://github.com/lscrd/AdventOfCode2019](https://github.com/lscrd/AdventOfCode2019)
Re: Advent of Nim 2019 megathread
I almost got convinced to defect to Ocaml, but sticking to Nim for this year: [https://github.com/zevv/aoc2019](https://github.com/zevv/aoc2019). Enjoy people!
Re: How to create a trojan and reverse shell with NIM
How can we help you commit bad deeds?! I suggest you forget this, and concentrate on doing something good instead.
Re: Advent of Nim 2019 megathread
Here we go :) [https://github.com/ducdetronquito/AdventOfCode2019](https://github.com/ducdetronquito/AdventOfCode2019)
Re: ``Table.take`` should be ``Table.pop`` -- discuss
Lol good point, I shouldn't post here when I had too little sleep.
Re: ``Table.take`` should be ``Table.pop`` -- discuss
Why mpop, the caller takes ownership of the result and must assign it or discard it.
Re: Advent of Nim 2019 megathread
happy to participate again! [https://github.com/pietroppeter/adventofnim](https://github.com/pietroppeter/adventofnim)