9999999999999999.0 – 9999999999999998.0

2024-01-11 Thread auxym
Nim doesn't "fail", Nim uses machine native floats by default (double precision to be exact) and your your CPU conforms to the IEEE 754 spec for floats. Therefore, this result is expected. > What Every Computer Scientist Should Know About Floating-Point Arithmetic : >

`nph` opinionated formatter v0.3

2024-01-09 Thread auxym
Myself and @xigoi commented in a previous thread I believe. For me, I think it's mostly a matter of consistency with other infix operators (1 + 1 rather than 1+1).

`nph` opinonated formatter v0.2

2023-12-22 Thread auxym
Any reason why Nim 2.0.2 is not supported?

Hello `nph`, an opinionated source code formatter for Nim

2023-12-19 Thread auxym
Agreed on that, I'd strongly prefer to have spaces around all infix operators, including `..` and `..<`.

Hello `nph`, an opinionated source code formatter for Nim

2023-12-16 Thread auxym
You're right, my vs code was (slightly) outdated. Thank you, extension works great, I am now a happy user of nph for all my Nim code :)

Can Nim interact with the hardware at a lower level than the C programming language?

2023-12-16 Thread auxym
was made for this and provides bindings to well know, robust libs (openssl and libsodium).

Hello `nph`, an opinionated source code formatter for Nim

2023-12-12 Thread auxym
Wow that's great, thanks! Though I'm getting the following error when trying to install in VS Code: > Can't install "arnetheduck.vscode-nph" extension because it is not compatible > with the current version of Visual Studio Code (1.84.2) I don't know anything about vs code extensions, is there

Hello `nph`, an opinionated source code formatter for Nim

2023-12-11 Thread auxym
With regards to treeform's suggestions; 1. I personally like the increased length to 88 chars 2. On the subject of blank lines, my impression, which may be mistaken, is that black changes the lines in between top-level functions/classes/methods but leaves blank lines within functions

How does 'nim secret' actually work?

2023-12-10 Thread auxym
You might also be interested in INim, which works by compiling the input on-the-fly with tcc, a small and non-optimizing, but very fast, C compiler.

Hello `nph`, an opinionated source code formatter for Nim

2023-12-10 Thread auxym
Awesome! I recently filled out the Nim survey, and one of the top things I found missing from the Nim tooling ecosystem is a good formatter (like black for python). Really looking forward to using this. If anyone has set this up in VS Code, let us know how. Would we need to update saem's

hardware-software interaction in Nim

2023-12-08 Thread auxym
If your drone runs something like px4 or ArduPilot, then you would basically only have to implement mavlink () in Nim and you could read data from your drone and send commands to it. Mavlink is pretty straightforward. 2 years ago I made a minimal implementation for

os:any vs os:standalone

2023-11-19 Thread auxym
My understanding is that `any` supercedes `standalone` and that `standalone` should probably be deprecated, but I'm not 100% sure. FYI here is the PR that added `os:any`:

Embedded: svd2nim for read/write of ARM Cortex micros

2023-06-16 Thread auxym
Hi! Could you let me know how you produced the assembly output (for a specific proc?). I'll play around with different (nim) codegen options and see how that ends up compiled by gcc. Are you compiling with -d:danger --opt:size?

volatile_store codegen error ?

2023-06-15 Thread auxym
Pretty sure you're correct that it's the issue you linked. Just wrap code in a main() proc or something similar as a workaround.

Library for tracking pressed keys

2023-06-14 Thread auxym
SDL is another option, but I don't think it will capture key events when the window isn't even focused. Likely because the OS doesn't even pass the key events to the app when it isn't focused, so it has no way to see them. You'll probably have to hook into the OS (in an OS-specific way) at a

How doeas NIM differ from Mojo programming language?

2023-06-13 Thread auxym
Serious answer: You can actually download and use the Nim compiler. It is mature and will hit 2.0 soon. Nim is open-source. Mojo appears to use manual memory management with borrow checking, like Rust, whereas Nim has fully automatic, yet deterministic, memory management via ARC

