Re: Code substitution with templates

2017-09-25 Thread dataPulverizer
@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

Re: Code substitution with templates

2017-09-25 Thread stisa
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.

Re: Code substitution with templates

2017-09-25 Thread Udiknedormin
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

Code substitution with templates

2017-09-25 Thread dataPulverizer
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

Re: Error: invalid indentation

2017-09-25 Thread dataPulverizer
@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

perfomance of set/hashset operation between python and nim

2017-09-25 Thread jil210
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:

Re: Date time with millisecond output?

2017-09-25 Thread blip
> 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

Re: Error: invalid indentation

2017-09-25 Thread mratsim
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

Re: Error: invalid indentation

2017-09-25 Thread LeuGim
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

Re: Date time with millisecond output?

2017-09-25 Thread Libman
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 =

Re: Nim and hot loading - any experiences to share?

2017-09-25 Thread Serenitor
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.

Re: Error: cannot instantiate: 'OrderedTable'

2017-09-25 Thread sflennik
Thank you, that helps. I'm now looking at the json module.

Re: Nimscript: setLen segfaults?

2017-09-25 Thread Udiknedormin
@cdome It wasn't a nil in this case.

Re: Get a constant passed to a macro call

2017-09-25 Thread Udiknedormin
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

Re: Error: cannot instantiate: 'OrderedTable'

2017-09-25 Thread Tiberium
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":

Error: cannot instantiate: 'OrderedTable'

2017-09-25 Thread sflennik
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,