Re: How to set a specific file as main file in VS Code ?
Tested this working today in settings.json: "code-runner.customCommand": "nim c -r --verbosity:0 --hints:off main.nim", Run ${workspaceFolder} throws an error in Nim for some reason, but you don't need it..
Nim now has Godbolt Compiler Support!
At long last: [https://nim.godbolt.org](https://nim.godbolt.org)/ We can thank [https://github.com/DaemonSnake](https://github.com/DaemonSnake) on github for this wonderful contribution :-D The PR for syntax highlighting was just accepted as well. So hopefully the next time they update the live site it will look prettier :-) Small note: There are a few small improvements that could be made around name mangling and source to asm mapping, if anyone has any thoughts: [https://github.com/mattgodbolt/compiler-explorer/pull/1753#issuecomment-570399679](https://github.com/mattgodbolt/compiler-explorer/pull/1753#issuecomment-570399679)
Re: How to write enum values without numbering order ?
Write a macro or create a feature request so that Nim reorders the enum internally on its own.
Re: How to get left most 8 bit's value from a 32 bit integer ?
The optimizing C compiler generates generally very good code for all the cases, but when you really need utmost performance you may inspect the generated assembler code. The cast to array may be a good solution when you need indeed bytes as result, but when you need ints as result, only with the selected bits, then shift and mask may be the better option. Note that you can exchange the order of shift and mask operation, you can first shift and then mask the lower 8 bits, or first mask and then shift. I think first shifting is simpler, because so you can always use the the same bitmask. In C for such operations Union types can be used, but Nim object variants does not allow such re-interpretion of content.
Re: nimble always install @#head for url
done: [https://github.com/nim-lang/nimble/issues/759](https://github.com/nim-lang/nimble/issues/759)
Re: nimble always install @#head for url
hrm, that's weird. Can you report it on GitHub?
How to write enum values without numbering order ?
Hi all, I want to write an enum like this. type KeyEnum* {. pure .} = enum A = 44, B = 45, apps = 72, add = 85, back = 2, C = 46, cancel = 1, capital = 8, capsLock = 8, clear = 5, D = 47, d0 = 34 Run But compiler says it is invalid order. I want to arrange my code alphabetical order for future maintenance. How to fix this error ?
Re: How to get left most 8 bit's value from a 32 bit integer ?
Thanks for the reply. Well, array of bytes is a good idea. Is there any speed penalty in that method ?
Re: A path commonPrefix function
When your commonPrefix takes 2 paths, length of both paths are n and both paths has no common prefix, it has O(n^2) time complexity. Because startsWith proc is O(n) and it is called n times. relativePath proc in os module calculate common prefix in O(n) time complexity. [https://github.com/nim-lang/Nim/blob/devel/lib/pure/os.nim](https://github.com/nim-lang/Nim/blob/devel/lib/pure/os.nim)
Re: A path commonPrefix function
something like that proc commonPrefix*(paths: openArray[string], sep = "/"): string = if len(paths) > 0: result = paths[0] for i in 1 .. paths.high: let path = paths[i] while not path.startsWith(result) and len(result) > 0: result.setLen(result.high) result.setLen(result.rfind(sep) + 1) Run
A path commonPrefix function
I have the following `commonPrefix()` function (for whole paths) which works fine on Linux (and Windows), but wondering if it could be shorter and/or more efficient? proc commonPrefix*(paths: openArray[string], sep = "/"): string = if len(paths) == 0: return "" result = paths[0] for path in paths[1 .. ^1]: while not path.startsWith(result) and len(result) > 0: result = result[0 .. ^2] result = result[0 .. result.rfind(sep)] Run Tests: test "commonPrefix": check(commonPrefix(["/tmp/test1", "/tmp/data.dat"]) == "/tmp/") check(commonPrefix(["/home/mark/test1", "/tmp/data.dat"]) == "/") check(commonPrefix(["/home/mark/test1", "local/data.dat"]) == "") Run