Migrated Norm docs to nimibook and loving it!

2021-07-19 Thread Stefan_Salewski
How can I get it display all content in one large page instead of using a separate page for each subsection? (I really hate the later)

Guidance on Isolating Memory Leak

2021-07-19 Thread arnetheduck
We use -d:nimTypeNames together with to track memory usage over time, per type - it's quite useful for a first hint at what's wrong - here's a sample of what this looks like for a long-running process: [https://metrics.status.im/d/pgeNfj2Wz23/nimbus-fl

How to implement the 'Type parameters(aka generics)' as the following code

2021-07-19 Thread geohuz
I guess this is more concise: proc greeting(sp: SchoolPerson):string = let (kind, name) = (sp.kind, sp.name) case (kind, name): of (spkTeacher, _): "Hey Prof!" of (spkDirector, _): "Sup Guv" of (spkStudent, "Richard"): "Still here Dick?" el

Guidance on Isolating Memory Leak

2021-07-19 Thread Araq
With the old default GCs you can do this: * Compile with -d:nimTypeNames * At strategic places in your program call dumpNumberOfInstances to see what the GC heap contains. This is mostly useful to find logical leaks where data structures simply keep growing and since they stay alive, the

How can I point to (the memory adress of) a variable?

2021-07-19 Thread Stefan_Salewski
proc main = var num: int = 19; var p_num: ptr int = addr(num) echo cast[int](p_num) echo p_num[] main() Run To learn more details you may read

Guidance on Isolating Memory Leak

2021-07-19 Thread Araq
Compile with `--gc:orc -d:useMalloc` and/or `--gc:boehm` and see if it makes a difference. If the results don't change, you need to review your code and your used dependencies and watch out for data structures that keep growing, for example some "history" like objects with a `seq` inside that st

Question about "thread-local heap" garbage collectors and threads.

2021-07-19 Thread GordonBGood
@tsojtsoj: It might not be necessary, but it is implementation dependent: If the only use of `data` is to pass it to the spawned thread, then it will be moved to the thread and doesn't need to exist after that point, thus could be subject to garbage collection when triggered.

How to default non-trivial argument with `staitc[]` type

