On Mon, Jul 6, 2020 at 3:11 PM bugpowder <mits...@gmail.com> wrote: > > I'd guess the compiler could then enforce it (see if any non-pure marked > function is called from a pure one), it could exploit it (e.g. play with > evaluation order, cache, etc), and other such things?
The compiler can already tell whether a function is pure, so I don't think that adding a keyword would lead to any better optimization. I agree that adding the keyword would let the compiler enforce it, but that doesn't seem all that big a benefit to me. It also seems like something that could be done by an analysis tool rather than requiring a change to the language. Ian > On Tue, Jul 7, 2020 at 1:00 AM Ian Lance Taylor <i...@golang.org> wrote: >> >> On Mon, Jul 6, 2020 at 9:47 AM <kurnia.d....@gmail.com> wrote: >> > >> > Hi, I don't know if this kind of idea is already discussed before. >> > >> > I have an idea of adding pure function marker/type on golang, it is just >> > like "constexpr" on C++ or "const fn" on Rust, whether this function is >> > evaluated at compile time if the input is known at compile time is another >> > discussion, >> > I don't think this idea is hard to implement >> > >> > 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) >> > >> > for this purpose, we can think receiver as input to the function >> >> ... >> >> > what do you guys think about this idea? >> >> You didn't really explain what we would gain by adding this to the >> language. It's clearly already possible to write pure functions. How >> does it help to add the ability to explicitly mark a function as pure? >> >> Ian >> >> -- >> 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/CAOyqgcXOdCc8Zz8mXAmghLm%2B6%3Dvi8S8zG_3Phrv2Hy-w%3Dm70kQ%40mail.gmail.com. > > -- > 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/CAACdnTAKTKQxU_K5xRqHGDKKBEhyTAq6%3D6q1HK%2BgDUewgJW1aw%40mail.gmail.com. -- 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/CAOyqgcWqYsBB6cWtGaqBrwEomv%2BVbOTTw0pWdzEZxDoqiwvrOw%40mail.gmail.com.