Re: newb saying Hi

2017-09-26 Thread Arrrrrrrrr
Check out nim's irc channel, that's where the real hacks and tricks are discussed.

Re: Code substitution with templates

2017-09-26 Thread Arrrrrrrrr
If you only need one extra field, you could write the template like this: template typeGen(tName, name, kind: untyped): untyped = type tName {.inject.} = object fname: string age: int name: kind typeGen(Employee, id, int)

Re: Code substitution with templates

2017-09-26 Thread Udiknedormin
@LeuGim That's bad. I'm using Nim 1.17.2 so it seems to imply the bug was created between 1.17.1 and 1.17.2, I guess...

Re: Code substitution with templates

2017-09-26 Thread slimshady
@Lando: Good point! thanks

Re: Execution speed Nim vs. Python

2017-09-26 Thread jil210
Please help speedup with the following nim code taking five times longer than python version: import os, sets, strutils if paramCount() != 2: echo "mydiff file1 file2" quit() let file1 = open(paramStr(1)) let file2 = open(paramStr(2)) let old_lines = file1.readAll().splitLines() let

Re: Code substitution with templates

2017-09-26 Thread Lando
> Your syntax for macro's call is OK Exactly. @slimshady, @dataPulverizer: General tip: if a macro call is passed to _dumpTree_ as a block argument and that compiles and prints the call as a (pre-symbol-binding) AST, then the call syntax is ok: import macros dumpTree:

Re: newb saying Hi

2017-09-26 Thread cdome
Welcome!

Re: Are array types that differ only in index boundaries different?

2017-09-26 Thread Tiberium
LeuGim: a side note: it's not an implicit conversion, with "var x: int8" Nim treats your "3" literal as "int8" type

Re: Are array types that differ only in index boundaries different?

2017-09-26 Thread LeuGim
Regarding assignment, it doesn't have to depend on types being indistinguishable. E.g.: proc p(x: int) = echo "int" proc p(x: int8) = echo "int8" var x: int8 x=3 # implicit conversion p x # int8 p 3 # int overloading works here, while allowing literal's

Re: Are array types that differ only in index boundaries different?

2017-09-26 Thread LeuGim
You can try to search forum for if there were previous discussions... Just > the situation when you can declare something that you cannot later call seems to be not intended.

Re: Are array types that differ only in index boundaries different?

2017-09-26 Thread olwi
I can definitely report this on Github, but before doing this I'd like to better understand this inconsistency. It seems that for array initialization to work as expected, array types that differ only in index boundaries should be treated as equal. Otherwise this: var b: array[-1

Re: Code substitution with templates

2017-09-26 Thread LeuGim
Your syntax for macro's call is OK, your key-value pair is parsed as a call (`id` being regarded as a proc name, and `int` as statement list (block), passed to it). Now you need to write a macro, that can use it. In that macro you first assign to `result` the constant part of your type, and

Re: Are array types that differ only in index boundaries different?

2017-09-26 Thread LeuGim
Report it as a bug on Github, if it's not there already, it's an old issue.

Re: Code substitution with templates

2017-09-26 Thread dataPulverizer
> No, parser cannot understand `extraCode` in an object declaration, in the > template, which is there an invalid syntax. I would like to substitute `id: int` for extra code in the template by doing: typeGen(Employee): id: int I thought (incorrectly) that this is how

Are array types that differ only in index boundaries different?

2017-09-26 Thread olwi
Two arrays of the same size and element type but with different index boundaries seem to be distinct types for the purpose of (polymorphic) proc definitions, so this compiles: proc p(a: array[10, int]) = discard proc p(a: array[-1 .. 8, int]) = discard but they seem to

Re: Code substitution with templates

2017-09-26 Thread LeuGim
No, parser cannot understand `extraCode` in an object declaration, in the template, which is there an invalid syntax. @Udiknedormin, concerning Error: cannot use symbol of kind 'var' as a 'field': that should be a bug, but I don't see such a behaviour with Nim 0.17.1.

newb saying Hi

2017-09-26 Thread andre1sk
Hey guys. Just learned about nim a few days ago from HN the lang. looks amazing so hope I will get up to speed quickly and can be of help to the Nim community.

Re: Code substitution with templates

2017-09-26 Thread slimshady
@dataPulverizer I think typeGen(Employee): id: int is invalid syntax. You cant declare variables like id:int and templates expect valid nim code.