Delaying evaluation

Golang has ‘go’ and ‘defer’ which both evaluate their arguments, and either execute asynchronously or at the end of scope respectively. Is there a more convenient way to evaluate arguments and then execute manually. The only way I know is to wrap in a function. Is there a canonical way to do this?

i.e. Id like a better way to do something like this

f = func() { return g(1,2,“test”) }

e.g. is there a keyword that works like ‘delay’ in this example :

f = delay g(1,2,“test”)



Do you have an actual example of what you’re trying to accomplish? From the short example here it does not make sense.

(There is no such keyword. But 1, 2 and “test” don’t need delayed evaluating either - maybe you’re just looking for a variable to store a temporary result in?)

Well, maybe it wasn’t clear I guess. I simply want to make a closure function object ‘f’ taking no arguments, from another function g, in a more convenient way (so I can execute f later). Something like my invented ‘delay’ keyword. its just a bit verbose to have func() { return … }. I was wondering if there is a cleaner way?

No, that’s the way to do it in that case.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.