Compile w/o using parent directory configs

2020-07-23 Thread SolitudeSF
\--skipParentCfg:on|

What code is affected by runtime check pragmas?

2020-07-23 Thread Hlaaftana
> are the runtime checks also deactivated for g? Is there a difference if g is > a template or macro? No, yes. Templates/macros "insert" the code into the proc so it is affected by the checks, whereas proc calls merely call already generated code elsewhere, in this case `g` was not instantiated

Custom DllMain Windows

2020-07-23 Thread Yardanico
" cpu:i386 is specified to compile the dll as 32bit" \- of course, yes, that's what it means. "And if yes, do you know if it is actually needed or it’s just for convenience of some type?" \- maybe the game itself is 32-bit, then the DLL should be 32-bit as well

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
That’s really nice, I didn’t know that. Do you know if, in the url I sent, cpu:i386 is specified to compile the dll as 32bit? And if yes, do you know if it is actually needed or it’s just for convenience of some type?

Custom DllMain Windows

2020-07-23 Thread Yardanico
Yes, exactly - Nim is sometimes smarter than people think - with --app:lib on Windows Nim automatically makes a DllMain entry-point which calls into your starting code. There's no need to add it manually at all

HttpClient with UNIX_AF/SOCK_STREAM Socket instance

2020-07-23 Thread velvetkeyboard
I guess I will have to gave up on this one for now. Need more time to get used to the language to tackle this one on my own. But I'm still impressed how fast it was to build and test all the other parts not related to the socket itself. Appreciate all the replies on the issue. Thanks All.

Avoiding RangeError getting address of empty seq

2020-07-23 Thread lscrd
I think we were in a dialog of deaf. You were focused on the difference between uninitialized (with {.noinit.}) and initialized sequences (other sequences) whereas I was focused on the difference between sequences with no explicit initialization and sequences with explicit initialization. What

Compile w/o using parent directory configs

2020-07-23 Thread GoldtoothFour
Beginner here. I'm trying to compile a simple binary (`nim c binary.nim`) without using parent directories' `config.nims` or `nim.cfg` but it seems `--skipCfg` and friends don't do anything. What am I missing?

HttpClient with UNIX_AF/SOCK_STREAM Socket instance

