[Question]
  [
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
 
 
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/187692/edit).
Closed 4 years ago.
[Improve this question](/posts/187692/edit) 
I honestly can't believe this challenge does not already exist.
# The challenge
Write a function.
# The specifics
* Your program must define some sort of callable function. This includes anything commonly known as a function, a lambda function, or a subroutine. All of these types of callables will be referred to as a "function" in this post.
	1. Input to the function is optional and not required.
	2. A return value from the function is also optional and not required but control must return to the calling program.
* The function must be assigned to some sort of variable so that it is possible to be accessed at a later time. This includes indirect assignment (in most common languages where declaring a named function automatically adds the name into the current scope) and direct assignment (assigning an anonymous function to a variable directly).
* The function does not need to be named.
* The function must be created by *you* - you cannot just assign a default function from the language to a variable.
* None of [the standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default), please.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so lowest score in bytes wins.
  
[Answer]
# x86 / x64 machine code, 1 byte
```
c3
```
Assembly:
```
ret
```
[Try it online! (nasm)](https://tio.run/##RYxBCkIxDET3OUUO8JWKG9HDSFqDFtIWfqLE09fSLpzN8BjekCqXKN9DJS29KyfLreLR2A1w5CktkuBdjXYDWH2dUyIR1HeESTdkz8sp7YNMvp3@FH0Lk3I1vIQXwBDXzSNi8HQeBzsb9P4D "Assembly (nasm, x64, Linux) – Try It Online")
¯\\_(ツ)\_/¯
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 0 bytes
[Try it online!](https://tio.run/##y0rNyan8DwQA "Jelly – Try It Online")
A monadic link that returns its argument. Since it is the first function to appear in the script, it can be called using `1Ŀ`. 
Thanks to @lirtosiast for pointing out that a 0 byte link/function would work in Jelly.
I.e.
```
3,4,5 1Ŀ
```
[Try it online!](https://tio.run/##y0rNyan8/5/LWMdEx1TB8Mj@//8B "Jelly – Try It Online")
[Answer]
# Javascript, 6 bytes
```
f=_=>0
```
Includes variable assignment. Not much to see here.
[Answer]
# [Haskell](https://www.haskell.org/), 3 bytes
```
o=9
```
This code defines a polymorphic function called `o` which takes one type parameter and one typeclass instance parameter. When this function is called, it takes the given typeclass instance, gets its `fromInteger` member, calls that member with the `Integer` value for 9, and returns the result.
Granted, what I just described is merely the behavior of the Haskell function `9`, and my code merely defines a function called `o` which is equivalent to `9`.
Now the only question is, is the `9` function "created by you," or is it "a default function from the language"?
I think that it is "created by you." My reason for saying this is that if you read the specification for Haskell, you will (I assume) find no mention of a `9` function anywhere. Instead, the specification states that you can create a number literal by stringing together one or more digits. Therefore, by writing a string of digits, I have written a function—even if I just so happen to have only used one digit.
[Answer]
# [Python 3](https://docs.python.org/3/), 9 bytes
```
def f():1
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNQ9PK8D@Q/A8A "Python 3 – Try It Online")
[Answer]
## ZX Spectrum BASIC, 6 bytes
```
DEF FN f()=PI
```
Hex dump: `CE 66 28 29 3D A7`. `CE` is a 1-byte keyword for `DEF FN` (including the trailing space), while `A7` is a 1-byte keyword for `PI`. Call using `FN f()`. Example program:
```
  10 PRINT FN f(): DEF FN f()=PI
```
Output:
```
3.1415927
```
[Answer]
# [R](https://www.r-project.org/), 9 bytes
```
body(t)=0
```
[Try it online!](https://tio.run/##K/r/Pyk/pVKjRNPW4H@JhuZ/AA "R – 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](https://www.r-project.org/), 13 bytes
```
f=function()0
```
[Try it online!](https://tio.run/##K/r/P802rTQvuSQzP09D0@B/mobmfwA "R – 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](https://www.r-project.org/), 11 bytes
```
function()0
```
[Try it online!](https://tio.run/##K/r/P600L7kkMz9PQ9Pgv55PYnGJXlliTmmqhuZ/AA "R – 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`.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 5 bytes
```
$!=!*
```
[Try it online!](https://tio.run/##K0gtyjH7r/BfRdFWUeu/NVdxYqWCiqKGoeZ/AA "Perl 6 – Try It Online")
Creates a Whatever lambda that returns the boolean not of its parameter, and assigns it to the variable `$!`.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 5 bytes
Defines a function `f` that takes no arguments and technically returns an undefined integer value.
```
f(){}
```
[Try it online!](https://tio.run/##bcsxCoAwDEDRvacITokguBcnTyLVlkCNUqsg4tlrCy6C8//PNM6YlCzSdSeWCPPAgsfCI8GlFMC6xw2rfvCexYGFkcNkoj8r0rlmp8tVJNaOkDqr/xjLF7oXhinuQaDV6k4P "C (gcc) – Try It Online")
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 7 bytes
```
  
	
```
Creates a subroutine that returns control to the caller. 
Explained in context:
```
[N
S S N
_Create_Label][N
T   N
_Return]
```
[Try it online!](https://tio.run/##K8/ILEktLkhMTv3/n0tBgYuLk@s/FxfXfwA "Whitespace – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)], 1 byte
This one is slightly questionable:
```
f
```
Defines `f`, which can be "called" e.g. by `f[]`, which "returns" the expression `f[]`
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 5 bytes
This is a function named `f` that does nothing.
```
: f ;
```
[**Try it Online**](https://tio.run/##S8svKsnQTU8DUf//WymkKVj/L05NVUj7DwA "Forth (gforth) – Try It Online")
In the TIO code, I added a footer of `see f`, which prints the definition of the function.
[Answer]
# [Lua](https://www.lua.org), 8 bytes
```
f=load''
```
[Try it online!](https://tio.run/##yylN/P8/zTYnPzFFXf1/moam9X8A "Lua – Try It Online")
Defines a (global) function `f`.
This uses Lua `load` function to compile given string which happens to be empty in our case (empty code is valid code) into function which does exactly what we wrote in its body: nothing.
For ones wondering, standard solution would be
```
function f()end
```
but this is longer (15 bytes).
[Answer]
# POSIX sh, 6 bytes
```
s()(1)
```
Using curly braces requires one more character.
[Answer]
# Java, 10 Bytes
this should match the rules of the challenge
```
void f(){}
```
[Answer]
# [Perl 5](https://www.perl.org/), 7 bytes
```
sub f{}
```
[Try it online!](https://tio.run/##K0gtyjH9/7@4NEkhrbr2/38A "Perl 5 – Try It Online")
[Answer]
# [Kotlin](https://kotlinlang.org/docs/reference/), 8 bytes
```
val f={}
```
An empty function stored in a variable f.  
Call it using `f()` or `f.invoke()`.
[Answer]
# [shortC](https://github.com/aaronryank/shortC), 1 byte
```
A
```
[Try it online!](https://tio.run/##K87ILypJ/v/f8f9/AA "shortC – Try It Online")
Transpiles into this C:
```
 int main(int argc, char **argv){;}
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~14~~ 13 bytes
```
(*f)()=L"Ã";
```
[Try it online!](https://tio.run/##S9ZNT07@/19DK01TQ9PWR@lws5L1/9zEzDwNzWouBYU0DU1rrtr//5LTchLTi//rVqVWpCYXlyQmZwMA "C (gcc) – Try It Online")
This defines a function `f` returning `int` and accepting an unspecified number (and type) of parameters, the machine code of which is contained within the string literal. The unicode character `Ã` (stored in memory as `0xc3 0x00 0x00 0x00` on a little endian machine) corresponds to the x86 `ret` instruction that returns from the function. Non x86 architectures may require different opcode(s) to return.
`gcc` may require the `-zexecstack` flag to avoid a segfault.
[Answer]
# Pascal, 22 bytes
```
procedure A;begin end;
```
[Answer]
# [Haskell](https://www.haskell.org/), 5 bytes
```
f x=0
```
[Try it online!](https://tio.run/##y0gszk7Nyfmfm5iZp2CrkJLPpaBQUJSZV6KgopCmYGhkjMJXcsvPT0osUvqfplBha/D/PwA "Haskell – Try It Online")
[Answer]
# [Tcl](http://tcl.tk/), ~~6~~ ~~5~~ 11 bytes
```
set f {_ ;}
```
[Try it online!](https://tio.run/##K0nO@f@/OLVEIU2hOl7BuvZ/YkFBTqWCSpqCwX8A "Tcl – Try It Online")
Including the assignment to the variable f as part of the bytecount to comply with rules. With this change, the more conventional definition below ties the one above for bytecount:
```
proc f _ {}
```
[Answer]
# XSLT, 134 bytes
```
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template name="a"></xsl:template></xsl:stylesheet>
```
A template is the closest thing this language has to a function. It can definitely be called; it takes zero arguments and "returns" the empty string.
[Answer]
# [F# (.NET Core)](https://www.microsoft.com/net/core/platform), 9 bytes
```
let f a=a
```
[Try it online!](https://tio.run/##SyvWTc4vSv3/Pye1RCFNIdE28f9/AA "F# (.NET Core) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 6 bytes
[Proc](https://ruby-doc.org/core-2.6/Proc.html) called `f` which accepts no argument and returns `nil`.
```
f=->{}
```
[Try it online!](https://tio.run/##KypNqvz/P81W16669n@BQppecmJOzn8A "Ruby – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 10 bytes
```
f=lambda:0
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P802JzE3KSXRyuB/mobmfwA)
[Answer]
## AppleScript, 10
```
on a()
end
```
Explained, compiled, and including invocation:
```
on a()    -- declare event handler "a"
end a     -- end declaration
-- invoke it:
a()
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 2 bytes
```
_
```
Called as `$U ($`.
`_` can be replaced with `@`, `Ï`, or `È`.
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Xwo)
[Answer]
# SmileBASIC (>=3), 9 bytes
```
DEF A
END
```
Function is called by `A`. 
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 2 bytes
```
#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zg@19Z7X9AUWZeSXRatHls7H8A "Wolfram Language (Mathematica) – Try It Online")
Unfortunately, just `&` does not work (an anonymous function that does nothing).
]