Submission formats are always flexible here on PPCG. Named functions, anonymous functions or even full programs that perform IO, are all fine.
Even currying is acceptable, for example, taking arguments as f(4)(5)
rather than f(4, 5)
.
But what about returning a function that returns the result?
Examples
Consider the following Python code to find the length of a string:
f = lambda s: s.__len__
I know this is a long way to do it, I'm just trying to give a simple example.
To call this function, one would have to call f
with the string parameter, and then call the result, to get the answer - for example, f("String")()
.
Another example is this pseudo-Java lambda to convert an object to a string:
x -> x.toString
If you assigned this to f
, you'd call it with f(object)()
. It's very similar to currying, except that the second call takes no parameter.
My question is - should we allow this as an acceptable output format for PPCG code-golf answers?
::
instead. \$\endgroup\$f(4)(5)
example is the counterpart to returning a function. I believe the counterpart would bef(g(4))
, as you are passing in a function, instead of simply calling the return value as a function. \$\endgroup\$