Re: Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-18 Thread mratsim
By the way, to restrict conversion to literals you can use the {lit} constraint converter toIntAp(n: int{lit}): IntAp Run Otherwise some subtle bugs might be introduced where you or your user do not want because an int was converted silently to IntAp.

Re: Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-18 Thread lotzz
Wow thanks, I didn't know about this use of converters. I can simplify a lot it code with this!

Re: Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-14 Thread JohnAD
No need apologize! Holy cow ... how did I not know about `converter`? I've been coding Nim for over a year now and I just now learned of it. I will have to re-read the manuals again. I wonder if there are any other hidden nuggets I've missed.

Re: Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-13 Thread Araq
Overloading of `=` is in devel but the signature always must be `= (dest: var T; source: T)` and it cannot be used to introduce new implicit conversions, for that you have to use a `converter`. There are currently no plans to change this, sorry.

Re: Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-13 Thread mashingan
Perhaps like this type IntAp = object setInts: array[0 .. 2, int] converter toIntAp(n: int): IntAp = let ints = [n, 0, 0] IntAp(setInts: ints) let n: IntAp = 5 Run

Is allowing non-matching types for assignment overloading in the development timeline?

2019-04-13 Thread JohnAD
If, for example, I were wanting to create a crazy new int type that stored its value as product of primes, and I was not concerned with performance, I could create my own pure nim type in a library. type intAP = object setOfPrimes: array[0..50, int] Run