Re: optional int parameters for a proc

2020-04-30 Thread Araq
I think I have a better design for `converter`, should write an RFC... _sigh_

Re: optional int parameters for a proc

2020-04-29 Thread mratsim
I really don't like converters if they are not in a "lenient_ops" kind of module. They introduce hard to debug bugs where the original input is converted and then not matched to something or ambiguous call because you have 2 automatic conversion possible (for example uint16 to int or uint16 to

optional int parameters for a proc

2020-04-28 Thread iffy1
To combine what @def and @Udiknedormin have suggested: import options converter toOption[T](x:T):Option[T] = some(x) proc xxx(param1: string, param2, param3 = none(int)) = if param2.isSome: echo "param2: ", param2.some if param3.isSome:

Re: optional int parameters for a proc

2017-08-29 Thread Arrrrrrrrr
But that's not how overloading in this case would work, as proposed by evacchi. If the function performs a different action depending on whether the value is nil or not, it might require totally different function to handle that case. Otherwise, putting the logic to adquire this value in a

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) =

Re: optional int parameters for a proc

2017-08-26 Thread evacchi
overloading may be an option as well: proc a(x:int) = discard proc a() = discard a() a(1)

Re: optional int parameters for a proc

2017-08-26 Thread def
For sake of completeness: import options proc xxx(param1: string, param2, param3 = none(int)) = if param2.isSome: echo "param2: ", param2.some if param3.isSome: echo "param3: ", param3.some xxx("a", param2 = some(1)) xxx("b", param3 =

Re: optional int parameters for a proc

2017-08-26 Thread bluenote
Actually there's no need for external libs or rolling your own solution. The standard library has an `Option[T]` and is exactly suited for this.

Re: optional int parameters for a proc

2017-08-26 Thread LeuGim
proc p(x: int, xIsSet: bool) = ... or smth like type IntOrNil = object x: int isSet: bool proc p(x: IntOrNil) = (if x.isSet: echo x.x else: #[ something else ]# discard) # additional procs may be added for such a type proc `$`(x:

optional int parameters for a proc

2017-08-26 Thread jlp765
**Issue**: Need `int` type parameters to be optional, and to test whether the parameter has been passed to the `proc` or not, BUT the `int` type does not allow a `nil` value So, how do you do the equivalent of proc xxx(param1: string, param2: int = nil, param3: int = nil)