Can Nim do Type States?

2023-03-09 Thread Araq
> My line of work prohibits metaprogramming. That's crazy. Like a mathematician who is prohibited from using integrals. ;-)

Can Nim do Type States?

2023-03-09 Thread dwhall256
Thank you for more great feedback. I see you've used options to reduce the number of hand-made type states. Compelling idea. I also see your use of bool and enum in the types; is that still zero-cost (no additional size for the object)? Also, I'm a little perplexed about the last three lines in

Can Nim do Type States?

2023-03-09 Thread dwhall256
Thank you for Nim and thank you for this tip; it helped improve my understanding of generics. My line of work prohibits metaprogramming. So I'm not headed in that direction, but I take your point. For now, I want to see if this style of Type States will cause any unwanted side effects (like code

{.nodecl} VS {.importc, nodecl} and return VS result

2023-03-09 Thread sls1005
That's one of the workarounds. Another is to make it a fake glabol, thus `{.nodecl.}` applies. proc main = {.emit: "int x = 1;".} var x {.importc, global, nodecl.}: cint echo x main() Run

Can Nim do Type States?

2023-03-09 Thread huantian
Something like this might also be similar to what you want, not exactly the same as the Rust though. This approach does work in Nim like Araq said, but you also have the additional flexibility of considering using a DSL for your API instead, it might be more ergonomic. import std/[

Can Nim do Type States?

2023-03-09 Thread Araq
Your gist does not contain enough but I managed to correct the first proc for you: type Peripheral* = ref object of RootObj GPIO* = ref object of Peripheral GpioConfig*[Tenable, Tdirection, Tmode] = object periph: GPIO # no need to have fields of generic par

Macros and interfacing with the world ?

2023-03-09 Thread sls1005
You mean to use Python at compile-time? macro example() = echo(staticExec "python -c 'print(123)'") Run

Can Nim do Type States?

2023-03-09 Thread huantian
Saw this concept in a youtube video at some point, I think Nim should be able to do this quite easily with generics. I'll whip up an example in Nim

why use nim over c#?

2023-03-09 Thread LokeX
How about Nim in Unreal engine - I'd say that counts for a plus...

Can Nim do Type States?

2023-03-09 Thread dwhall256
I'm an embedded developer 2 weeks into learning nim and I'm trying to see if Nim's type system can approach the "Type States" described in in [Chap 4 of The Embedded Rust Book](https://docs.rust-embedded.org/book/static-guarantees/index.html) (esp [section 4.4](https://docs.rust-embedded.org/b

why use nim over c#?

2023-03-09 Thread Lite3000
Personally I got a time of 2 milliseconds in Nim where the test timed out in this benchmark. I wouldn't trust those benchmarks. Looks like there's a saboteur afoot.

{.nodecl} VS {.importc, nodecl} and return VS result

2023-03-09 Thread shirleyquirk
No, of course destructor, yes. > sorry for conflating my experiment with this post's question, which was, how > do you `nodecl` a variable. My experiment was exploring whether theres a way to supply a `finally` block when unwrapping a `Result`

Macros and interfacing with the world ?

2023-03-09 Thread nimnam
Sometimes I am just to lazy to do my work thus macros could be doing them. Examples: Get version from git repository and add it in version Use maxima/Python's math libraries to solve equations and turn the result into code like Now

nimqt - bindings to Qt

2023-03-09 Thread gareth60
Issue created :-)

{.nodecl} VS {.importc, nodecl} and return VS result

2023-03-09 Thread Araq
What's the point of the hack? Feel free to use a destructor instead.

{.nodecl} VS {.importc, nodecl} and return VS result

2023-03-09 Thread shirleyquirk
The hack I've found to do this: proc foo() = proc cleanup(p:pointer){.used.} = echo "cleanup" var x {.codeGenDecl:"",nodecl,noinit.}: seq[int] {.emit:[typeof(x)," ",x," __attribute__((cleanup(",cleanup,"))) =",@[5],";"].} echo x foo()

Nim enters top 50 programming languages list on TIOBE Index!

2023-03-09 Thread alexeypetrushin
They will consider Nim if it would be possible to make more money with Nim than with LangX.