I am trying to understand why does this proc may have side-effects:
import times
const gigasecond = 1_000_000_000.seconds
proc addGigasecond*(moment: DateTime): DateTime =
moment + gigasecond
If you change proc with func you get:
Error: 'addGigasecond' can have side effects
I was told that the problem is in +, but from the point of view of the user I do not quite understand where's the side-effect. If you pass a particular DateTime object, in what sense does adding a fix number of seconds may have a side-effect? Isn't the result deterministic?
I tried using the effects pragma like this:
import times
const gigasecond = 1_000_000_000.seconds
proc addGigasecond*(moment: DateTime): DateTime =
result = moment + gigasecond
{.effects.}
but I see nothing in the output when compiling the file. Am I using the pragma correctly?
The .effects pragma only lists exceptions and "tag" effects.
import times
const gigasecond = 1_000_000_000.seconds
proc g() {.tags: [RootEffect].} = discard
proc addGigasecond*(moment: DateTime): DateTime =
result = moment + gigasecond
g()
{.effects.}
(I'm not sure why either but that's how it is.)