Introspection over a proc type

2022-04-25 Thread krakengore
This will return a NimNode, i was trying to have getReturnType to return the `typedesc` instead

Brogrammer uptick

2022-04-25 Thread PMunch
Might be that Nim is starting to become more used in America. The Nim userbase has historically shifted quite heavily towards Europe, but some Asian and American users. The Asian userbase has increased quite a bit, but we don't see them much around here, probably because of language barriers. Bu

Datetime parse format for round-trip "O"

2022-04-25 Thread treeform
Seconds fractions are not commonly supported or found in the wild, but you can still parse them with my calendar/timestamp/timezone library: github: docs: import chrono

Introspection over a proc type

2022-04-25 Thread ynfle
import std/macros func f(x: int): seq[string] = discard macro getReturnType(x: proc): untyped = x.getimpl.params[0] echo getReturnType(f) echo default(getReturnType(f)) & "monkeys" Run

Datetime parse format for round-trip "O"

2022-04-25 Thread enthus1ast
It seems this pattern is not yet supported. (While googling the "fffK" pattern i found this informative gist: maybe someone will pr times.nim someday.)

Binding a closure to a std::function to call it from C++... safe to do ?

2022-04-25 Thread krakengore
If you try this example, it fails to compile, for some reason nim is not able to deduce the correct type of the passed procedure to `bindNimClosure` unless i fully specify the generics. This doesn't work: var myclos = bindNimClosure(my) myc

Introspection over a proc type

2022-04-25 Thread krakengore
How can i introspect a proc symbol passed to a template / macro ? I would like to extract the return type (i've tried `typeof(proc())` but requires that i pass the correct number of arguments) and the arguments types, but couldn't figure it out after looking at std/typetraits.

How to iterate a slice of children of a NimNode ?

2022-04-25 Thread krakengore
awesome thanks !

Seeking advices for a C programming book

2022-04-25 Thread Sixte
> Indeed, Ada generics suffer from this deficiency as well. It was an important > factor in my decision to stop using Ada, even though I liked many other > aspects of it. If you have module-wide types, you might be tempted to instantiate or over-instantiate them. Both Ada and Modula-3 allow thi

Seeking advices for a C programming book

2022-04-25 Thread Sixte
I can offer you another language comparison: Oberon-2, Modula-3, Sather and Self with focus on "object orientation". It is particularly because of the asterisk "*" annotation that you can find both in Oberon and in Nim. [https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.14.6912&rep=rep1&

Seeking advices for a C programming book

2022-04-25 Thread bpr
> And that makes it inferior to C++'s template mechanism. Yes, it really does > and explicit instantiation is unheard of in Java, C#, Scala... for this > reason. Indeed, Ada generics suffer from this deficiency as well. It was an important factor in my decision to stop using Ada, even though I

Datetime parse format for round-trip "O"

2022-04-25 Thread jmgomez
Hey guys, What would be the date format for the round trip O in nim? () So I can do let date = parse ("2022-04-25T13:03:28.8936219Z", ???, utc())

How to iterate a slice of children of a NimNode ?

2022-04-25 Thread PMunch
Correct, children is an [iterator](https://nim-lang.org/docs/macros.html#children.i%2CNimNode) so you can't slice it. When you do `for child in body[1 .. ^1]:` you're basically taking the sequence of Nim nodes, creating a new sequence of Nim nodes containing only the slice, and then calling the

Binding a closure to a std::function to call it from C++... safe to do ?

2022-04-25 Thread krakengore
I now realised that nimcall calling convention only allows to capture the global scope. So i might still need to revert back to rawProc and rawEnv

How to iterate a slice of children of a NimNode ?

2022-04-25 Thread krakengore
Oh yes, it seems to work when importing macros indeed. Side question, is this not working because .children is a function call returning some kind of iterator right ? for child in body.children[1 .. ^1]: Run

How to iterate a slice of children of a NimNode ?

2022-04-25 Thread Yardanico
Oh, I assumed that the code already imported macros and that slicing wasn't available :)

How to iterate a slice of children of a NimNode ?

2022-04-25 Thread PMunch
The easiest way to do it is to import the `macros` module which includes the slice operator for the `NimNode` type: import macros macro xyz(body: untyped): untyped = for child in body[1 .. ^1]: echo child.astGenRepr xyz: var q = 1 var p = 2

How to iterate a slice of children of a NimNode ?

2022-04-25 Thread Yardanico
One way is to capture all elements into a sequence and then iterate over it: import std/[macros, sequtils] macro xyz(body: untyped): untyped = let children = toSeq(body.items()) for child in children[1 .. ^1]: echo child.astGenRepr xyz:

How to iterate a slice of children of a NimNode ?

2022-04-25 Thread krakengore
I'm trying to iterate only a slice of the children of a NimNode, but i'm not able to find a way to do it macro xyz(body: untyped): untyped = for child in body[1 .. ^1]: echo child.astGenRepr xyz: var q = 1 var p = 2 var r = 3

Seeking advices for a C programming book

2022-04-25 Thread Araq
As I said, the version of Modula 3 that I looked at had no "GENERIC INTERFACE". Or maybe I misremember. Regardless of the history the design requires explicit instantiation via MODULE Integer; TYPE T = INTEGER; END; MODULE IntStack = Stack(Integer) END; Run And th