Re: Onsetgame ReelValley goes opensource
This is awesome! Thank you very much! ☺ I hope this gets as many views as possible. To promote this, I would highly recommend a more detailed blog post [(like this older one)](https://yglukhov.github.io/Making-ReelValley-Overview/) or an updated Web-site ([OnsetGame.com](http://onsetgame.com/) is out of date), both promoting the game and the development choices it involved. A video would also be awesome.
Re: no "--opt:size" leads EXE to "SIGSEGV: Illegal storage access. (Attempt to read from nil?)"
Maybe you have forgotten the binding, but I am using wxnim from [PMunch fork](https://github.com/PMunch/wxnim) from you, [Araq](https://github.com/Araq/wxnim), it is not my wrapping code. And the example2 is in the wxnim too. nim cpp -r -d:useSysAssert -d:useGcAssert example2.nim Run says Traceback (most recent call last) example2.nim(7) example2 example2.nim(40) createFrame SIGSEGV: Illegal storage access. (Attempt to read from nil?) Run where line 07 let f = createFrame() line 40 text.styleSetForeground(wxSTC_STYLE_LINENUMBER, constructWxColour(75, 75, 75) ) line 41 text.styleSetBackground(wxSTC_STYLE_LINENUMBER, constructWxColour(220, 220, 220)) Run if I comment out line 40 and 41, then the compiled EXE can run without crash. I am puzzled why line 7 can passed this time If I change line 40, 41 to line 40 var c1 = cnew constructWxColour(75, 75, 75) line 41 text.styleSetForeground(wxSTC_STYLE_LINENUMBER, c1 ) line 42 var c2 = cnew constructWxColour(220, 220, 220) line 43 text.styleSetBackground(wxSTC_STYLE_LINENUMBER, c2) Run then I get example2.nim(41, 7) Error: type mismatch: got but expected one of: proc styleSetForeground(this: var WxStyledTextCtrl; style: cint; fore: WxColour) first type mismatch at position: 3 required type: WxColour but expression 'c1' is of type: ptr WxColour 1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them expression: styleSetForeground(text, 33, c1) Run I still don't know how to fix it
Re: no "--opt:size" leads EXE to "SIGSEGV: Illegal storage access. (Attempt to read from nil?)"
Compile without -d:release and with `-d:useSysAssert -d:useGcAssert`, you have a memory corruption, most likely because of a bug in your wrapping code. Don't assume that it's "only" \--opt:size that makes your program crash, you are simply "lucky" for the other optimization levels.
Re: How to keep the output of a recursive proc?
Grabbing the result from stdout(echo) is a bit of a detour. You usually want to seperate the calculation of something from the I/O. So for example if you later want to use that function in a GUI application you wouldn't need any modifications to the function itself, you would fetch the inputs from the GUI and then put the calculated values back into the GUI. As a small note, your `output_lcs` proc has the return type `string`, but never writes to it, so it always returns an empty string when using echo. Now let's come back to the question. One solution would be always return the concatenated results of the recursive calls, like so: proc output_lcs(backtrack: seq[seq[int]], v: string, i: int, j: int): string = if i == 0 or j == 0: return if backtrack[i][j] == 1: result.add output_lcs(backtrack, v, i-1, j) elif backtrack[i][j] == 2: result.add output_lcs(backtrack, v, i, j-1) else: result.add output_lcs(backtrack, v, i-1, j-1) result.add v[i-1] Run The only thing left to do, is to remove the `result = ""` in the calling proc, so the last statement can count as an implicit return(we could also prepend the call by a return, but this way it's cleaner) Alternatively we could also pass a `string` as a var parameter, so we can modify the passed variable: proc output_lcs(backtrack: seq[seq[int]], v: string, i: int, j: int, result: var string)= if i == 0 or j == 0: return if backtrack[i][j] == 1: output_lcs(backtrack, v, i-1, j) elif backtrack[i][j] == 2: output_lcs(backtrack, v, i, j-1) else: output_lcs(backtrack, v, i-1, j-1) result.add v[i-1] Run Note that this result variable is not the implicitely defined one from a proc with return type. Here the name result is just choosen arbitrarily and doesn't bear any special meaning. In case we use this method, we also have to change the initial call, so that the recursive proc writes into the result variable of `lcs_backtrack`: output_lcs(backtrack, v, vlen, wlen, result) Run The latter solution is more efficient, since it only modifies the output the `string` when needed, though it doesn't really matter in this situation, because the bottlenecks lie in other places.
Re: Text adventure engine in Nim using macros
Surprising how the macro itself is larger than vanilla adaptation to nim.
Re: Text adventure engine in Nim using macros
Well it does a lot of work, which in the original, was the programmers burden. If you look at `originalprogram.nim` you will see it is quite hard to figure out the Map structure.
Re: How to keep the output of a recursive proc?
You should be able to pass an additional variable of type 'var string' around your recursive functions, and simply use add() to add characters as you go - strings in Nim are modifiable and adding to them is cheap. When you've fully bubbled back up the call stack the result is there for you in your string.
Text adventure engine in Nim using macros
Hey all! Wanted to share with you [Night Adventure](https://github.com/b3liever/nightadventure). It is... > This adventure is based on the original that was published in Sonic's "Python > Games: Programming _should_ be fun", at > DeltaHacker magazine in March 2012. > ...which in turn was based on Stathis Efthimiou's "Adventure Games", Pixel, > January 1986. Now also re-written in Nim! What might interest you is that I have chosen to write a `gameworld` macro which converts the Rooms in the game from Array Of Structures to SOA format. Instead of writting it OOP I also kept the original logic which used a 2x2 matrix to point to the next Rooms. All of that with a DSL which makes it easy to write your own adventure. Hope you like it!
How to use closureScope to be used in thread?
Thinking about it, would be nice if closureScope had an argument to capture the variable. As it stands now, is so redundant: for i in 0..threads.high: closureCapture i: captureMe(i) Run
How to keep the output of a recursive proc?
This is a homework problem where I am using nim to identify the longest common subsequence. I have the correct output, but I don't know how to grab the output from a recursive algorithm. Example: AACCTTGG ACACTGTGA Run Code to run example: import os, strutils, sequtils # down = 1 # right = 2 # diag = 3 proc pp[T](matrix: seq[seq[T]]): char = for line in matrix: echo line proc output_lcs(backtrack: seq[seq[int]], v: string, i: int, j: int): string = if i == 0 or j == 0: return if backtrack[i][j] == 1: discard output_lcs(backtrack, v, i-1, j) elif backtrack[i][j] == 2: discard output_lcs(backtrack, v, i, j-1) else: discard output_lcs(backtrack, v, i-1, j-1) echo v[i-1] proc lcs_backtrack(v: string, w: string): string = let vlen: int = v.len let wlen: int = w.len let sfill = repeat(repeat(0, wlen + 1), vlen + 1) let btfill = repeat(repeat(0, wlen + 1), vlen + 1) var s: seq[seq[int]] var backtrack: seq[seq[int]] result = "" s.add(sfill) backtrack.add(btfill) echo "starting matrices: " echo pp(s) echo pp(backtrack) for i in 1..vlen: for j in 1..wlen: if v[i-1] != w[j-1]: s[i][j] = max(@[s[i-1][j], s[i][j-1]]) else: s[i][j] = max(@[s[i-1][j], s[i][j-1], s[i-1][j-1] + 1]) if s[i][j] == s[i-1][j]: backtrack[i][j] = 1 elif s[i][j] == s[i][j-1]: backtrack[i][j] = 2 elif s[i][j] == s[i-1][j-1] + 1 and v[i-1] == w[j-1]: backtrack[i][j] = 3 echo "s after pop: " echo pp(s) echo "backtrack after pop: " echo pp(backtrack) echo output_lcs(backtrack, v, vlen, wlen) proc main() = let f = open(paramStr(1)) defer: f.close() let v = f.readLine() w = f.readLine() echo lcs_backtrack(v, w) main() Run I'm a bad coder so please ignore that. My main problem is with my recursive function: proc output_lcs(backtrack: seq[seq[int]], v: string, i: int, j: int): string = if i == 0 or j == 0: return if backtrack[i][j] == 1: discard output_lcs(backtrack, v, i-1, j) elif backtrack[i][j] == 2: discard output_lcs(backtrack, v, i, j-1) else: discard output_lcs(backtrack, v, i-1, j-1) echo v[i-1] Run The output looks like: A A C T T G Run which is the correct answer "AACTTG". But i'm not sure how to grab that output from echo (return doesn't work since it simply returns the the first return statement after i and j are both equal to 0. Hopefully this made a bit of sense. Thanks!
Re: "Nim needs better documentation" - share your thoughts
One more week, one more quick recap. In addition to 10 already improved modules last week, we now have better documentation for **7 more** modules: * sets, insets, parseopt, xmltree, algorithm, parsecsv, os Also, now when you're viewing the documentation for some proc, you can click on its name to get the direct link, for easier sharing. The following modules are in the works: * random, jsffi * * * **I 'm inviting you once again to help us with this.** [Here is the list](https://github.com/nim-lang/Nim/issues/10330) of modules you could work on (some of them are really short).
no "--opt:size" leads EXE to "SIGSEGV: Illegal storage access. (Attempt to read from nil?)"
I use nim in MSYS2+Mingw64 on Windows 7 64 bits. The involved code can be download [here](https://forums.wxwidgets.org/viewtopic.php?f=27=45513) which uses [wxnim](https://github.com/PMunch/wxnim) . And I have stated the [details to compile wxWidgets](https://github.com/PMunch/wxnim/issues/12) **First of all** I can compile and run the [CPP version by PB](https://forums.wxwidgets.org/viewtopic.php?f=27=45513), no matter with g++ -Os `(/opt/windows_64/bin/wx-config --cflags)` test.cpp `(/opt/windows_64/bin/wx-config --libs all)` Run or g++ `(/opt/windows_64/bin/wx-config --cflags)` test.cpp `(/opt/windows_64/bin/wx-config --libs all)` Run **Then for the nim code** I use $ nim Nim Compiler Version 0.19.9 [Windows: amd64] Compiled at 2019-01-28 Copyright (c) 2006-2018 by Andreas Rumpf Run $ nim cpp -r -d:release --passL:-s --opt:size example2.nim| the EXE runs without crash ---|--- $ nim cpp -r -d:release --passL:-s example2.nim| the EXE runs and crash $ nim cpp -r -d:release --opt:size example2.nim| the EXE runs without crash $ nim cpp -r -d:release example2.nim| the EXE runs and crash all the crashes says SIGSEGV: Illegal storage access. (Attempt to read from nil?) Error: execution of an external program failed: 'C:\Users\USER\.nimble\pkgs\wxnim-0.8.0\examples\purewx\example2.exe ' Run of cause, all the EXE files have different file size. so what is the problem and how to fix it? Thanks
Re: Buggy concepts
I wasn't able to create a MCVE, that's why I didn't include it in the post.
Re: Buggy concepts
Anything reproducible available?
Re: Buggy concepts
The situation is not as dire as described, I use them quite extensively in [emmy](https://github.com/unicredit/emmy) Still, I find some issues with them, they are not completely stable right now
Buggy concepts
Hello, I have been trying out Nim's concepts for the past few days, and I have to say: they're far from stable. In simple use cases they work, but when you add advanced OOP techniques into the mix, you get an amalgamate of compiler errors and meaningless exit codes. So far, concepts are very unpredictable, take my current project as an example: [https://github.com/liquid600pgm/rod](https://github.com/liquid600pgm/rod) I tried to create an interface for a proper `RodVM`, to avoid cyclic imports (and add some modularity). Unfortunately, it didn't work out, because for some reason, the compiler crashed with exit code 1 without any reason on compilation. I wasn't able to trace down where the issue is, so I went for a different model: I decided to use a `RodBaseVM` class, which didn't help at all. I still needed concepts to define a meta-type, that would describe a type that implements the required methods of a VM, but failed miserably, with a cryptic compiler error: Error: internal error: getTypeDescAux(tyProxy) No stack traceback available To create a stacktrace, rerun compilation with ./koch temp c Run I get that concepts are still in development, but I expected that the compiler would at least give me some line numbers, but no. That never happened. Overall, I think the overall idea behind concepts is brilliant: they're much more powerful and modular than interfaces, however, they still need a lot of work to be considered stable. TL;DR: Don't use concepts. Not yet, at least.
Re: Concatenate identifiers in template
Thank you!
Re: Concatenate identifiers in template
`proc `r id` = body ` Run
Concatenate identifiers in template
Hello, I would like to concatenate two identifiers in a template, like so: template myTemplate(id: untyped, body: untyped): untyped = proc r##id() = # I've seen it done this way in C body Run Is this possible without the use of macros?
Re: An Attempt to Access NumPy Array Data rom Nim
Thanks. Indeed, neo, arraymancer and nimtorch are feasible alternatives. Regarding accessing elements using ptr arithmetic, is there a simpler way? Is there a generic way for pointer casting (instead of ptr cdouble)?
Re: Read gzip-compressed file line by line
Thanks @dom96! see please my PR ti fix it: [https://github.com/nim-lang/zip/pull/35](https://github.com/nim-lang/zip/pull/35)