R, 9 bytes
body(t)=0
I think this complies with the rules. The function t
takes no input and outputs 0
. This works because there already exists a function called t
(the transposition function) and it redefines the body of the function; it would not work with say body(a)=0
(no object called a
) or body(F)=0
(F
is a logical, not a function). I think it complies because it is still created by me: I am not reusing what the pre-defined function does, simply its name.
I don't think I've ever seen this used by R golfers, but there may be situations where it allows us to save a few bytes on challenges where we need a helper function.
A more standard solution would have been:
R, 13 bytes
f=function()0
Function which takes no input and outputs 0
. This is 1 byte shorter than the function which takes no input and outputs nothing, which would be
f=function(){}
If we try to define a function with no body (f=function()
), R interprets this as an incomplete command (this might not be true in older versions of R).
As pointed out by OganM, we take this down to 11 bytes with
R, 11 bytes
function()0
which technically complies with the challenge requirement that the function be assigned to some sort of variable, since it is (ephemerally) assigned to .Last.value
.