2020-07-23 Thread euant
.net allows passing a HttpMessageHandler to the HttpClient constructor. The handler is responsible for sending a request: [https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmessagehandler?view=netcore-3.1](https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmessagehandle

What code is affected by runtime check pragmas?

2020-07-23 Thread juancarlospaco
I think it depends, if it is `template` or `macro` or `proc` or `proc {.inline.}`. But "normal" proc outside push/pop should not be affected. You can try using `macros.expandMacros` and friends.

Web app architecture?

2020-07-23 Thread cmc
I used jester to serve json to a karax frontend. I loved it. Best part was I used the same objects in karax and jester. The karax frintend app would populate and serialize one or more objects to JSON as the request body. The jester app would then deserialize, do backend things, and respond with

What code is affected by runtime check pragmas?

2020-07-23 Thread sschwarzer
I know I can use `-d:danger` to deactivate runtime checks for the whole program, but let's assume I usually want the checks, but only deactivate them for a certain section of my code. The [manual](https://nim-lang.org/docs/manual.html#pragmas-compilation-option-pragmas) describes pragmas to do

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
@Shucks I have made a little research, this guy doesnt seem to have any problems using winim functions, and another method to do things, have a look at it also [https://guidedhacking.com/threads/internal-with-nim.15281](https://guidedhacking.com/threads/internal-with-nim.15281)/

Web app architecture?

2020-07-23 Thread jasonprogrammer
I haven't used it yet but this web framework seems nice as well: [https://github.com/planety/Prologue](https://github.com/planety/Prologue)

Single Open Intermediate Language (SOIL) Initiative

2020-07-23 Thread jibal
Yeah, .NET is the closest thing to what SOIL apparently trying to be. I meant that C is the closest thing to an UNCOL ... but for interop with .NET, the JVM, and other such "hosted" environments, I suppose it isn't.

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
Thats because you disnt define DllMain, rename entryPoint to DllMain

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.

Compile time check for let

2020-07-23 Thread jibal
> I did try to make sense of his ideas in those diagnostic ways Yeah, sorry, I seem to have missed your comment earlier. > To me, const was always meant to be used for things who represent something > like a physical constant That's just one usage. In a language like Nim, which takes compile-ti

cstring to string?

2020-07-23 Thread jibal
> $(exc.name) No need for the parentheses ... $ binds less tightly than .

nim c fibonacci.nim

2020-07-23 Thread sschwarzer
If someone isn't aware that there are compiler options to influence the runtime, they may not understand the implications of "debug build" vs. "release build" either. ("I don't want to release this, so the 'debug build' should be fine." :-) ) That said, the message that a debug build is generat

Avoiding RangeError getting address of empty seq

2020-07-23 Thread jibal
> It doesn't matter, actually. Note my comment above: "there is a subtlety: the quoted C standard says that "pointer arguments on such a call shall still have valid values", which is not true of NULL (nil). But few implementations check the pointer when the len is 0, so people get away with it.

Troubleshooting huge memory leaks with ORC

2020-07-23 Thread Yardanico
I don't think there is one :)

Avoiding RangeError getting address of empty seq

2020-07-23 Thread snej
> But, then there is a inconsistency as some sequences of length 0 (those non > allocated) will return nil, while others (those empty) will return a non nil > value. It would be better to return nil in both cases. It doesn't matter, actually. Any two zero-length byte ranges (slices) are equival

Troubleshooting huge memory leaks with ORC

2020-07-23 Thread snej
What's the bug ID for this leak? I'd like to read and understand it, or at least get notifications.

Avoiding RangeError getting address of empty seq

2020-07-23 Thread jibal
> Yes, indeed, except that the compiler processes them the same way, i.e. both > are considered to have length 0. No, you're misunderstanding, and making the same mistake. An uninitialized seq, which you can get with {.noinit.}, has not been zero-filled ... it contains junk, and using it is lik

Web app architecture?

2020-07-23 Thread jasonfi
After researching this for a bit I found this playlist useful: [https://www.youtube.com/playlist?list=PL6RpFCvmb5SGw7aJK1E4goBxpMK3NvkON](https://www.youtube.com/playlist?list=PL6RpFCvmb5SGw7aJK1E4goBxpMK3NvkON)

Troubleshooting huge memory leaks with ORC

2020-07-23 Thread snej
Gosh dang it to heck! 🤬 I can't seem to keep track of which features are incompatible with which other features. So ARC/ORC works with threads but not with async. And non-ARC works with async but not with threads (in the way I want, i.e. passing objects between threads.) Is this async leak supp

ARC: Calling default destructor of embedded field from a destructor

2020-07-23 Thread Araq
In general yes maybe. But in this case a PR against the Nim repo so that we can review your spec additions is totally appropriate.

cstring to string?

2020-07-23 Thread snej
According to the manual, the correct conversion from `cstring` to `string` is the `$` operator — so use `$(exc.name)`. (Tested on bleeding-edge devel.)

Avoiding RangeError getting address of empty seq

2020-07-23 Thread lscrd
No, you can’t avoid the test as the area containing the length, the capacity and the items may not have been allocated yet, as in `var s: seq[int]`. You can’t return the address of something which doesn’t exist. Now, I agree that if this area has been allocated, it would be possible to simply r

ARC: Calling default destructor of embedded field from a destructor

2020-07-23 Thread snej
If the website used a wiki, it'd be super easy for people to fix these little documentation omissions (hint, hint)

Is it possible to mimic Go's Goroutines

2020-07-23 Thread Serge
Brilliant ! Thank you very much!

Is it possible to mimic Go's Goroutines

2020-07-23 Thread Serge
Thank you!

HttpClient with UNIX_AF/SOCK_STREAM Socket instance

2020-07-23 Thread snej
Option 1 won't work, it's just a duplicate method and I assume the compiler will complain. Option 2 is workable but requires minor changes to the HttpClient class, because Nim objects don't support dynamic dispatching by default. (In C++ terms, the overriding is non-virtual.) So if you implemen

nim c fibonacci.nim

2020-07-23 Thread juancarlospaco
Thats true, is too complicated to make it red color and green when is release/danger ?, is just "Discoverability" of the feature. I am joking about Observable stores, I wonder how that will evolve. :)

Avoiding RangeError getting address of empty seq

2020-07-23 Thread snej
A predefined proc for this could avoid the unnecessary range check and simply return the internal `seq` field that points to the items — that would boil down to one CPU instruction. If the seq is empty the result would presumably be `nil`, but as explained several times above (thanks, @jibal!)

nim c fibonacci.nim

2020-07-23 Thread Yardanico
Compiler already mentions if it's a debug or a release build - it's user's issue if they didn't read it :)

Troubleshooting huge memory leaks with ORC

2020-07-23 Thread Yardanico
And for heap profiling - compile with -d:useMalloc and possibly --debugger:native

nim c fibonacci.nim

2020-07-23 Thread snej
I like that idea of a warning. Maybe not in _all_ builds, but if the source code contains the strings `fibonacci` or `benchmark` ;-)