2021-07-19 Thread solo989
You additionally do this func cmpImplFunc(ignoreArgs: static[IgnoredArgs]) = discard macro cmdImpl(ignoreArgs: static[IgnoredArgs]): untyped = discard template cmd*(ignoreArgs : IgnoredArgs{`const`|lit} = IgnoredArgs()): untyped = cmdImpl(ignoreAr

How to default non-trivial argument with `staitc[]` type

2021-07-19 Thread solo989
This works if you don't need default arguments. proc pass(a : IgnoredArgs) : IgnoredArgs = a macro cmdImpl(ignoreArgs: static[IgnoredArgs]): untyped = discard template cmd*(ignoreArgs : static[IgnoredArgs]): untyped = cmdImpl(pass ignoreArgs)

How to default non-trivial argument with `staitc[]` type

2021-07-19 Thread solo989
You have the same problem if you try to pass a static seq through a template and then to a macro. The workaround there is to pass the static seq through an intermediate proc but that doesn't work here.

How to default non-trivial argument with `staitc[]` type

2021-07-19 Thread solo989
You could also do this if you don't have a non static overload. macro cmdImpl(ignoreArgs: static[IgnoredArgs]): untyped = discard template cmd*(ignoreArgs : IgnoredArgs = IgnoredArgs()): untyped = cmdImpl(ignoreArgs) Run

Youtube "Software Drag Racing" to count primes in Nim

2021-07-19 Thread ElegantBeef
The restraint is that it uses `classes` and as such a ref object + methods is the most fitting(which is odd), yea I probably should've used a larger size for the bitvector.

Template or macro for heterogeneous tuple expressions?

2021-07-19 Thread stu002
Thanks -- that's a very useful technique. I _think_ the generic `T: tuple | object` parameter and the `eq(xi, yi)` call have the same effect as my original `eq*[T, U: Eq](...)` function? That is, if types `T` and `U` implement `eq` so does `(T, U)`?

Migrated Norm docs to nimibook and loving it!

2021-07-19 Thread hugogranstrom
Great to hear you enjoyed it! đŸ˜„ Pietro really has created a really powerful and extensible framework for writing code and text in a great manner. You could do virtually anything you want with it without any boilerplate thanks to metaprogramming in Nim. Regarding build times, yes it's quite slow

Guidance on Isolating Memory Leak

2021-07-19 Thread rbohl64
Hello, I have an application ported from Python that leaks memory. As a first step to confirm a memory leak, a call to GC_getStatistics() and mratsim's getrusage() procedures is made every 100,000 json messages processed by the application. The output shows an incremental increase in the proces

How can I point to (the memory adress of) a variable?

2021-07-19 Thread rempas
I would like to know how I can do that. I've read the first part of the tutorial but I found that it needs improvement so here I am asking. For the people that didn't understand what I want to do. I'll make the example on so someone can tell me (and explain me how it works) the equivalent in Nim

Migrated Norm docs to nimibook and loving it!

2021-07-19 Thread moigagoo
The only thing I'd like improved about nimibook is build time. On every change in the source, nimibook rebuilds the entire book even if you changed a single character.

Migrated Norm docs to nimibook and loving it!

2021-07-19 Thread moigagoo
Just wanted to give a shoutout to Pietro Peterlongo, Regis Caillaud, and Hugo Granström for their great work on [nimibook](https://pietroppeter.github.io/nimibook/). I've just finished moving [Norm docs](https://norm.nim.town) from the built-in doc generator to nimibook and I have to say it was

Youtube "Software Drag Racing" to count primes in Nim

2021-07-19 Thread mratsim
I don't see the point of so many methods/dynamic dispatch there. An easy optimization would be to use a `seq[uint64]` instead of `seq[byte]` to back the bitvector. See my prime sieve:

How to default non-trivial argument with `staitc[]` type

2021-07-19 Thread cblake
A `static seq[T]` is really an `array` if you think about it. `array[3, int]` works. So, this may be an issue worthy bug, but within this observation might also lie a workaround for you for "right now"..just use `array` instead if you can get a `len` (which you should be able to do - somehow - i

"No handles or timers registered in dispatcher" in Chapter 3.17 example of Nim In Action

2021-07-19 Thread QMaster
It is a bad error making no sense at all for async environments. Just if you have any pending callbacks, but no timers and socket handlers it'll fail for no reason for good and completely working code. I was into that problem and shown you some examples why this is not good at all. And you advis

How to default non-trivial argument with `staitc[]` type

2021-07-19 Thread haxscramper
I I'm trying to pass non-trivial type as a `static[]` argument to a macro, but it fails to compile as soon as I add `seq` field to the type. I can pass `IgnoredArgs` if it has `int`, or `string` field, but adding `seq[]` immediately leads to a compilation error. What is wrong with my code, or is

How to implement the 'Type parameters(aka generics)' as the following code

2021-07-19 Thread geohuz
Thanks a lot! So glad to learn it!

New Nim Discussion Site

2021-07-19 Thread Fire
/

Youtube "Software Drag Racing" to count primes in Nim

2021-07-19 Thread GamzWithJamz
The Youtube channel [Dave's Garage](https://www.youtube.com/channel/UCNzszbnvQeFzObW0ghk0Ckw) has a series where he is implementing a prime counting algorithm in many different languages to see how the implementations stack up, all the while talking mostly about how the languages differ from on

How to implement the 'Type parameters(aka generics)' as the following code

2021-07-19 Thread shirleyquirk
One way might be: type spKind = enum spkTeacher,spkDirector,spkStudent SchoolPerson = object case kind:spKind of spkStudent: name: string else: discard proc greeting(sp: SchoolPerson):string = case sp.kind

How to implement the 'Type parameters(aka generics)' as the following code

2021-07-19 Thread geohuz
The following code snippet is from reasonml, a dialect from ocaml, type schoolPerson = Teacher | Director | Student(string); let greeting = person => switch (person) { | Teacher => "Hey Professor!" | Director => "Hello Director." | Student("Richard") =

New Nim Discussion Site

2021-07-19 Thread dom96
Suggestion: * `nim-lang` * `nim` I think something shorter would make it feel more official and professional. What do other language's spaces look like?

problem of run procedure with interval and stop the running

2021-07-19 Thread geohuz
Thanks for all the replies! It looks like the most elegant/simple way to "clear" an interval is to using chronos library, import chronos proc test() {.async.} = while true: await sleepAsync(1000) echo "test" proc run() {.async.} = let fut

Template or macro for heterogeneous tuple expressions?

2021-07-19 Thread demotomohiro
This code uses func eq(x, y: SomeOrdinal): bool = x == y func eq[T: tuple | object](x, y: T): bool = for xi, yi in fields(x, y): if not eq(xi, yi): return false return true d

Question about "thread-local heap" garbage collectors and threads.

2021-07-19 Thread tsojtsoj
Thanks for the answer. Is this `data.GC_ref`, `data.GC_unref` also necessary if I call `sync ()` in the name function (or in the same function where I created the `data` variable)?

Compiling with OpenSSL on Windows 10?

2021-07-19 Thread jasonfi
I mostly got it working with by directly passing the DLLs to the linker:\--passL:"C:\Dev\nim-1.4.8\bin\libssl-1_1-x64.dll" \--passL:"C:\Dev\nim-1.4.8\bin\libcrypto-1_1-x64.dll"| ---|--- Hopefully this helps someone. However I now get symbol not found errors for EVP_MD_CTX_create and EVP

Compiling with OpenSSL on Windows 10?

2021-07-19 Thread jasonfi
Can someone please post a working example of compiling with Nim 1.4.8 and OpenSSL? With -d:ssl alone I get undefined reference linker errors to the OpenSSL functions. Adding --lcrypto1.1 makes no difference.

Template or macro for heterogeneous tuple expressions?

2021-07-19 Thread stu002
Thanks for that insight.

Template or macro for heterogeneous tuple expressions?

2021-07-19 Thread stu002
Yes -- good point, I'm looking at that approach now as an alternative. Converting the tuples into a series of homogeneous sequences.

Template or macro for heterogeneous tuple expressions?

2021-07-19 Thread ynfle
I would suggest using an array for variable length