My answer is yes. Function literals are functions. Functions need no names.
When a question asks, "Define a function t", I find no requirement to use the name t
within the program. The name t allows the question to make requirements like, "t(0) must return 0". In the actual program, the function might have a different name. Also, t(0)
might not be valid syntax to call the function.
Different languages have different rules for naming functions. In dc(1), every name is a single character, so we may make a t
function, but not a triple
function. In Common Lisp, t
is a constant for the true value, so we may not make a t
function.
If the function must have a name, then we have a question of scope, because not all languages use a single global namespace for all functions. Let us make a function s
(not t
) in Common Lisp to triple a value:
(flet((s(x)(* 3 x))))
What? The name s
is local to the flet
! We can't call this function! This s
is good enough for me, because one may call it by inserting code inside the flet
, before the last parenthesis. (For code golf, we can save 2 characters by doing (defun s(x)(* 3 x))
, which defines s
in the current package. If we want two named functions, then flet
is shorter.)
Someone might attempt to do (set's(lambda(x)(* 3 x)))
, which sets the variable name s
, not the function name s
. Now we can't write (s 4)
. We must write (funcall s 4)
. It still counts as a function named s
, I guess.
The removal of function names is a legitimate way to golf code. In Factor, why would I write : s ( x -- x ) 3 * ;
and then [ s ] map
when I can just write [ 3 * ] map
?
A few extreme languages have no functions because they have no call stack or returns. I mean sed(1). (For evidence that sed is a programming language, see math.sed.) If a question asks for a function, my opinion is that you may not answer with a sed function. You may answer with a shell-script function that calls sed.