Nim v2: what would you change?

2024-01-04 Thread cdunn2001
There are many C libraries with `Foo`, `foo`, and `FOO`. I learned long ago how to rename in a wrapper. I can make Nim work for personal projects. But the problem is when I am trying to convince a team to adopt Nim. This single impediment ends all discussion. I work at a Mag7 company on embedde

Nim v2: what would you change?

2023-12-20 Thread cdunn2001
I keep wanting to return to Nim. It's such a great language in so many ways. But the most compelling reason to use Nim -- the easiest argument to make with a team of developers -- is C/C++ interop. That is hindered by The Thing Which Cannot Be Mentioned. So I'm back to wishing Zig had macros. B

Nim enters top 50 programming languages list on TIOBE Index!

2021-08-12 Thread cdunn2001
Wow. I just googled the user you mentioned. First, a different user names some very good reasons to use Nim: * That repo is labeled "My experiments in weaponizing Nim". And that user gives credit to @ShiteSecure for figuring out the key

Nim earns mention in the news (unfortunately?)

2021-08-04 Thread cdunn2001
The idea that they code in specific languages to avoid detection is absurd. The malware is in the binary. These are really good coders, and they are adopting agile languages because they are agile. Nim is particularly agile, and still low-level. I'd say this is a sign that Nim is about to explo

Use cstring for C binding

2021-07-07 Thread cdunn2001
I think you want s.setLen snprintf(s.cstring, s.cap + 1, "Foo bar %s", "Hello") # or s.setLen snprintf(s.cstring, MAX_LEN + 1, "Foo bar %s", "Hello") Run Otherwise, the longest string snprintf could write is only 1023 (plus a null), while the Nim string could

Use cstring for C binding

2021-07-07 Thread cdunn2001
var s = newString(1024) Run That creates a buffer of 1025 characters, but only 1024 are legally accessible. I.e. s[1024] = 'Z' Run is an error: Error: unhandled exception: index 1024 not in 0 .. 1023 [IndexDefect] Run

Life is a struggle - a struggle with Nim (video)

2021-06-29 Thread cdunn2001
re: > Is it used in production, or am I going to be the first to test it properly? My company uses it for some production code. I have never had a single problem with it. In my opinion, the global threadpool should be grounded. It writes checks that th

Life is a struggle - a struggle with Nim (video)

2021-06-29 Thread cdunn2001
> Not necessarily. It makes sense from the point of view of functionality - > i.e.: you want to limit the number of CPU-bound threads in your application, > so you can use your CPU cores efficiently. I cannot tell the program how many threads to use until inside `main()`. Using all CPUs is ofte

Life is a struggle - a struggle with Nim (video)

2021-06-29 Thread cdunn2001
You've overlooked the advantages of letting the compiler avoid the overhead when it's provably unnecessary, which is the typical case. When RC is truly a poor solution, you can use Boehm-Weiser instead.

Life is a struggle - a struggle with Nim (video)

2021-06-24 Thread cdunn2001
> So it is that exact case mentioned in Sean Parent's presentation :), right ? Yeah, but it's a bug in the library, not the language. A better criticism would be that the language has not settled. I'd rather not waste time on fixing "threadpool" until 2.0 is available. (I suspect that the global

Life is a struggle - a struggle with Nim (video)

2021-06-23 Thread cdunn2001
* Use ARC/ORC. I think the thread-based GC was always buggy, but it's not needed. Nim fills a niche as a Python replacement for easy interfacing to C (and possibly C++), and the reference-counted GC is much better in that application. * The global threadpool was an architectural mistake.

Nim in Meson?

2021-02-20 Thread cdunn2001
Does anyone know the status of Nim in Meson? * Is anyone still working on that?

How to convert const char * to string?

2021-01-20 Thread cdunn2001
I hit the same problem a long time ago. IIRC, I had to do this: let cstr = foo.asCstring() nimstr = $cstr Run I never learned why `$()` didn't work, but sometimes the parser has trouble. Not too big a deal.

Package level scope

2020-12-05 Thread cdunn2001
".privateimport." is long, but ".all." is too short. It would be a difficult thing to search. If I'm new to nim and see `{.all.}`, I might not know where to learn what's going on. It almost looks like a typo. "Did they mean 'call'?" It's so short that it's line-noise. I'm not convinced that "pr

Naming convention when calling procs from other modules?

2020-10-24 Thread cdunn2001
The first one (with module name) is way better if you want people to be able to read your code. I usually do this: from my_utils import nil ... my_utils.thisIsAProc() Run Unfortunately, templates generally assume that you have imported all symbols from th

Convert Time to Duration

2020-10-24 Thread cdunn2001
I'm confused. I just read another forum post that said never to access the "second" field of a Time object. (And it's private anyway.) We're supposed to use "toUnix()". Ok, but "nanosecond" is also a private field of "Time". Why is it ok to use one but not the other? Is "t.nanosecond" implicitly

Passing data between threads with ARC

2020-10-24 Thread cdunn2001
You can try editing your post to reformat. Use a "triple-backtick block, and put "nim" on the same line as the first triple-backtick. Then your code will be nicely formatted.

What could be the cause?

2020-10-24 Thread cdunn2001
After reformatting your code, copied from "lib/system/arc.nim" I guess: proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} = if p != nil: var cell = head(p) if (cell.rc and not rcMask) == 0: result = true when traceCollector:

Regarding the future of --gc:none and --gc:regions

2020-10-19 Thread cdunn2001
I think we need to understand why ARC was faster for Thavlak. That's strange. Anyway, aside from performance, there is another reason why regions can be helpful: cryptography. With a slight change to "withRegions()", there could be secure and efficient zero-ing of the previously used memory. I

