@Udiknedormin many thanks for the thorough explanation and for your correction
of age from string - silly error on my part.
@stisa thanks for the heads up on dirty templates
I guess the way to generate types using templates is to insert code into a
template type structure rather than inserting
You can also mark the whole template with `{.dirty.}`
template someCode(): untyped {.dirty.}=
var
fname: string = "Mark"
age: int = 44
someCode()
echo fname # "Mark"
echo age # 44 Notice both symbols are visible outside the template.
First code:
Let's start with why any of this template's instantiation won't compile --- it
has a type error. "44" is a string but you assign it to an int variable. In
fact, Nim's type inference makes it redundant for you to specify these
variables' types.
Secondly: templates provide something
I'm trying to use templates to paste code:
template someCode(): untyped =
var
fname: string = "Mark"
age: int = "44"
someCode()
echo fname
The above code does not recognise the var declarations and the code below
doesn't run either
@LeuGim - thanks for the clarification
@mratsim I didn't know about SomeReal thanks for pointing that out.
> By the way, I don't really understand your need but you can usually go very
> far in Nim with just generics and overloading without to implement class-like
> types.
>
> If you need
Hi, I have mydiff.py to compare two files using two sets. my python version is
as follows but nim version takes five times longer. Can anyone explain the
performance difference or give me a better nim code [I am comparing about two
million lines of files:
> Strange that I can't find a Nim implementation of strftime, which has %f for
> microseconds
Yes, this is exactly what I was looking for and what I successfully used in
Python (I've got something similar working in Rust as well). For the
milliseconds() proc in the times docs it is
Nitpicking but just use the
[SomeReal](https://nim-lang.org/docs/system.html#SomeReal) typeclass instead of
this line:
floatingPoint = float | float64 | float32
By the way, I don't really understand your need but you can usually go very far
in Nim with just generics and
Yes, `object` is a value, `ptr object` is a non-garbage-collected pointer to an
object, `ref object` is a garbage-collected pointer to an object, `object of
...` is the way to inherit, to be combined with any of the previous, and after
any of that a list of fields may go.
`RootObj` is not smth
Probably not the prettiest way to do this, but here's a thought:
import times, strutils
let
startEpochTime = epochTime()
startEpochSec = ($startEpochTime).split(".")[^1]
startTimeInfo = getLocalTime(fromSeconds(startEpochTime))
startTimeStr =
Hey def_pri_pub, yes, I know your article. It's been a great help to get
started, thanks for that!
When I first tried to implement hot loading in Nim a couple of months ago I
based it on your article, however, I decided to not use threading and not to
call the compiler from within the script.
Thank you, that helps. I'm now looking at the json module.
@cdome It wasn't a nil in this case.
Well, I tried symbol.getImpl and it handles some cases but the problem is that
I need to be able to dispatch a certain proc for the const's type and then
apply this proc to this const, all of this at compile-time. Unluckily,
symbol.getImpl doesn't allow me to do that (at least I haven't figured
sflennik: your code is wrong, OrderedTable can't contain different types It
should be like this:
from tables import OrderedTable, toOrderedTable
proc getMetaInfo(filename: string, fileSize: int64): OrderedTable[string,
string] =
result = {
"filename":
I get a compiler error for the following code. Anyone know what I am doing
wrong?
from tables import OrderedTable, toOrderedTable
proc getMetaInfo(filename: string, fileSize: int64): OrderedTable =
result = {
"filename": filename,
"size": fileSize,
16 matches
Mail list logo