Re: What are you writing using nim? :)

2017-08-28 Thread Udiknedormin
Unluckily, I can't replace Python with Nim as I need some science libraries not yet available in Nim (maybe I'll port them another day...). While my friend uses Nim for similar things, I chose Rust for my thesis and I had some good reasons: * when I started it, Nim lacked advanced generics it

Compile Time Evaluation of Constants From C-Header Files

2017-08-28 Thread ivanitto
Is there a way to make nim compiler to evaluate constants from C-header files at compile time? For example, symbols S_IFREG and S_IFDIR (from posix.nim <\- sys/stat.h) used in following code snippet: case x: of S_IFREG: echo "file" of S_IFDIR: echo "dir" else:

Re: Been away for 9 months. What changed? Need some help to get back on track.

2017-08-28 Thread Libman
> I've been away from Nim for about 9 months. Can anyone give me a quick update > ... We keep [accelerating toward C](https://www.quora.com/Which-language-has-the-brightest-future-in-replacement-of-C-between-D-Go-and-Rust-And-Why), but v1.0 [remains elusive](https://en.wikipedia.org/wiki/Time_d

Re: Editor profiles fo Nim

2017-08-28 Thread Libman
As far as I know, the most advanced Nim development environment so far is [VSCode](https://en.wikipedia.org/wiki/Visual_Studio_Code) \+ [this](https://github.com/pragmagic/vscode-nim) [extension](https://marketplace.visualstudio.com/items?itemName=kosz78.nim). Someone please correct me if I'm w

GetType() for object type macro parameter

2017-08-28 Thread Stefan_Salewski
import macros type S = string I = int O = object i: int P = ref O var i: I var s: S var p: P var o: O macro mconnect(arg: typed): typed = let at = getType(arg) echo $(at.toStrLit) if at.len > 1: ec

Re: Export docs? Submodules?

2017-08-28 Thread Udiknedormin
More precisely: for exported entities. Meaning: # foo.nim const sth* = 5 const oth = 4 # bar.nim from foo import sth export sth bar.nim docs should include sth but not oth. Also, it should be explicitly marked as exported in the docs unless foo.nim is p

Re: optional int parameters for a proc

2017-08-28 Thread Udiknedormin
Overloading has one major disadvantage: proc hasTwoIntArgs(x = 3, y = 4) = ... hasTwoIntArgs(x = -1) # args: x = -1, y = 4 hasTwoIntArgs(y = -1) # args: x = 3, y = -1 proc hasTwoIntArgsInvalid(x, y) = ... proc hasTwoIntArgsInvalid(x) = hasTwoIntArgsInvali

Re: Question regarding the setter method/proc

2017-08-28 Thread Udiknedormin
It seems to me it would be better to not allow a getter/setter to be named just like a private field. It's quite misleading.

Re: Defining an array inside a tuple

2017-08-28 Thread Udiknedormin
Wow! I'm really lucky as far as finding bizzare language subtelties or compiler bugs but... I've actually encountered this behaviour before. I guess I just assumed you can use constructor syntax with any type. @rayman22201 array is pretty much std::array and seq is pretty much std::vector. I t

Re: Bug with generic methods?

2017-08-28 Thread Udiknedormin
Not quite. The type of a variable in your code is indeed Console but the type of b is ViewportConsole. It's a subtle difference: in the seq exemple it's a variable of a type Console which stores a value of ViewportConsole. The difference is: # in seq example: consoles[0] of Co

Re: Simple Python-like class macro and some python-like procedures (print, input, range, others)

2017-08-28 Thread Udiknedormin
@dom96 I am quite sure that when I was writing some macros in Nim some time ago, it was clearly stated somewhere that doc-comments cannot be read from (or created as) AST.

Re: Nim - nimble, nake, confused

2017-08-28 Thread jacmoe
> That is precisely what's happening Excellent! I'll carry on with Nimble, then

Re: Nim - nimble, nake, confused

2017-08-28 Thread dom96
> and it looks like that Nimble is slowly obsoleting Nake by incorporating most > (all?) of Nake's features That is precisely what's happening You should be able to use Nimble for most use cases nowadays.

Re: Bug with generic methods?

2017-08-28 Thread Lando
@def: still seems that the sequence plays a role in a way I don't quite understand here, because this works as intended: type Console* = ref object of RootObj ViewportConsole* = ref object of Console method draw*[T](self: Console, engine: T) {.base.} =

Re: Defining an array inside a tuple

2017-08-28 Thread rayman22201
Thank you for your help everyone. @BigEpsilon: I understand the difference seq vs array. An array is a fixed size from compile time (a C array with the size information stored in the type system), and a seq is closer to a std::vector in C++. My question is about setting the default values of t

Re: Nim - nimble, nake, confused

2017-08-28 Thread jacmoe
Thanks, Andrea, for confirming my thinking. To me, it makes a lot of sense to let a package manager handle builds, versions and dependencies, and it looks like that Nimble is slowly obsoleting Nake by incorporating most (all?) of Nake's features. At the very least it can explain the overlap bet

Re: Nim - nimble, nake, confused

2017-08-28 Thread andrea
Notice that nimble now supports tasks, which are custom command, scriptable with nimscript. This should be extensible enough to cover your needs. Nake is a build tool - I have never used it, since I find that build tools need to be coupled to a package manager to be useful - there is no way to b

Re: Nim - nimble, nake, confused

2017-08-28 Thread jacmoe
> will compile not only your_program.nim, but also all imported modules > recursively and build the final complete executable, so most of time you need > just the compiler to build your project. That is true, and also how I started out - mainly due to the fact that the Nim tutorial does not men

Re: Been away for 9 months. What changed? Need some help to get back on track.

2017-08-28 Thread jlp765
Yeah, I guess I assumed a blog was stories rather than news announcements. Other (younger) people probably would not have made that assumption.

Re: Question regarding the setter method/proc

2017-08-28 Thread pgmf
Thanks again @Lando for confirming this. It more clear to me now. Best Regards

Re: Bug with generic methods?

2017-08-28 Thread def
That's obviously supposed to work and it's a bug when using methods in combination with generics. Without generics it works fine: type Console* = ref object of RootObj ViewportConsole* = ref object of Console method draw*(self: Console, engine: string) =

Re: Bug with generic methods?

2017-08-28 Thread Lando
Probably an [object variant](https://nim-lang.org/docs/manual.html#types-object-variants). Or maybe wait until concepts are implemented.

Re: Bug with generic methods?

2017-08-28 Thread 10c8
Is there a way to get my expected behavior while keeping all the Consoles in a single sequence?

Re: Bug with generic methods?

2017-08-28 Thread Lando
That's because of the sequence. If you would store the objects in two separate sequences for _Console_ and _ViewportConsole_ instead, you would get the expected result. Apparently, _var consoles: seq[Console]_ sets the runtime type of the elements to **exactly** _Console_.

Re: Question regarding the setter method/proc

2017-08-28 Thread Lando
Correct. This is why the name of the field was changed to something other than _host_ in the updated example code.

Re: Defining an array inside a tuple

2017-08-28 Thread Krux02
I think you should use `object`, it is the equivalent of `struct` from C. type Vec2i = object x,y: int Vec2f = object x,y: float NVGglyphPosition = int32 GlyphArray* = array[100, NVGglyphPosition] TextBuffer* = object posit

Re: Question regarding the setter method/proc

2017-08-28 Thread pgmf
@Lando, Many thanks for your reply, much appreciated. I was really confused. This is how I understand the concept from your reply. Please correct me if I am wrong. * if ' s.host = 34 ' is called from the _same module_, it will directly access the object variable bypassing the 's.host=' method

Re: Been away for 9 months. What changed? Need some help to get back on track.

2017-08-28 Thread Araq
> You access them from the blog: > [https://nim-lang.org/blog.html](https://nim-lang.org/blog.html). Why isn't > this obvious? Because it should be named "news" instead?

Re: Question regarding the setter method/proc

2017-08-28 Thread Lando
The example from the tutorial is a bit misleading, try the updated [version from the language manual](https://nim-lang.org/docs/manual.html#procedures-properties) instead. The _host_ field of a _Socket_ object is invisible to code from a different module, but the tutorial example code accesses

Re: Nim - nimble, nake, confused

2017-08-28 Thread evacchi
Nimble can handle your build as well; I think you can safely ignore Nake

Re: Nim - nimble, nake, confused

2017-08-28 Thread LeuGim
> my needs are simple Consider first in Nim running just `nim c your_program` will compile not only _your_program.nim_, but also all imported modules recursively and build the final complete executable, so most of time you need just the compiler to build your project.

Re: Question regarding the setter method/proc

2017-08-28 Thread pgmf
Aplologies, there was an error in my program, corrected now. My question still stands though. Thanks.

Re: Nim - nimble, nake, confused

2017-08-28 Thread jacmoe
The reason I am confused is because if nimble is able to handle builds (nimble build) I would rather not have to deal with nake, if I can help it. Nake is probably more fully featured, but my needs are simple. Since I am totally new to Nim, I thought I'd ask you guys for advice. Are you using

Re: Defining an array inside a tuple

2017-08-28 Thread LeuGim
In addition to what _BigEpsilon_ says, if you want to instantiate it that way, you may use a template for not creating an additional variable explicitly each time and to fit all in one initialization: template ofType(typ: typedesc): auto = var x: typ x # usage va

Nim - nimble, nake, confused

2017-08-28 Thread jacmoe
I am a bit confused about the difference between nake and nimble when it applies to project management. Coming from Rust, where I am used to use Cargo to manage my projects/builds. I am currently using 'nimble init' to kick off a new Nim project, but I am aware of nake, which is a build tool.

Re: Defining an array inside a tuple

2017-08-28 Thread BigEpsilon
You don't need to instentiate an array because it is already instentiated. Try this Var x :TextBuffer echo repr (x.glyphPositions) Which should print 100 element with the default value of NVGglyphPosition, and that because array[100, X] is a fixed size array, wich means t

Defining an array inside a tuple

2017-08-28 Thread rayman22201
I am a Nim n00b, and one of the hardest things I am having trouble with is dealing with arrays in Nim. I have the following typedef type GlyphArray* = array[100, NVGglyphPosition] type TextBuffer* = tuple position: tuple[ x : float, y : float ] cur

Re: Simple Python-like class macro and some python-like procedures (print, input, range, others)

2017-08-28 Thread Krux02
@dom96 I am fairly sure that I submitted a pull request (that got accepted) not that long age that fixed the doc comments.

Question regarding the setter method/proc

2017-08-28 Thread pgmf
Hello all, A newbie here. I have been learning Nim using the online tutorials and is thoroughly enjoying Nim . I have completed the part 1 and have advanced to Part 2 of the tutorial. Have a question regarding the setter methods discussed in the 'Properties' section of the tutorial. Can you ple