Can Nim be considered an independent language?

2023-06-10 Thread auxym
https://peterme.net/is-nim-a-transpiler.html

Replicate python code in nim

2023-05-21 Thread auxym
Consider also constantine, which was especially designed for crypto applications . BigInt type and shift procs available is this module specifically: Should be

Ed25519 signing for nim

2023-04-29 Thread auxym
Here's one implementation. Since its from status I'd tend to trust it:

Can I download Nim on my iOS or Android device?

2023-04-29 Thread auxym
You might be interested in replit, which provides an online dev environment supporting Nim:

Is there still interest to develop INim or are there better Nim REPL?

2023-04-23 Thread auxym
This is just my opinion, but if the maintainers are unresponsive, or even if your opinion just diverges from the maintainers', then its perfectly reasonable to fork the project (with a name change) to continue development. That's what open source is for! Most discussion happens either here or

Moderator updates

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

Export C library components when using `--app:lib`

2023-03-15 Thread auxym
That's odd and might be a bug, as the docs specify: > The compile pragma can be used to compile and link a C/C++ source file with > the project I've persoally used `{.compile.}` in the past and haven't had a problem, Nim was building and linking the requested C files as requested.

Example of simple parser?

2023-03-15 Thread auxym
FWIW, if you're only interested in writing a simple recursive-descent parser that outputs an AST, you can stop after chapter 6 (out of 30). The rest of the book is about writing an interpreter and bytecode compiler.

Export C library components when using `--app:lib`

2023-03-15 Thread auxym
If I'm understanding correctly, you are compiling a static or dynamic library, in which you are including C code using {.compile.}, and you want whatever is in those C files to be accessible to C code that is linked against your lib (or Nim via importc I guess)? If so, you shouldn't need to do

Why does Nim compiler allways depends on another's language compiler?

2023-03-13 Thread auxym
IAR and Keil are mostly used with ARM cortex-M, which Nim supports very well via arm-none-eabi-gcc. In fact, exactly thanks to Nim's piggybacking on gcc, Nim supports many embedded targets including ARM (many versions, including stuff like GBA and Nintendo Switch), RISCV, AVR and MIPS. Would

Example of simple parser?

2023-03-13 Thread auxym
In case you weren't aware, Crafting Interpreters is a great book and freely available online: It gently walks you through writing a parser (and later an interpreter) for a java-like language using recursive descent (with code in java) and Pratt parsing (in

Nested macro expansion order

2023-03-10 Thread auxym
Yes, macros are expanded "outside in". That is, the outermost macro is evaluating. Then, if the resulting AST contains more macros (or templates), they are evaluated, and the process continues like this recursively.

How do I detect/guess the encoding used in a text file?

2023-02-22 Thread auxym
One option would be to wrap this library: Or look at the algorithms it implements and rewrite in Nim. I did not find an existing Nim equivalent from a cursory search on nimble directory.

Is it possible to only compile the linked modules but not the executable?

2023-02-21 Thread auxym
Can you link an example that does this compile-time only behavior? I had a look at: >From what I can tell, there is no compile-time code in there. It generates the >STEP file in main() at runtime. You could compile it once,

Is it possible to only compile the linked modules but not the executable?

2023-02-21 Thread auxym
To be honest it's still not clear to me what the situation is. You have a Nim module which generates a STEP model at compile time? Sounds like a weird situation, but anyways could you run the module as nimscript using nim e? That's what happens when you compile a module, compile time code is

Is there a way to automatically find the path to nimbase.h when installed with choosenim?

2023-02-19 Thread auxym
I implemented elcritch's nim dump method (thanks) in picostdlib, in case it can be useful to someone else: (with some extra checks rather than sort and pick the first path)

Leaving out type names during compilation

