Hi! This is an exercise from exercism.io:
import times
const gigasecond = initDuration(seconds = 1_000_000_000)
proc addGigasecond*(moment: DateTime): DateTime =
moment + gigasecond
If I replace proc with func, the compiler complains there could be side-effects. Which could they be?
I have tried to use the effects pragma to find out, but could not make it work. How would you use the pragma in this case?
I do not know for sure, but suspect it is from time zone construction. This works just added to the end of the posted example:
func diff*(a, b: DateTime): Duration = a - b
@Araq in this case the problem is that the time zone could change between calls and therefore this is not a pure function?
Do you know how to use the effects macro here?
Do you know how to use the effects macro here?
I didn't try it, but it should say that + has a side effect (what else?) and then you need to edit times.nim's + operator with the effects macro to get further information.