Small introductory post about ARC/ORC in Nim.

2020-10-14 Thread cdunn2001
Interesting. This helps me understand what's going on. I was a big fan of "owned refs", but I didn't follow the discussion last year. I wanted to wait for the feature to becom

Nimpretty --maxLineLine seems broken

2020-10-09 Thread cdunn2001
I agree with this, but for a different reason. I have bad eyes, so I _always_ use 80 columns in my monitor. But my editor can line-wrap. The problem is when a function has several parameters. If I add one in the middle, the nimpretty wrap position moves. With different changes on different bran

Pointer Arithmetic and constructs like cast[var int](p) += sizeof(a[0])

2020-10-07 Thread cdunn2001
> Sad that he left Nim. What happened? Oddly, I cannot search for his posts here, as if the search engine ignores his name. I used to read every post he made.

Pointer Arithmetic and constructs like cast[var int](p) += sizeof(a[0])

2020-10-04 Thread cdunn2001
Interesting. var s = @[1, 2, 3, 4, 5] var p = addr s[0] echo p[] # 1 echo type(p) echo type((addr p)[]) echo type(cast[ptr int](addr p)[]) cast[var int](addr p) += sizeof(s[0]) echo p[] cast[ptr int](addr p)[] += sizeof(s[0]) echo p[]

80-bit (long double) support?

2020-10-04 Thread cdunn2001
When I compile with C++ instead of C backend: /usercode/nimcache/@min.nim.cpp: In function 'void coloneq___7zlIf7POTZHxgRJdjlbnawin(long double&, NF)': /usercode/nimcache/@min.nim.cpp:103:3: error: invalid type argument of unary '*' (have 'long double') *a=b; ^

it there general gitignore configs for binaries?

2020-09-30 Thread cdunn2001
I often use a makefile rule to generate "foo.exe" for each "foo.nim" %.exe: %.nim nim c -o:$@ $< Run To me the real problem is that "nim c" alters source directories by default. As a general rule, it's helpful if a build system builds into the current-work

Update on --gc:arc

2020-09-28 Thread cdunn2001
I'm confused. On the one hand, "Offers a shared heap." But on the other hand, "Well you cannot share them, you can move them around." If there is a shared heap, why can't we share?

get raw command line

2020-09-25 Thread cdunn2001
Result: $ ./foo 1 "2 3" 4 1 '2 3' 4 Run

get raw command line

2020-09-25 Thread cdunn2001
It doesn't exactly "remove" the quotes. The shell interprets them and stores into command-line arguments without them. A C program works the same way. I think you want `shellQuote`. import os import strutils import sug

abs(int8) returns int8?

2020-09-23 Thread cdunn2001
Good question! That's why C, C++, and C# all return the same type as the argument. If you write your own library: proc (int8 x): uint8 = if x > 0: return x else: return (

ARC/ORC cpu intensive loop bug?

2020-09-23 Thread cdunn2001
@mratsim, in the code you linked, what does this do? proc vec_zero(ret: pointer, num: csize_t) {.importc, exportc, header: srcPath/"vect.h", nodecl.} Run

Growth of popularity and Nim community

2020-09-22 Thread cdunn2001
For the record, I love the new GC. I hope the mentioned fix for ARC in arraymancer is merged soon because I want to start using that too.

On my first 'greet.nim' I get a C compiler error on RHEL 7

2020-09-02 Thread cdunn2001
Ugh! I put that line back, cleared the cache, but now I cannot cause that error anymore. Now, why is it suddenly _not_ happening? ... Ah. Switching to older gcc compiler does it. And I have to clear the cache whenever I change compilers. Ok, that's good to know.

On my first 'greet.nim' I get a C compiler error on RHEL 7

2020-09-02 Thread cdunn2001
For more info, see "overflow" here:

On my first 'greet.nim' I get a C compiler error on RHEL 7

2020-09-02 Thread cdunn2001
This happens for us with nim 1.2.0 also. But not with nim 0.20.0. Adding `-d:nimEmulateOverflowChecks` solves it, but why? Could someone explain why this happens? Is there a source-code change we could make? It doesn't happen everywhere or for other nim programs. I found the line of code that c

Proposal: Renaming imported symbols

2020-07-31 Thread cdunn2001
In theory, I agree with the poster. But in reality, there is something about Nim which leads to a philosophical change. I'll try to explain. I strongly prefer to show a symbol's origin explicitly, and I like a language to enforce that. With Python, at least you have to write `from foo import *`

cstring to string?

2020-07-23 Thread cdunn2001
Oh, I see it now. Thank you. [https://nim-lang.org/docs/manual.html#types-cstring-type](https://nim-lang.org/docs/manual.html#types-cstring-type) > A $ proc is defined for cstrings that returns a string.

cstring to string?

2020-07-22 Thread cdunn2001
Btw, I'm at the bleeding edge: commit ec65bfae3ac20a6c3d13249bc1fc8413db2b3abb (HEAD -> devel, origin/devel, origin/HEAD) Author: Miran Date: Wed Jul 22 05:57:40 2020 Change testing commands for some packages (#15041) Run So I'd understand

cstring to string?

2020-07-22 Thread cdunn2001
Same error. Here is what I had: -if exc.name == expected: +let name: string = exc.name.string +if name.startsWith(expected): Run See? When I was comparing cstring to string, it was working, but now I n

cstring to string?

2020-07-22 Thread cdunn2001
I'm trying to update my code for the latest Nim, and I'm hitting a weird error: 228 except Exception as exc: 229 let name: string = exc.name t_raptor_db.nim(229, 43) Error: type mismatch: got but expected 'string' Run I