On Mon, Jul 6, 2020 at 6:46 PM <kurnia.d....@gmail.com> wrote:

>
> to my understanding, a pure function is a function that doesn't have a
> side effect, so we can limit pure function to:
> - unable to call non-pure function
> - unable to modify a variable that is not declared on current function
> (like a global variable)
>
>
You also need an additional property, namely that the function always
returns the same output for a given input. That is, it is a "stable"
relation from inputs to outputs. Consider e.g.

https://play.golang.org/p/XI4IgfiLoub

where we read a global variable as part of the function body. You could
make this into an escaping variable in a closure if you want something more
local, but the global will serve the same purpose. There are many variants
of this scheme, for instance by reading on a channel as part of the
function body, and having that channel fed random values, etc.

Marking an expression as pure is a nominal type of language construction.
Go usually prefers structural language constructions in most places, so I
don't think it fits into the language design as a whole.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiUj339ySGiG5L2aE7jrV4OfhDr%2BW73%2B%2B4w49VG%2BrLFUNw%40mail.gmail.com.

Reply via email to