Syntax for default arguments to generic proc

2021-06-16 Thread mp035
Thanks, I did not think of the ternary style of providing an argument, that is neat. I agree regarding the separate function, I ended up writing a `fooAux` procedure which was called by overloaded versions of `foo` with default arguments.

Syntax for default arguments to generic proc

2021-06-15 Thread xigoi
This works: func foo[T: int|float](x: T = when T is int: 3 else: 4.0): T = x * x echo foo[int]() echo foo[float]() echo foo(6) Run Though with more arguments, it would probably be better to extract it into a separate function for readability.

Syntax for default arguments to generic proc

2021-06-15 Thread mp035
Hi, is there syntax available for specifying default arguments to a generic proc based on type? For example (syntax doesnt work): proc get_a_value[ T: int | float](defaultValue: T int = low(int) | float = NegInf): T = var raw = getSomeStringFromInput() if raw == "":