Troubleshooting huge memory leaks with ORC

2020-07-23 Thread Yardanico
As far as I know ORC sadly still leaks memory with async :(

Is it possible to mimic Go's Goroutines

2020-07-23 Thread snej
I think `waitfor A() and B()` is cleaner ... that way you can handle any errors that occur.

Link to documentation in homepage examples

2020-07-23 Thread ShalokShalom
"others might have their interest piqued, wondering what all means, and start reading the documents" Yeah. And thats the point. I happened to be such one who is interested and ready to read the documents, and got confused in the current, overwhelming and chaotic documentation. I actually offer

Custom DllMain Windows

2020-07-23 Thread Shucks
That code snippets I've coded are ofcourse compiled with --noMain. However the "nim" way didn't produces a valid dllmain. The emitting one does but I wan't to keep my code on nim.

Compile time check for let

2020-07-23 Thread ShalokShalom
Yeah, its the language barrier, although all the people involved in this thread already got the idea right, also cblake. I understand that there are details to the implementation who change the meaning of those things, while I try to keep it simple and understand those things on a practical sid

nim c fibonacci.nim

2020-07-23 Thread juancarlospaco
Ok, now is not too complicated to add: `Warning: Compiling on Debug mode, compiled result is slow, compile with -d:danger for performance.` It may even be more useful than the current `Warning: Observable stores.` (?) :P

Compile time check for let

2020-07-23 Thread juancarlospaco
But... a let can have compile-time parts and run-time parts, like when you use `let foo = block:`, that may or may not have `static( )` or even macro code somewhere in between.

Troubleshooting huge memory leaks with ORC

2020-07-23 Thread snej
I just noticed that my little WebSocket-based server is leaking memory like crazy — about 1GB for every time I run the test suite (serving ~40MB of data.) If I turn off `--gc:orc`, the leaks go away. (This is on devel from a few days ago, not 1.2.x.) Unfortunately my macOS heap-profiling expert

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
You can define DllMain and compile your code with —NoMain so that there are no issues, however I did have problems when using winim functions, I think it was because it tried to load kernel32, even though it was already loaded (in the injected process)

Custom DllMain Windows

2020-07-23 Thread Shucks
So this got asked [here](https://forum.nim-lang.org/t/3190) already. How to define a DllMain Entrypoint without emitting raw c code? My example doesn't works. Looking at the raw cache .c file it also doesn't looks correct at all. import winim/inc/[windef, wincon] proc mainT

raw binary data

2020-07-23 Thread cblake
@arch \- Well, in Nim I am pretty sure you can just implement your own `proc or` to do whatever you want on two `openArray[SomeInt]` params { `SomeInt` if you want something that could operate in bigger chunks than 1 byte. :-) }

Is it possible to mimic Go's Goroutines

2020-07-23 Thread cblake
Lol. :-) I mostly meant "schedulable on >1 CPU at a time" which then happens to be non-deterministic because the OS is scheduling who knows what, but yeah. I probably should have mentioned weave, too, which can presumably do this without crashing?

