How to Save Directory Listing into Variable.

2023-03-16 Thread Yardanico
Right, I forgot about `toSeq` somehow :) Although your code does filtering to only include files and not folders, which is a bit different from what the OP asks, but useful as a point of reference nonetheless.

Comparison Rust vs Nim binary sizes for IOT applications (just an FYI if you're interested)

2023-03-16 Thread Yardanico
> If you know how to compile with clang and statically compile musl with Nim > please let me know Yes, you can use Zig (its C compiler feature). Just install Zig itself and then install , after that you can tell Nim to use `zigcc` as the Clang binary. Then

How to Save Directory Listing into Variable.

2023-03-16 Thread jackhftang
Want to add that you can also use `toSeq` in `sequtils` import std/[os, rdstdin, sequtils] let userInput = readLineFromStdin "Enter a directory > " let filePaths = toSeq(walkDir(userInput, relative = true)) .filterIt(it.kind == pcFile) .mapIt(it.path)

I asked chat-gpt to write a fft function in Nim

2023-03-16 Thread Yardanico
I've also tried using GPT - a lot of variations of it - ChatGPT (web), ChatGPT (the `gpt-3.5-turbo` model through the API), GPT-4, and on they own they do know Nim, but not that well. I think the only somewhat viable option is to use Bing Chat, because it has access to search and can read

How to Save Directory Listing into Variable.

2023-03-16 Thread Yardanico
The classic way is: import std/os stdout.write "Enter a directory > " let userInput = stdin.readLine() var dirs: seq[string] for (kind, path) in walkDir(userInput, relative = true): dirs.add path echo dirs Run If you don't want

How to Save Directory Listing into Variable.

2023-03-16 Thread Naterlarsen
Need to the sub-directories names and file names in that directory to a variable. Here is the example in python. import os user_input = input("Enter a directory > ") file_path = os.listdir(user_input) print(file_path) output: Enter a

I asked chat-gpt to write a fft function in Nim

2023-03-16 Thread xioren
HTML parser... import htmlparser type NodeKind = enum textNode, elementNode Node = object kind: NodeKind case kind: of textNode: text: string of elementNode: tag: string attrs:

I asked chat-gpt to write a fft function in Nim

2023-03-16 Thread xioren
proc fft(input: seq[complex[float]]): seq[complex[float]] = let n = input.len if n == 1: return input var even = @[input[i] | i in 0 ..< n by 2] var odd = @[input[i] | i in 1 ..< n by 2] var y = fft(even) & fft(odd) for k in 0 ..< n div 2:

Comparison Rust vs Nim binary sizes for IOT applications (just an FYI if you're interested)

2023-03-16 Thread giaco
FYI I've just repeated a similar test with: * Nim devel 1.9.1 * Nim stable 1.6.12 * Rust nightly (1.70.0-nightly) Shared conditions: * ubuntu 22.04 * print "Hello, World!" * static link * lto * panics * opt size * musl * strip * no binary compression * no hacks on

.o files going missing before linking?

2023-03-16 Thread dwhall256
What is the nature of your R: drive? If R: is not local to your machine, can you recreate this issue when building on a local filesystem?

Newbie needs help with locks and gcsafe and segfaults

2023-03-16 Thread sls1005
Whether it's pushed onto the stack or allocated on the heap has nothing to do with the fact that you cannot access the variable at the same time with two threads, unless they both don't modify it, or there'll be an error since it could be accessed while not fullly changed. If the DB lock also

/usr/lib/nim/lib/system.nim

2023-03-16 Thread tmsa04
Trying to build pakku-git with nim-git from the AUR this month is giving this error: ==> Starting build()... NIM: lib/tools Error: cannot open '/usr/lib/nim/lib/system.nim' make: *** [Makefile:115: lib/tools] Error 1 It was working back in January and with -d:nimPreviewSlimSystem yet now it

Slicing a string of characters from a starting point until all is selected.

2023-03-16 Thread Naterlarsen
Wow! Thanks for the help.

Trying to understand: is it better if IndexDefect is CatchableError or not

2023-03-16 Thread inv2004
I think it is the same like to suggest to show all mm:none or arc warnings for mm:org. But in case to show that problem is possible here But my idea to show the error, not to hide, because the exect Catchable, Defect will hide the problem, that is why I think it is better to show it when you

Trying to understand: is it better if IndexDefect is CatchableError or not

2023-03-16 Thread ElegantBeef
Is it not better to just turn it off if you do not care with `--warning[BareExcept]: off` so it does not effect all code, just your project? Any library that does expect a `defect` to be caught is the issue, if you know you want it caught that's down to you.

Trying to understand: is it better if IndexDefect is CatchableError or not

2023-03-16 Thread inv2004
I think that you are right, but it does not mean that it will be 100% ideal and better to not close the app anyway - I think it is a bit another question And one more question: I started to write `except CatchableError, Defect` everywhere just to supress the warning, that is why I think it

Trying to understand: is it better if IndexDefect is CatchableError or not

2023-03-16 Thread ElegantBeef
I feel like your anecdote with asciigraph is exactly evidence to the contrary, though that is just wishful thinking. The hope being if the library was developed where `try except` did not work on defects perhaps it would not have this bug.

Debugging Memory Usage in Nim

2023-03-16 Thread zevv
A few weeks ago I made this little tool for fun to visualize memory usage for multi threaded programs: it injects a little LD_PRELOAD lib overriding malloc() and friends and draws all allocations in a 2D hilbert projection of the heap; nice to get a "feel" of what your program is doing, also

Debugging Memory Usage in Nim

2023-03-16 Thread tanelso2
Valgrind was the ticket. Very easy to use Massif to find exactly what was growing unbounded over time.

Trying to understand: is it better if IndexDefect is CatchableError or not

2023-03-16 Thread inv2004
After the suggestion I still think that it would be better to not show the warning with panics:off

Newbie needs help with locks and gcsafe and segfaults

2023-03-16 Thread gs
Thank you very much... Now i am feeling a bit dump... I have the lock for the db but the compiler surely does not know that :) It protects the ulid global as well... But does this mean that this global inside the ulid package gets allocated everytime i call the ulid function and deallocated

Moderator updates

2023-03-16 Thread auxym
Thanks to all mods for your contribution to the Nim community!

How to sort 2d array?

2023-03-16 Thread vanderlei
Thanks for the quick feedback PMunch. I will test your suggestions in the next few days. I hope to be successful with your tips. ** By the way, this forum supports RST/Markdown styling so you should wrap your code in code block statements to make it easier to read. ** OK, next time I will try

All chr() up to 127 returns correct unicode character, but chr([128++]) returns �

2023-03-16 Thread PeterG
This works! Now I understand -- thank you.

All chr() up to 127 returns correct unicode character, but chr([128++]) returns �

2023-03-16 Thread PMunch
More specifically if you want to turn numbers into unicode characters you need to use the unicode module: import unicode for i in 120..127: echo i, ": ", i.Rune for i in 162..168: echo i, ": ", i.Rune Run

All chr() up to 127 returns correct unicode character, but chr([128++]) returns �

2023-03-16 Thread PeterG
Ah! Thank you so much. With ASCII, the problem still exists: any number 127 or higher produces �.

All chr() up to 127 returns correct unicode character, but chr([128++]) returns �

2023-03-16 Thread juancarlospaco
char is ASCII.

All chr() up to 127 returns correct unicode character, but chr([128++]) returns �

2023-03-16 Thread PeterG
I'm a newb. Re: **This single-line code:** echo chr(97) # a Run Returns the letter "a" All Unicode decimal numbers up to 127 work. But all Unicode numbers from 128 - 255 return � (replacement character) This also

Newbie needs help with locks and gcsafe and segfaults

2023-03-16 Thread sls1005
As I can remember, accessing to a global variable from one of the threads, is considered unsafe (non-multithreaded safe) because another thread can modify it at the same time. By enforcing every thread to hold something (the "lock," something that can only be held by excatly one thread at the

How to sort 2d array?

2023-03-16 Thread PMunch
You're on the right track, `sort` takes a procedure which defines how to do the actual sorting. What you need to do is to pass a procedure which compares the second element of each of the arrays and return an

How to sort 2d array?

2023-03-16 Thread vanderlei
For the past few weeks I have been working on converting an old script in Python to NIM. Despite little experience with NIM, I am very happy with the results, especially the performance. Ok, but there is something that I can't find a solution, even though it is simple, I did not found a way to

Slicing a string of characters from a starting point until all is selected.

2023-03-16 Thread foxoman
To Translate your python code to nim using the string slice: import os let myString = "filesizec:\\users\\nate\\desktop\\thepark.jpg" let newString = myString[8..^1] echo newString let fileSize = getFileSize(newString) echo "The file's size is:

Newbie needs help with locks and gcsafe and segfaults

2023-03-16 Thread gs
Hello everybody , Just started to try some nim. So it's my second day... Besides of some hussle with linking native libraries the experience is amazing. I have a rest api with mummy, which should persist to leveldb. For the keys I use ulid with some prefix… When I write it like this

Moderator updates

2023-03-16 Thread Zoom
Thanks for bringing some of us into the loop on name changes/connections. This explains a lot :D