Using Concepts for abstracting display graphics

2023-10-17 Thread KerryC
I have wondered about this myself.

how to convert epoch (in milliseconds) to human time ?

2022-10-24 Thread KerryC
If all you need is local or UTC then you can do something like this. import std/times var t = fromUnix(convert(Milliseconds, Seconds, 1628231654073)) echo t echo t.utc() Run The docs for `times` are [here](https://nim-lang.org/docs/times.html) .

Introducing PhylogeNi and BioSeq

2022-10-13 Thread KerryC
I would like to bring some attention to two projects that I have been working on. [PhylogeNi](https://github.com/kerrycobb/PhylogeNi) \- A library for working with phylogenetic trees (evolutionary trees). [BioSeq](https://github.com/kerrycobb/BioSeq) \- A library for working with biological se

One lookup table indexed by multiple enums

2022-09-13 Thread KerryC
Ah great! That is actually what I was trying to do before stripping things down to a minimal example but I failed to realize that I needed the `ord` in order for `enm` to work as an index. Thanks a lot!

One lookup table indexed by multiple enums

2022-09-13 Thread KerryC
I have some enum types which I am using to access values from lookup tables. I thought for instances where the values would be the same for each enum that I might be able to do this: type aEnum = enum A1, A2, A3 bEnum = enum B1, B2, B3 eitherEnum = aEnum | bEnum

Mastering Nim: A complete guide to the programming language

2022-09-08 Thread KerryC
For those deterred by the price or opposed to personal ownership of physical books, consider placing a request with your local library to purchase a copy. In my experience they are quite happy to fulfill such requests. And they would have no way to know if you had already purchased a copy ;)

Define proc that is called from imported module

2022-03-31 Thread KerryC
Great! Thank you! I thought mixin was how to go about this. It wasn't clear to me from the manual how I should apply it.

Define proc that is called from imported module

2022-03-31 Thread KerryC
Is there a way to define a proc inside a file that is called from an imported module. My idea is that I will have a library for doing common operations on an object that has a generic type associated with it. Then a user could define a desired behavior for some custom type that is triggered duri

String formatting a number with Javascript backend

2021-07-26 Thread KerryC
Thank you for your reply! I'm still confused though. I can do this and `strformat` seems to have no issue with `cstring` import jsffi, strformat, jsconsole var obj = JsObject{field: "1".cstring} s = obj.field.to(cstring) var f = fmt"{s} is a string".cst

String formatting a number with Javascript backend

2021-07-26 Thread KerryC
I've encountered an error when trying to use `strformat` with a number in the Javascript backend. It's not a show stopper as there is another way. But it is really bugging me that I don't understand why I am encountering a problem and I would prefer to use the `strformat` approach. If I have th

Use break statement inside of called proc

2021-06-22 Thread KerryC
I should have remembered that I could just do something like this: proc foo(bar: var bool) = bar = false var bar = true while bar: foo(bar) Run Thanks for the comments!

Use break statement inside of called proc

2021-06-22 Thread KerryC
Is there a way to break out of a named block from a proc called within that block. I want to make some code a bit more readable by doing something like: proc foo() = break outer block outer: while true: foo() Run I cant't figure out how t

How to wrap JavaScript library

2020-08-29 Thread KerryC
I am struggling with wrapping some parts of a JavaScript library in order to use it with the JavaScript backend in Nim. Examples that I have found don't seem to match my scenario. Is this bit of JavaScript code clear enough that someone could get me started in the right direction? I first set a

Inheriting from a type containing instances of itself

2020-07-22 Thread KerryC
It doesn't seem to me that it is just a limitation of echo. This fails with Error: attempting to call undeclared routine: 'ext=': n0.children[0].ext = true Run Whereas this works: ExtNode(n0.children[0]).ext = true echo n1[] Run Outpu

Inheriting from a type containing instances of itself

2020-07-21 Thread KerryC
I have a type which contains instances of itself. I would like to inherit from this type but when I try to access the contained instances, it seems that the subtype is changed to the parent type.. The code below yields (children: ...) instead of (ext: false, children: ...) as I had hoped. Is th