Skip to main content
.Last.value
Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70

R, 9 bytes

body(t)=0

Try it online!

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

Try it online!

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

Try it online!

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.

R, 9 bytes

body(t)=0

Try it online!

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

Try it online!

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).

R, 9 bytes

body(t)=0

Try it online!

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

Try it online!

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

Try it online!

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.

added 26 characters in body
Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70

R, 9 bytes

body(t)=0

Try it online!

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 will allowallows us to save ~4a few bytes on challenges where we need to define a helper function.

A more standard solution would have been:

R, 13 bytes

f=function()0

Try it online!

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).

R, 9 bytes

body(t)=0

Try it online!

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 it will allow us to save ~4 bytes on challenges where we need to define a function.

A more standard solution would have been:

R, 13 bytes

f=function()0

Try it online!

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).

R, 9 bytes

body(t)=0

Try it online!

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

Try it online!

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).

Source Link
Robin Ryder
  • 15.6k
  • 2
  • 24
  • 70

R, 9 bytes

body(t)=0

Try it online!

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 it will allow us to save ~4 bytes on challenges where we need to define a function.

A more standard solution would have been:

R, 13 bytes

f=function()0

Try it online!

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).