It always returns nil.
Doesn't that mean it's pure?
Does println cause any side effects??
Side effects can be roughly defined as "modifying any state not contained within the function itself". This includes writing to disk or making some sort of external API call, etc. Since println
writes to STDOUT
, it is altering the state of the stdout. Therefore it has a side effect.
It always returns nil.
Doesn't that mean it's pure?
It only means it's pure if it doesn't have side-effects.
Does println cause any side effects??
Yes, it prints.
If it didn't have a side-effect, it would be pretty boring since it also doesn't return anything sensible.
I prefer the term referential transparency to purity. An expression or a function is referentially transparent if you can replace it with its value (or vice versa) without changing the meaning of the program. This means that println
is referantially transparent IFF I can replace any occurrence of println
with nil
or any occurrence of nil
with println
without changing the meaning of the program. Obviously, you can't do that, ergo, println
is not referentially transparent / pure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With