2023-02-18 Thread auxym
Methods and class inheritance need runtime type information in order to function. Maybe don't use these nim features if you don't want types in the compiled code. Or use some sort of automated C obfuscator before calling the C compiler (you could write some sort of shim program that obfuscates

Is there a way to automatically find the path to nimbase.h when installed with choosenim?

2023-02-17 Thread auxym
That, or it could be implemented as a library proc in system or std/os like `getCurrentCompilerExe`. If you want to shell out with make you can then do something like `nim --verbosity:0 --eval:"import std/os; echo getCurrentLibPath()"` (runs as nimscript) I could probably put in a PR for

Is there a way to automatically find the path to nimbase.h when installed with choosenim?

2023-02-17 Thread auxym
This is how I implemented it in picostdlib: Works for me on linux and windows using choosenim. It should find the "lib" directory (containing the nimbase.h file) that is associated with the "nim" binary currently on

Expose static nim library to DLL

2023-02-17 Thread auxym
You might also be interested in the genny library, especially if you need to generate a header file for your exported Nim procs.

Trouble with Nim debugging in VS Code

2023-02-14 Thread auxym
Agreed. The debugging situation is not great and a large part of the whole poor tooling situation. Out of curiosity, C++ does name mangling too IIRC? How is that handled by gdb? Is it possible to map the non-mangled symbols in the DWARF data?

what's with deepCopy?

2023-02-05 Thread auxym
Correct, that won't copy children refs. Which is why deepcopy is useful. But I've also found myself wondering why deepcopy needs a separate compiler option and what are the tradeoffs involved. I hope araq or someone else familiar with ARC internals will be able to shed some light.

how to convert to pure c++ code and how do i do classification prediction on my project? am new

2023-01-24 Thread auxym
As a further note: nim's generated code is not supposed to human-readable. Nim treats c/c++ like gcc treats assembly: as a backend machine language.

Numerical libraries for data science

2023-01-17 Thread auxym
Have a look at genny to automate python bindings to nim: And weave for parallel processing:

Question about async programming

2023-01-06 Thread auxym
I am far from an expert on this, but my understanding of nim and python async runtimes, is that task switches (check for pending future, etc) _only_ happen when the routine that is currently running invokes `await` (or finishes). `await` explicitly pauses your routine and gives the control back

How to further speed up the build of your Nim's projects (using ccache)

2022-12-25 Thread auxym
Doesn't Linux cache files in unused ram already?

Formal verification in Nim using COQ and other proof assistants

2022-12-23 Thread auxym
?

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-20 Thread auxym
I also hit this issue recently. Do you know if there is a github issue already tracking this?

BigNum and BigInt timings on the Pollard Rho algorithm

2022-12-15 Thread auxym
Maybe also of interest:

Do you have to use 'ref' for the field types within ref objects?

2022-12-01 Thread auxym
As far as I know, nim always passes by ref for value types larger than 24 bytes.

Advent of Nim 2022

2022-11-30 Thread auxym
I'm in for sure, AOC is always good fun, especially in Nim. <https://github.com/auxym/AdventOfCode> Young kids mean programming time is limited. I'll probably get the first couple days in time, and finish it up after christmas. Still managed to solve all days except 24 last year!

Looking for a pair programming partner / coach

2022-11-25 Thread auxym
Also do feel free to hit up discord and ask questions or even a code review. I'd be glad to review some code once in a while, as I also think it would be great to have a high quality graph library in the Nim ecosystem.

Best way for ipc between a rust app and Nim app?

2022-11-25 Thread auxym
I second zmq, works really well. Nim has bindings maintained by araq: Plus, zmq docs are really well written.

Declaring an uninitialized seq & avoid unnecessary zero-mem's

2022-10-24 Thread auxym
This maybe?

Nim 2: What’s special about Task?

2022-10-23 Thread auxym
I enjoyed Araq's talk, but I also had the same question. How is Task different than wrapping a proc in a closure that includes its arguments, then passing that closure around as an object? Ringabout/flywind posted the following on discord: > Yeah, let x = toTask(hello(521, "123")) is roughly

How do I turn binary file data into hex representation

2022-10-15 Thread auxym
There is toHex in strutils: You'll have to chunk the resulting string into 2-character strings yourself though, which you can do with eg countUp.

How to declare a varible in a case statement for use afterwrads

2022-10-08 Thread auxym
You might like this blog post with other similar patterns:

How to chain anonymous proc with UFCS?

2022-09-30 Thread auxym
pipe is a 7-line macro, moreover it is public domain/unlicense. Copy it into your codebase if you don't want external dependencies? Nim's very powerful macro system exists exactly for this reason: not everything can be included in the language, so macros allow modifying the language as you

How to chain anonymous proc with UFCS?

2022-09-30 Thread auxym
Have you tried this package?

How to properly typecheck a variable number of array args?

2022-09-28 Thread auxym
proc staticLengthCheck[A, B: static[int]](a: array[A, int], b: array[B, int]): array[4, int] = static: assert A + B == 4 discard # do stuff here discard staticLengthCheck([1], [1, 2, 3]) # ok discard staticLengthCheck([1, 2], [1, 2, 3]) # compile time

To `ref` or not to `ref` on embedded?

2022-09-24 Thread auxym
Most people will avoid refs (and dynamic heap usage in general in embedded) because of the associated runtime cost, the difficulty in predicting memory usage on these constrained systems, and the risk of heap fragmentation. That said, use them sparingly if you have to, and you know the limits

Return multiple "flat" nodes from a macro

2022-09-20 Thread auxym
Thanks for the suggestion, I did converge on a [similar solution/workaround](https://github.com/auxym/nim-tinyusb/blob/hid-report-desc/src/tinyusb/class/hid.nim#L748) for my use case.

Return multiple "flat" nodes from a macro

2022-09-19 Thread auxym
This might be entirely misguided as I'm new to writing macros, but, is there a way to return many nodes from a macro, instead of a "tree" with a single root node? For example, consider the following: import std/macros macro manyItems: untyped = newLit(78)

libpe & peni - Portable Executable parsing lib & tool released

2022-09-09 Thread auxym
I'm also not a lawyer, but if you're simply re-implementing APIs, the SCOTUS recently ruled in the famous oracle vs google case that re-implementing java APIs from scratch is not copyright infringement. That's my layman's understanding, at least.

Writing byte array to FileStream - best approaches?

2022-09-06 Thread auxym
looks OK, what you're doing is basically the same implementation as .

Get location of nimcache folder at compile time

2022-09-02 Thread auxym
Old thread but wanted to post a solution because this thread turned up first in my searches. This worked for me: import std/compilesettings const nimcache = querySetting(SingleValueSetting.nimcacheDir) Run

How to have multiple (alternate) return types?

2022-09-02 Thread auxym
Nim does not have "product" types. `(string|int)` is a "typeclass" in nim speak and only used for generics: Nim is statically typed, therefore the return type has to be known at compile-time. Your only choice here is a variant

Hello World with --mm:none and --warningAsError:GcMem

2022-08-30 Thread auxym
Strings in nim are heap-allocated and garbage collected. If you want to declare a string and print it (hello world), you'd have to use a cstring and `{.importc.}` C's printf, or something like that. That said, ARC is a fine recommendation. It produces allocs and frees in the C code at

Recursively replace pair of bytes with one byte, within given byte array

2022-08-23 Thread auxym
This reminds of an AOC problem for last year: IIRC the trick for that one might have been memoization/dynamic programming. You could try that? You can find a bunch of hints and discussion on reddit:

Ideas for useful/cute little GUI programs?

2022-08-20 Thread auxym
Feel like writing a beam solver? Like this? <https://mechanicalc.com/calculators/beam-analysis/> I wrote the actual calculation engine (in nim leveraging arraymancer) but never got around to writing a GUI (or any kind of interface indeed) for it. <https://github.com/auxym/beamdirect>

When do we use pass & return by ref if everything behind the scenes is by-pointer anyway?

2022-08-20 Thread auxym
Ref is useful for "many to one" relationships - many things need a handle to the same piece of data, either to modify it or read it.

Getting compile command in compile time.

2022-08-09 Thread auxym
I'm not sure if you can access all options, but some can be accessed eg. defines: And you can access the `--cpu` and `--os` via `hostCpu` and `hostOs` consts in system.

string of compressed source code

2022-08-01 Thread auxym
If I understand correctly, you would like to include a non-printable byte, like 0x15 (ASCII NAK), in a string literal in source code. If so you can do it using "x" escapes like this: const s = "hello\x15\x2f" Run This does not increases (binary) code size.

Newbie questions about Nim, Python, XCB

2022-03-30 Thread auxym
For wayland, someone hanging out on discord is working on this, though my understanding is that it's a very early WIP:

Newbie questions about Nim, Python, XCB

2022-03-28 Thread auxym
With regards to GUI libraries: my understanding is the gintro, the GTK wrapper, is pretty mature. On the less mature side, but probably still functional, there is wxnim, nimqml and nimx. If you want to call nim code from python, consider using genny:

Very need to understand of locks and condition

2022-03-27 Thread auxym
This SO has decent explanations that differentiate locks (mutex) and condition variables:

How do we preallocate string as element of array as this is..

2022-03-23 Thread auxym
use `newSeqWith` fom the `std/sequtils` package

The dynamical scope of proc

2022-03-06 Thread auxym
I think some example code would greatly help in clarifying your question.

Embedded STM32 - Bare Metal Bootstrap

2022-02-27 Thread auxym
Happy to see more stuff coming out that could bring aware to Nim as a viable tool for embedded software! Personally, video tutorials are not really my thing, but some people do enjoy them. I think most youtubers try to aim for 10-ish minute videos though, maybe cut it up in 2-3 parts next

variable has incomplete type: struct...

2022-02-21 Thread auxym
Are you using `sizeof` somewhere? The one time I had that error, I was using `sizeof` on an importc'd object definition. I fixed it by defining all the fields and annotation the object with `{.completeStruct.}`.

Preallocating multi-dimensioanal sequence i.e. variable size array

2022-02-14 Thread auxym

Can if statements be used as expressions everywhere?

2022-02-12 Thread auxym
Not sure, but it works if you replace "+=" with ".inc". Might be a bug.

To insert regex pattern into another

2022-02-09 Thread auxym
I assume you are using the "regex" nimble package? If so you can assemble the pattern string as you wish (concatenation, using the std/strformat package, etc), then use the "re" function to compile it to a regex object (possibly at compile-time if you pass in a static string):

How to find bottlenecks?

2022-01-28 Thread auxym
Does it work on linux? I read the first line in the readme as implying it _only_ works on windows.

Nim Community Survey 2021

2022-01-17 Thread auxym
Really? What would be replacing untyped then? Explicitly returning NimNode? I can see that working for macros, not sure for templates. I'm not against it btw. Typed and untyped was _very_ confusing for me until I got it, sort of at least.

Nim Community Survey 2021

2022-01-17 Thread auxym
Agreed that a cool embedded project write-up using Nim would be pretty cool. Eg something that could get featured in on HackADay, etc. I think all the pieces are there on the Nim side, between PMunch's Badger (which could be repurposed for another application on AVR aka Arduino), elcritch'd

Advent of Nim 2021

2021-12-04 Thread auxym
Welp, can't help myself even though I have about 1000 other things I should be spending my free time on: <https://github.com/auxym/AdventOfCode/tree/master/2021> 2020 was the first time I finished all days, though a bit late in January. Let's see where it goes this year, but

Readability problems

2021-11-13 Thread auxym
Eh, python did it for urllib. Though python I'd probably a bad model to follow for version transitions.

How to convert hexstring to bytes array?

2021-11-06 Thread auxym
https://play.nim-lang.org/#ix=3Ebk

How to pass a "plain type" to a proc that expects a "ref type" in Nim ?

2021-10-27 Thread auxym
Yes, but keep in mind that Nim may pass references internally in some cases, even if your type is a value type. For example "var" arguments in prices are passed as reference (internally, as an implementation detail) so that it can be mutated. Non-var arguments may also be passed as a reference

More Nim on more Microcontrollers!? (Arm CMSIS / Zephyr RTOS)

2021-10-23 Thread auxym
> Would you be interested in moving the CMSIS library to EmbeddedNim? We can > keep it somewhat updated there, and perhaps inspire others to contribute. Definitely! I think I need permissions to create repositories in nim-embedded in order to do the transfer however? Or just let me know if

More Nim on more Microcontrollers!? (Arm CMSIS / Zephyr RTOS)

2021-10-04 Thread auxym
TBH this whole libc and syscalls is pretty new to me and was a bit of a headache! It's something you never really have to worry about for non-embedded programming. So yes, I'm linking against Newlib, which is the default for `arm-none-eabi-gcc`. More precisely, newlib-nano (via

More Nim on more Microcontrollers!? (Arm CMSIS / Zephyr RTOS)

2021-10-03 Thread auxym
So I have a "blinky" demo (the "hello world" of embedded?) up and running on github, which I've tested on an Adafruit Feather M0 board: <https://github.com/auxym/nim-on-samd21> The [DFLL clock initialization code](https://github.co

Nim 1.6.0 RC2

2021-10-02 Thread auxym
Pretty sure we all are! The people who aren't is corporate/university IT. Good news for the signed binaries!

Thoughts on pure Nim api for SPI & I2C device access?

2021-09-24 Thread auxym
> I'm not sure how easy it'd be to create const's that you could ensure were > valid C structs. My understanding is that nim objects map 1:1 to C structs. c2nim always add the `{.bycopy.}` pragma, but I'm not sure why that's required. However, I also just learned that you can't create a

Futhark: Automatic C imports in Nim using libclang

2021-09-23 Thread auxym
Maybe I'm not using it right (documentation is a bit sparse unfortunately), but I'd like to note that I haven't had much success running c2nim on headers that are heavy on preprocessor macros, either.

Thoughts on pure Nim api for SPI & I2C device access?

2021-09-21 Thread auxym
Shouldn't be a problem to create a `const` object that contains information about the registers or file-like objects (for Linux) relevant to the specific bus. Then `init` can do some some work on those registers/file-like objects. Some devices have configurable sercoms

config files: Nimscript and Nim compiler documentation inconsistency

2021-09-18 Thread auxym
Does config.nims have a mechanism for defining cross-compiling toolchains? Eg the `arm.linux.gcc.exe` as defined here:

More Nim on more Microcontrollers!? (Arm CMSIS / Zephyr RTOS)

2021-09-14 Thread auxym
I did not, but @haxscramper mentioned it over discord. Thanks for confirming it though, seems like the way to go!

More Nim on more Microcontrollers!? (Arm CMSIS / Zephyr RTOS)

2021-09-13 Thread auxym
> That sounds like a good call. For the Nim/C struct mismatch are you mainly > talking about bitfield's or field access? I'm doing a lot C struct wrapping > so it'd be really helpful to know where the overlaps break down. The two things I hit that made me reconsider a C-copycat API: 1\.

More Nim on more Microcontrollers!? (Arm CMSIS / Zephyr RTOS)

2021-09-12 Thread auxym
Very cool for Zephyr, I've been interested in checking it out since I heard one of the devs on the Embedded.fm podcast. > Interesting, did you go with the C-struct model or use the setter/getter > pattern you discussed before? Setters/getters. For a few reasons. (1) C doesn't map closely

More Nim on more Microcontrollers!? (Arm CMSIS / Zephyr RTOS)

2021-09-11 Thread auxym
Hi everyone :) My evenings for the past couple weeks were spent (re)writing this: <https://github.com/auxym/svd2nim> It seems to be working, I have a test that checks all register addresses against those in a reference C header (generated by ARM's tool, SVDConv). The API is de

String expression parsing

2021-08-26 Thread auxym
FWIW, a good resource for writing a relatively simple tokenizer and recursive descent parser from scratch is / I used to to write a parser for arithmetic expressions in last year's Advent of Code, which was massive overkill but interesting.

How to make Nim more popular

2021-08-25 Thread auxym
Not convinced, unfortunately not a lot of people write native desktop GUIs nowadays.

  1   2   >