Re: How to determine the type of an object

2019-03-23 Thread Stefan_Salewski
We have "is" and "of" in Nim for static and dynamic type tests. Note that your custom names "String" and "Integer" may be a bit confusing, as people unfamiliar with Nim may guess that that are basic Nim types. This code works for me: import strutils, typetraits, unicode

Re: sleep function?

2019-03-23 Thread minimisthupper
its very complex ;) _just thought that there is an easier solution._

Re: Problem with export marker and macros

2019-03-23 Thread Stefan_Salewski
I guess that is an old isseu, see [https://forum.nim-lang.org/t/3877#24115](https://forum.nim-lang.org/t/3877#24115)

Re: How to determine the type of an object

2019-03-23 Thread Stefan_Salewski
That was already included in my example, but with () notation: echo name(type(x)) Run Seems that import typetraits is not necessary for latest Nim compiler.

Problem with export marker and macros

2019-03-23 Thread b3liever
Hi, one of my most common struggles when writing macros, is that it is not easy to compose the export marker `*` in my macro's syntax. For example: activations: act sigmoid*: fn: 1 / (1 + exp(-x)) deriv: fx * (1 - fx) act tanh*:

Re: How to determine the type of an object

2019-03-23 Thread mratsim
Name is used like this: import typetraits let x = 1 echo x.type.name Run Notice the `type` proc that returns the type from a variable.

Re: Problem with export marker and macros

2019-03-23 Thread mratsim
Seems like neural net functions that should produce proc sigmoid*[T: SomeFloat](x: SomeFloat): SomeFloat = 1 / (1 + exp(-x)) proc sigmoid_deriv*[T: SomeFloat](fx: SomeFloat): SomeFloat = fx * (1 - fx) Run

A little problem with inheritance

2019-03-23 Thread Skaruts
I'm making a few ui widgets for a terminal emulation thingy I'm doing (for a roguelike), and I'm trying to do some inheritance. But I'm having a bit of a problem. So far I got what you see in the code right below: a Widget base class, a Label sub-object of Widget, and a Ui object that creates

Re: Problem with export marker and macros

2019-03-23 Thread Araq
I don't know what `act sigmoid*:` would produce. That means you can make export the default and use `pact sigmoid` for private acts. Or you use `act sigmoid {.public/private.}`. Usually I design the DSL so that this problem doesn't even come up but I don't know how I would do it in your case

Re: How to determine the type of an object

2019-03-23 Thread drifter
Stefan, "is" is what I was looking for!. My use case is not very complicated as I'm just trying trying to learn by experimenting. The code was just an example. I have some ideas on a project I want to make using nim, for example a translator that converts a markup to groff code. The idea

Re: Problem with export marker and macros

2019-03-23 Thread b3liever
Searching, I found this interesting discussion in the irc: [https://irclogs.nim-lang.org/09-10-2018.html#16:05:28](https://irclogs.nim-lang.org/09-10-2018.html#16:05:28) But I guess at this point, a change like that isn't possible...

Re: Problem with export marker and macros

2019-03-23 Thread b3liever
This one is just a let sigmoid = ActivationFuntion(fn: ..., deriv: ...) so it just exports the variable. Also I have an interface [macro]([https://github.com/b3liever/protocoled](https://github.com/b3liever/protocoled)) with same syntax. I'm curious how would you design the last one?

Re: A little problem with inheritance

2019-03-23 Thread Araq
Use `method` for this with a declaration like `method draw(w: Widget) = assert(false, "to override")`

Re: How to determine the type of an object

2019-03-23 Thread Araq
Instead you should use `case` statements or some Nimble package for pattern matching. Dynamic dispatch is inferior by pretty much every objective criterion I can come up with, harder to analyse, slower, more code to write, doesn't work for nested patterns.

Re: A little problem with inheritance

2019-03-23 Thread Skaruts
Thanks. That worked. The compiler told me to use {.base.} too. Should I use method on all procs that are specific to types, though? I switched them all to `method`, but then the compiler told me to use {.base.} on all of them, but some procs aren't supposed to have a base method in Widget, as

Re: How to determine the type of an object

2019-03-23 Thread drifter
I feel honored receiving a reply from the maestro himself!

Re: sleep function?

2019-03-23 Thread Stefan_Salewski
Example import os echo "tired" sleep(3000) echo "still tired, and maybe fooled?" Run

Re: [Beginner] CLI Utility that continuously reads keyboard input; threads or no threads?

2019-03-23 Thread shashlick
Async != threads. readInput() will block regardless. You will need to use kbhit() equivalent code. I did something similar in my CLI editor. Check it out, hope it helps. [https://github.com/genotrance/snip](https://github.com/genotrance/snip)

Re: pibench2 – A multi-threaded performance benchmark written in Nim

2019-03-23 Thread lqdev
Hmm, strange. My CPU load is 100% during the benchmark, almost constantly (with tiny fluctuations to 99%).