nim c fibonacci.nim

2020-07-23 Thread cblake
For the curious it matters quite a bit to do floating point arithmetic because a "big" optimization in question relates to FP vectorization. There are more details in the @xyz32, @aedt @cblake and @oyster comments in [https://forum.nim-lang.org/t/1779](https://forum.nim-lang.org/t/1779) (which

nim c fibonacci.nim

2020-07-23 Thread mratsim
See also [https://forum.nim-lang.org/t/4253](https://forum.nim-lang.org/t/4253) / [https://github.com/drujensen/fib](https://github.com/drujensen/fib) where Nim C++ was 8 times faster than C, Nim C or C++. Single-threaded Fibonacci is a benchmark of tail-call optimizations and tail-call folding

raw binary data

2020-07-23 Thread arch
@mratsim thank you for the libs. I'm going to check them out.

Experimenting with a FreeRTOS OS Port

2020-07-23 Thread elcritch
P.S. Unfortunately I didn't get a chance to rebase a PR last weekend. I'm still working on it, but work priorities have kept me elsewhere for a bit.

Experimenting with a FreeRTOS OS Port

2020-07-23 Thread elcritch
> Personally, I don't like this approach. If we have --os:esp-idf, then will we > have --os:companly_a, --os:company_b, etc, later? Yah, that's part of why I realized really it's about supporting FreeRTOS + LwIP. Then each cpu is just setting the RTOS people might be using. Though I imagine com

raw binary data

2020-07-23 Thread mratsim
Use `seq[byte]` (heap allocates), `array[N, byte]` or `openArray[byte]` (equivalent pointer+length) The following libraries are battle-tested for raw byte manipulation and are being audited by security firms: * stew/byteutils: [https://github.com/status-im/nim-stew/blob/master/stew/byteutils

Is it possible to mimic Go's Goroutines

2020-07-23 Thread mratsim
If you want non-deterministic ordering you need to use multithreading. But usually we use multithreading **despite** non-determinism.

raw binary data

2020-07-23 Thread arch
Thank you @cblake. But it seems that openArrays can be used only as params. And sequences don't support bitwise operators like this: seq1 or seq2.

Avoiding RangeError getting address of empty seq

2020-07-23 Thread lscrd
> Empty is not uninitialized--they are two completely different concepts. Yes, indeed, except that the compiler processes them the same way, i.e. both are considered to have length 0. In fact, there are no uninitialized objects in Nim. If you write `var s: seq[int]`, the memory area representin

Single Open Intermediate Language (SOIL) Initiative

2020-07-23 Thread Araq
> Nim (that is, Araq) made a wise choice and targeted the closest thing to it: C Heh, IMO .NET is actually the closest thing to it, it supports many dynamic features, it supports GC, it supports reflection and value based datatypes. Yes, it's from Microsoft so now we need webassembly instead. Bu

Is it necessary to extract the content of a Table into a sequence for ordering

2020-07-23 Thread Serge
Thanks!

Is it possible to mimic Go's Goroutines

2020-07-23 Thread cblake
Right. This produces "lock step" A,B,A,B,A,B. He had referred to "A,B,B,AA,B" which I took to refer to non-deterministic/truly parallel work. He'll have to chime in with what he really meant. :-)

Is it possible to mimic Go's Goroutines

2020-07-23 Thread dom96
Yes, it is possible: import asyncdispatch proc A() {.async.} = for _ in 1..10: echo("A") await sleepAsync(0) proc B() {.async.} = for _ in 1..10: echo("B") await sleepAsync(0) asyncCheck A()

embed DLL into EXE?

2020-07-23 Thread oyster
no I mean why newFileStream("libadd.dll").readAll() can't return binary data well, but staticRead("libadd.dll") returns binary data without problem. What is the reasonable relationship between static and binary data, and bad-relationship between readall and binary data?

Is it possible to mimic Go's Goroutines

2020-07-23 Thread cblake
It sounds like what you want is less "async output" and more "truly parallel execution with whatever work happens to finish earliest" winning the race. This is similar to the Unix process level `wait4(-1,..)` or `waitpid(-1,..)` which I have found quite useful from time to time, but on the finer

Single Open Intermediate Language (SOIL) Initiative

2020-07-23 Thread cblake
While I am 100% sure @jibal already knows, it perhaps bears mention for others that the idea has had **_many_** incarnations -- only a tiny fraction of which are on that Wikipedia page. Things like SUIF, C--, the internals of practically any retargetable compiler, and on and on. The Wikipedia pa

HttpClient with UNIX_AF/SOCK_STREAM Socket instance

2020-07-23 Thread velvetkeyboard
In Python i was able to override a class method that handler to socket connection. Bellow is the simplified sample: from http.client import HTTPConnection # Core Library class HTTPConnectionUnixSocket(HTTPConnection): def connect(self): sock = socket.soc

Compile time check for let

2020-07-23 Thread cblake
I did try to make sense of his ideas in those diagnostic ways (which I think could add value though maybe not be a high priority), but I guess my description was not to @ShalokShalom's liking. :-(

raw binary data

2020-07-23 Thread cblake
I think @arch should probably use seq[char] or maybe seq[uint8], but the first class openArray[T] idea may also be relevant: [https://github.com/nim-lang/RFCs/issues/88](https://github.com/nim-lang/RFCs/issues/88) There are also existing ways (toOpenArray[uint8]) where you could probably write

Is it possible to mimic Go's Goroutines

2020-07-23 Thread Serge
Is it possible to modify: The following snippet so as to print alternatively "A" and "B", like: A, B, B, A, A, B, etc... import asyncdispatch proc A() {.async.} = for _ in 1..10: echo("A") proc B() {.async.} = for _ in 1..10:

HttpClient with UNIX_AF/SOCK_STREAM Socket instance

2020-07-23 Thread dom96
How do other languages solve this problem?

nim c fibonacci.nim

2020-07-23 Thread cblake
FWIW, I copy-pasted his code, ran it with PGO and the Nim was actually 1.5x faster than the C...I believe this is due to a quirky/sensitive gcc optimization that the very specific layout of the Nim C code allows that the most natural C code does not. Recursive Fibonacci was only ever useful as

HttpClient with UNIX_AF/SOCK_STREAM Socket instance

2020-07-23 Thread velvetkeyboard
Goal: Use the _HttpClient_ to communicate with a _ReST API_ through a _UNIX socket_ provided by a _daemon_. Details: _Podman_ is providing a brand new _ReST API_ (v2.0) and the _podman daemon_ creates a _unix socket_ to which we can connect and start talking with the application using _HTTP_.

Is it necessary to extract the content of a Table into a sequence for ordering

2020-07-23 Thread cblake
@Serge \- it looks like you probably want CountTable which also has a sort proc available. See [https://nim-lang.org/docs/tables.html](https://nim-lang.org/docs/tables.html)

Is it necessary to extract the content of a Table into a sequence for ordering

2020-07-23 Thread Stefan_Salewski
I learned recently that there is an ordered table, and a sort() proc which can be applied to that ordered table. But I have not used it myself.

Is it necessary to extract the content of a Table into a sequence for ordering

2020-07-23 Thread filcuc
Or use a sorted Seq and binary search

Web app architecture?

2020-07-23 Thread jasonfi
I want to build a web app using Nim. It would have several pages, but each page should have AJAX abilities if required. Would Jester + htmlx work for this? For reference htmlx is the successor to intercooler js: [https://github.com/htmlx-org/HTMLx](https://github.com/htmlx-org/HTMLx) Could some

More readable C name-mangling?

2020-07-23 Thread JPLRouge
I was confronted, when switching to gc-arc for typeinfo the compilation did not find any error except for the encapsulation in C. But I quickly understood the mode of operation and the associations with the references (line) of the code. This allowed me to correct;). As for debugging the module

nim c fibonacci.nim

2020-07-23 Thread JPLRouge
to say nothing is also to let it go, approved. therefore validated. I agree with @Stefan_Salewski, impossible to say, it gives a bad opinion ...

Is it necessary to extract the content of a Table into a sequence for ordering

2020-07-23 Thread Serge
Here is an example (snippet): > # Dico is a table var Dico = initTable[string, int]() > > #wc is a tuple > > type wc = tuple > word: string count: int > > # wc_seq is a sequence var wc_seq: seq[wc] > > for p in Dico.pairs: > wc_seq.add(p) > > # sorting the sequence: wc_seq.sort(myCmp)

nim c fibonacci.nim

2020-07-23 Thread Stefan_Salewski
> we don't need to call the author stupid or a fool. Sometimes I try to make a friendly face. But when I see a fool I call him a fool, and when I see garbage I call it garbage. The author has been told about his debug mode issue 4 days ago. And did he care? Not at all. Writing about something

embed DLL into EXE?

2020-07-23 Thread jibal
> slurp or staticRead sounds too weird for me to recall what they really do What would be _more_ obvious and explanatory of a name than staticRead, given that one is familiar enough with the language to know that "static" refers to compile time values?

nim c fibonacci.nim

2020-07-23 Thread Vindaar
Independent of whether the article is good or bad, we don't need to call the author stupid or a fool. Also, we should be happy people outside the main community take note of Nim and write articles about it. If they get something wrong, we should educate and not insult them. Especially given th

Link to documentation in homepage examples

2020-07-23 Thread jibal
> why is Person in a capital letter P in the let statement and with some small > one in the following for .. in? One's a type and the other is a variable of that type. [https://nim-lang.org/docs/nep1.html#introduction-naming-conventions](https://nim-lang.org/docs/nep1.html#introduction-naming-co

Single Open Intermediate Language (SOIL) Initiative

2020-07-23 Thread jibal
This idea is almost as old as I am (it does predate my entry into programming by a few years): [https://en.wikipedia.org/wiki/UNCOL](https://en.wikipedia.org/wiki/UNCOL) Nim (that is, Araq) made a wise choice and targeted the closest thing to it: C

Single Open Intermediate Language (SOIL) Initiative

2020-07-23 Thread Yardanico
I'm sorry, but I don't think Nim should consider targeting SOIL at this point. It seems to be in a design stage, and doesn't have exact answers for how it will solve problems of current IR representations, it just promises that "it will be better". Also it seems to be heavily geared towards the

Single Open Intermediate Language (SOIL) Initiative

2020-07-23 Thread sirinath
I came across the [SOIL-initiative]([http://soil-initiative.org/](http://soil-initiative.org/)) which aims to create a Single Open Intermediate Language. I believe perhaps if there is a collaboration with this initiative it might be of mutual benefit for this project also. This can help further

Inheriting builtin types

2020-07-23 Thread jibal
> So nim's way is to make you implement all the methods you need by hand ? No, Nim's way is to not do wrongheaded subclassing, as explained.

nim c fibonacci.nim

2020-07-23 Thread Yardanico
They try to pretend to be more professional than they are or just want to try to gain some followers :P I only wrote one article about Nim sadly, in 2017 when I was relatively new to the language (and it's very small and just shows generics/converters).

Storing coordinates in a set/HashSet?

2020-07-23 Thread jibal
You can store any type in a HashSet as long as hash and == are defined on the type (this is explained in the tables documentation but is omitted in the sets documentation). If you still have trouble, maybe post what you've tried.

Python transpiler

2020-07-23 Thread jibal
> I mean a transpiler for Nim to Python, like it already exists for C, C++ and > ObjectiveC The Nim compiler is a compiler, not a transpiler. I realize that many people don't understand the difference between a compiler for language A that generates code in language B, and a transpiler from lan

Compile time check for let

2020-07-23 Thread jibal
It may partially be the language barrier, but your comments are incoherent. You could replace every const with let and it wouldn't affect program behavior unless the variable is used in a when or {.compiletime.} context. And you could replace every let with const as long as the initializer can b

Avoiding RangeError getting address of empty seq

2020-07-23 Thread jibal
C and C++ define the address of the element one beyond the end of an array to be referable but not dereferenceable ... that is, you can take its address but you can't access its content. Nim considers merely taking the address of the element one beyond the end of an array or sequence to be a ran