Nim .18.0 whitespace issue

2018-03-14 Thread h42
"for i in 1 ..2:" give syntax error while "for i in 1..2 or 1 .. 2:" works. also x = x -10 gives syntax error. x = x-10 and x = x - 10 works fine. Normally, I am consistent with spaces or no spaces so this isn't a problem for me but the error message resulting from accidentally leaving out the

Re: Increasing Nim exposure

2018-03-14 Thread wavexx
A long time ago I suggested that to attract new developers a mailing list would be ideal. Following the forum is just inconvenient for me. My email client is vastly superior than any forum or rss interface. I find discourse much worse in term of user interface than nim-forum (at least this

Re: Increasing Nim exposure

2018-03-14 Thread Libman
[Related thread.](https://forum.nim-lang.org/t/3534) I hope the Nim ecosystem comes up with it's own alternatives - eventually even to GitHub, Linux, and the browser stack.

How to send tuple in Nim?

2018-03-14 Thread samzw
the codes is blow: type entry = tuple id: uint16 qname: string qtype: uint16 var obj: entry obj.id = 1 obj.qname = "this is demo" obj.qtype = 21 var socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) discard

Re: Increasing Nim exposure

2018-03-14 Thread dom96
I can see Nim: [https://hacklines.com/en?tags=Nim](https://hacklines.com/en?tags=Nim) The Nim Forum is a staple of Nim. I'd rather spend time improving it than switching to Discourse, are there features of Discourse that you think might make it more accessible? There are also other places to

Re: Lots of problems with package-level objects

2018-03-14 Thread dom96
> No. I couldn't get people to test this feature, sorry. You should have advertised it more. I didn't even know this feature existed...

Re: Lots of problems with package-level objects

2018-03-14 Thread Araq
> Has anyone successfully used these on something non-trivial? No. I couldn't get people to test this feature, sorry. > I often get request for RTTI generation for incomplete object errors on > things that should work Well, the compiler begs to differ. Not sure how much these can be mitigated

Re: Structural typing hack PoC

2018-03-14 Thread StasB
@mratsim: That sounds quite similar to what I made, except with classic vtables of proc pointers, while mine contain field offsets. Is there any chance that similar functionality could be supported by this vtref feature? The compiler could additionally generate getters and setters and add them

Re: Structural typing hack PoC

2018-03-14 Thread mratsim
@StasB, the future VTable and vtptr and vtref are hidden [here](https://github.com/nim-lang/Nim/blob/c671356d51488c96b4749a4d109b00d924e1f739/doc/manual/generics.txt#L585-L639).

Re: Is something like this possible?

2018-03-14 Thread solo989
Thx for the help. One more question : is there any way to forward declare a variable without knowing the exact type? if flag == true: var c = 5 else: var c = 10.0 The if statements here open a new scope so I no longer have access to the c variable. I was

Re: Is something like this possible?

2018-03-14 Thread mashingan
use `when` , as long the variable can be know at compile time import typetraits const flag = true when flag == true: var c = 5 else: var c = 10.0 echo name(type(c)) take a note that's only for compile time, you cannot switch during runtime

Re: Nim syntax Quiz

2018-03-14 Thread mashingan
`nimsuggest` doesn't help?

Re: Nim syntax Quiz

2018-03-14 Thread StasB
I think what it boils down to is that syntactic flexibility and good error messages are at odds, simply because the parser can keep going quite a long way past the point where it's already clear from the context that the result will be semantically invalid, as long as the code happens to be

Re: Nim syntax Quiz

2018-03-14 Thread Allin
To drive my point home, I shall now reveal what the compiler tells the errors are. And boy, they are bogus. type MyTuple = tuple(a: int, b: int) # syntax...Error: invalid indentation var myTuple: MyTuple = [a: 10, b: 10] # syntax...Error: invalid indentation

Increasing Nim exposure

2018-03-14 Thread spider910
Having access to various Ruby article feeder sites I recently came across this [https://hacklines.com](https://hacklines.com)/ [https://hacklines.com/en?ucc=rubyflow=Ruby%2CRails%2CSinatra](https://hacklines.com/en?ucc=rubyflow=Ruby%2CRails%2CSinatra) which is multilingual. It lists articles

Re: Structural typing hack PoC

2018-03-14 Thread StasB
> vtref is virtual table ref. I think what I did is already a virtual table ref of sorts, so I'm not sure what boia01 meant. Maybe that something like this (or better) is already being planned for the Nim core? That's always preferable to improvised solutions, I guess. > what's the advantage

Re: Is something like this possible?

2018-03-14 Thread def
While `StoreKind` can be any of `StoreInt|StoreFloat|StoreString`, once it is instantiated, it will stay that one. Instead you have two choices: 1\. derive from a common `Store` object: type Store = ref object of RootObj dep: seq[Store] req: seq[Store]

Re: Is something like this possible?

2018-03-14 Thread StasB
Well, you could do this: type StoreInt = ref object of RootObj val: int dep : seq[StoreVariable] req : seq[StoreVariable] StoreFloat = ref object of RootObj val : float dep : seq[StoreVariable] req :

Re: Is something like this possible?

2018-03-14 Thread mashingan
Do you perhaps want it like this? type Store[T] = ref object of RootObj val: T dep: seq[Store[T]] StoreInt = Store[int] converter toInt[T: int](x: Store[T]): T = x.val var a = StoreInt(val: 5, dep: @[]) echo a.toInt

Re: Structural typing hack PoC

2018-03-14 Thread StasB
Thanks! What's a vtref, though?

Re: Structural typing hack PoC

2018-03-14 Thread mashingan
vtref is virtual table ref. I don't know much about C++, what's the advantage of virtual table?

Is something like this possible?

2018-03-14 Thread solo989
type StoreInt = ref object of RootObj val: int dep : seq[StoreKind] req : seq[StoreKind] StoreFloat = ref object of RootObj val : float dep : seq[StoreKind] req : seq[StoreKind] StoreString = ref object of RootObj val :

Lots of problems with package-level objects

2018-03-14 Thread aviator
These seems like a nice solution to the cyclic type problem, but I've been run into lots of weird errors. Here's a simple one that causes a gcc error: main.nim: type plotest.MyObj = object import defs proc foo() = discard MyRef()

Re: Structural typing hack PoC

2018-03-14 Thread boia01
Very cool! (Still ... can't wait for concepts + vtrefs! )

Re: Nim syntax Quiz

2018-03-14 Thread Araq
> Quiz 2: Now, imagine that you are a nim newbie. Try to fix the errors with > the help of nim manual and compiler error messages. Or,better yet, ask a nim > beginner to fix the code and watch the frustration grow. Or better yet, you ask a beginner who can read a tutorial again to look at some