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
its very complex ;) _just thought that there is an easier solution._
I guess that is an old isseu, see
[https://forum.nim-lang.org/t/3877#24115](https://forum.nim-lang.org/t/3877#24115)
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.
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*:
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.
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
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
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
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
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...
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?
Use `method` for this with a declaration like `method draw(w: Widget) =
assert(false, "to override")`
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.
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
I feel honored receiving a reply from the maestro himself!
Example
import os
echo "tired"
sleep(3000)
echo "still tired, and maybe fooled?"
Run
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)
Hmm, strange. My CPU load is 100% during the benchmark, almost constantly (with
tiny fluctuations to 99%).
19 matches
Mail list logo