Empty program: Difference between revisions
Walterpachl (talk | contribs) No edit summary |
Walterpachl (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{task|Basic language learning}} In this task, the goal is to create the simplest possible program that is still considered "correct." =Programming Languages= =={{header|Ada}}== {{works with|GCC|4.1.2}} procedure Empty is begin null; end;=={{header|Agena}}== Actually nothing is valid code, too. |
|||
{{task|Basic language learning}} |
|||
In this task, the goal is to create the simplest possible program that is still considered "correct." |
|||
=Programming Languages= |
|||
=={{header|Ada}}== |
|||
{{works with|GCC|4.1.2}} |
|||
<lang ada>procedure Empty is |
|||
begin |
|||
null; |
|||
end;</lang> |
|||
=={{header|Agena}}== |
|||
Actually nothing is valid code, too. |
|||
<lang agena></lang> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
=== Brief form === |
=== Brief form === |
||
~ |
|||
<lang algol68>~</lang> |
|||
=== BOLD form === |
=== BOLD form === |
||
SKIP |
|||
<lang algol68>SKIP</lang> |
|||
=={{header|AmigaE}}== |
=={{header|AmigaE}}== |
||
PROC main() |
|||
ENDPROC=={{header|AppleScript}}== An empty .scpt file is considered the smallest runnable code, but the following would also be acceptable. return=={{header|Argile}}== The empty string or file are valid and do nothing. |
|||
ENDPROC</lang> |
|||
=={{header|AutoHotkey}}== An empty script would be enough. Adding "#Persistent" makes it persistent. #Persistent=={{header|AutoIt}}== An a single comment can be considered a valid program that does nothing. ;nothing=={{header|AWK}}== The empty string (or file) is recognised as valid program that does nothing. The program 1is the simplest useful program: like the UNIX command 'cat', it prints every line of the files given as arguments, or (if no arguments are given) the standard input. =={{header|BASIC}}== {{works with|QBasic}} 10 END{{works with|ZX Spectrum Basic}} On the ZX Spectrum, we can have a completely empty program with no lines. Here we attempt to run the empty program: RUN0 OK, 0:1 =={{header|Batch File}}== An empty batch file is syntactically correct and does nothing. |
|||
=={{header|AppleScript}}== |
|||
But on windows 7 an empty .bat file is not recognized and thus a character must exist in it: REM=={{header|BBC BASIC}}== In BBC BASIC an empty program is syntactically correct. |
|||
An empty .scpt file is considered the smallest runnable code, but the following would also be acceptable. |
|||
<lang applescript>return</lang> |
|||
=={{header|Befunge}}== @ The halt command '''@''' is required because code wraps around. An empty file would be an infinite loop. =={{header|Bracmat}}== An empty file is a valid program. However you need to load it, which requires a statement. In a Linux terminal, you could do touch empty bracmat 'get$empty'In DOS, you can do touch empty bracmat get$emptyIf we drop the requirement that the shortest program is stored in a file, we can do bracmat '' |
|||
=={{header|Argile}}== |
|||
The empty string or file are valid and do nothing. |
|||
<lang Argile></lang> |
|||
=={{header|AutoHotkey}}== |
|||
An empty script would be enough. Adding "#Persistent" makes it persistent. |
|||
<lang AutoHotkey>#Persistent</lang> |
|||
=={{header|AutoIt}}== |
|||
An a single comment can be considered a valid program that does nothing. |
|||
<lang AutoIt>;nothing</lang> |
|||
=={{header|AWK}}== |
|||
The empty string (or file) is recognised as valid program that does nothing. |
|||
The program |
|||
<lang awk> 1</lang> |
|||
is the simplest useful program: like the UNIX command 'cat', it prints every line of the files given as arguments, or (if no arguments are given) the standard input. |
|||
=={{header|BASIC}}== |
|||
{{works with|QBasic}} |
|||
<lang qbasic>10 END</lang> |
|||
{{works with|ZX Spectrum Basic}} |
|||
On the ZX Spectrum, we can have a completely empty program with no lines. Here we attempt to run the empty program: |
|||
<lang basic>RUN</lang> |
|||
0 OK, 0:1 |
|||
=={{header|Batch File}}== |
|||
An empty batch file is syntactically correct and does nothing. |
|||
<lang dos></lang> |
|||
But on windows 7 an empty .bat file is not recognized and thus a character must exist in it: |
|||
<lang dos>REM</lang> |
|||
=={{header|BBC BASIC}}== |
|||
In BBC BASIC an empty program is syntactically correct. |
|||
<lang bbcbasic></lang> |
|||
=={{header|Befunge}}== |
|||
@ |
|||
The halt command '''@''' is required because code wraps around. An empty file would be an infinite loop. |
|||
=={{header|Bracmat}}== |
|||
An empty file is a valid program. However you need to load it, which requires a statement. In a Linux terminal, you could do |
|||
<lang bracmat>touch empty |
|||
bracmat 'get$empty'</lang> |
|||
In DOS, you can do |
|||
<lang dos>touch empty |
|||
bracmat get$empty</lang> |
|||
If we drop the requirement that the shortest program is stored in a file, we can do |
|||
<lang bash>bracmat ''</lang> |
|||
(Linux) |
(Linux) |
||
or |
or |
||
bracmat ""(Windows) If two quotes to demarcate an empty string are counted as bigger than a single undemarcated non-empty expression, we can do bracmat . The dot is a binary operator. So the input consists of three nodes: the operator and its lhs and rhs, both empty strings in this case. If three nodes is too much, consider a slightly bigger glyph, such as the hyphen, which is a prefix, not a binary operator: bracmat - You also can start Bracmat without arguments, in which case it will run in interactive mode. Now press the Enter key. You have just run the shortest valid Bracmat program. =={{header|Brainf***}}== Empty program |
|||
<lang dos>bracmat ""</lang> |
|||
''Note:'' this works as all non-instruction characters are considered comments. Alternatively, a zero-byte file also works. =={{header|Brlcad}}== Pressing enter from the mged prompt, just returns another prompt, so I suppose that is the smallest possible program. However, before we can draw anything we at least need to open a database: opendb empty.g y=={{header|C}}== You'll notice that each example has an int return type, and returns 0. The meaning of the return value is system-dependent. '''argc''' contains the number of arguments. '''argv''' is an array containing those arguments as null-terminated strings. These memory for these strings are maintained by the runtime, and don't need to be manually freed. int main(int argc, char* argv[]) |
|||
(Windows) |
|||
If two quotes to demarcate an empty string are counted as bigger than a single undemarcated non-empty expression, we can do |
|||
bracmat . |
|||
The dot is a binary operator. So the input consists of three nodes: the operator and its lhs and rhs, both empty strings in this case. If three nodes is too much, consider a slightly bigger glyph, such as the hyphen, which is a prefix, not a binary operator: |
|||
bracmat - |
|||
You also can start Bracmat without arguments, in which case it will run in interactive mode. Now press the Enter key. You have just run the shortest valid Bracmat program. |
|||
=={{header|Brainf***}}== |
|||
<pre>Empty program</pre> |
|||
''Note:'' this works as all non-instruction characters are considered comments. Alternatively, a zero-byte file also works. |
|||
=={{header|Brlcad}}== |
|||
Pressing enter from the mged prompt, just returns another prompt, so I suppose that is the smallest possible program. However, before we can draw anything we at least need to open a database: |
|||
<lang mged>opendb empty.g y</lang> |
|||
=={{header|C}}== |
|||
You'll notice that each example has an int return type, and returns 0. The meaning of the return value is system-dependent. |
|||
'''argc''' contains the number of arguments. '''argv''' is an array containing those arguments as null-terminated strings. These memory for these strings are maintained by the runtime, and don't need to be manually freed. |
|||
<lang c>int main(int argc, char* argv[]) |
|||
{ |
{ |
||
return 0; |
return 0; |
||
}With some compilers, '''argc''' and '''argv''' may omitted. {{works with|gcc|4.0.3}} int main () |
|||
}</lang> |
|||
With some compilers, '''argc''' and '''argv''' may omitted. |
|||
{{works with|gcc|4.0.3}} |
|||
<lang c>int main () |
|||
{ |
{ |
||
return 0; |
return 0; |
||
} |
|||
}</lang> |
|||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
class Program |
|||
{ |
{ |
||
static void Main() |
static void Main() |
||
{ |
{ |
||
} |
} |
||
} |
|||
}</lang> |
|||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{works with|g++|4.0.3}} |
{{works with|g++|4.0.3}} |
||
int main ( int /*argc*/, char * * /*argv*/ ) { // Unused arguments should not be named // There are variations: // 1: main ''may'' explicitly return a value // (other non-void-returning C++ functions ''must'' do so, // but there's a special exception for main that falling off it // without an explicit return is equivalent to a "return 0;" at // the end of the main function) // 2: The arguments may be omitted entirely }=={{header|Clean}}== module Empty Start world = worldCompile the project with ''No Console'' or ''No Return Type'' to suppress printing of the value of the world. =={{header|Clojure}}== An empty file is the simplest valid Clojure program. =={{header|CoffeeScript}}== |
|||
<lang cpp>int main ( int /*argc*/, char * * /*argv*/ ) |
|||
{ |
|||
// Unused arguments should not be named |
|||
// There are variations: |
|||
// 1: main ''may'' explicitly return a value |
|||
// (other non-void-returning C++ functions ''must'' do so, |
|||
// but there's a special exception for main that falling off it |
|||
// without an explicit return is equivalent to a "return 0;" at |
|||
// the end of the main function) |
|||
// 2: The arguments may be omitted entirely |
|||
}</lang> |
|||
=={{header|Clean}}== |
|||
<lang clean>module Empty |
|||
Start world = world</lang> |
|||
Compile the project with ''No Console'' or ''No Return Type'' to suppress printing of the value of the world. |
|||
=={{header|Clojure}}== |
|||
An empty file is the simplest valid Clojure program. |
|||
=={{header|CoffeeScript}}== |
|||
<lang coffeescript></lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
void main() {} |
|||
=={{header|Dart}}== |
=={{header|Dart}}== |
||
main() { |
|||
} |
|||
}</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
Line 164: | Line 50: | ||
=={{header|E}}== |
=={{header|E}}== |
||
The shortest possible program: |
The shortest possible program: |
||
<pre></pre> |
|||
This is equivalent to: |
This is equivalent to: null |
||
<lang e>null</lang> |
|||
=={{header|eC}}== |
=={{header|eC}}== |
||
<pre></pre> |
|||
or |
or |
||
class EmptyApp : Application { void Main() { } }=={{header|Eiffel}}== A file called main.e: class MAIN |
|||
{ |
|||
void Main() |
|||
{ |
|||
} |
|||
}</lang> |
|||
=={{header|Eiffel}}== |
|||
A file called main.e: |
|||
<lang eiffel>class MAIN |
|||
create main |
create main |
||
feature main |
feature main |
||
do |
do |
||
end |
end |
||
end=={{header|Erlang}}== An empty module: -module(empty). An empty Erlang script file (escript): main(_) -> 1. |
|||
end</lang> |
|||
=={{header|Erlang}}== |
|||
An empty module: |
|||
<lang erlang>-module(empty).</lang> |
|||
An empty Erlang script file (escript): |
|||
<lang erlang>main(_) -> 1.</lang> |
|||
=={{header|eSQL}}== |
=={{header|eSQL}}== |
||
CREATE COMPUTE MODULE ESQL_Compute CREATE FUNCTION Main() RETURNS BOOLEAN BEGIN RETURN TRUE; END; END MODULE; |
|||
CREATE FUNCTION Main() RETURNS BOOLEAN |
|||
BEGIN |
|||
RETURN TRUE; |
|||
END; |
|||
END MODULE;</lang> |
|||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |
||
<lang Euphoria></lang> |
|||
=={{header|F_Sharp|F#}}== |
|||
F# has an interactive mode and a compiled mode. The interactive interpreter will accept an empty file so the shortest valid program is an empty zero-length file with the .fsx extension. |
=={{header|F_Sharp|F#}}== F# has an interactive mode and a compiled mode. The interactive interpreter will accept an empty file so the shortest valid program is an empty zero-length file with the .fsx extension. |
||
An empty compiled program is: [] |
|||
<lang fsharp></lang> |
|||
let main args = 0 |
|||
An empty compiled program is: |
|||
<lang fsharp>[<EntryPoint>] |
|||
let main args = 0</lang> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<lang factor></lang> |
|||
If you want to deploy a stand-alone application, that doesn't suffice though. Here's another version. |
|||
<lang factor>IN: rosetta.empty |
|||
: main ( -- ) ; |
|||
MAIN: main</lang> |
|||
If you want to deploy a stand-alone application, that doesn't suffice though. Here's another version. IN: rosetta.empty : main ( -- ) ; MAIN: main |
|||
=={{header|Falcon}}== |
|||
<pre>></pre> |
|||
Prints an empty line. |
|||
=={{header|Falcon}}== |
|||
<pre>>></pre> |
|||
> |
|||
Prints an empty line. >> |
|||
Prints nothing. |
Prints nothing. |
||
=={{header|FALSE}}== |
=={{header|FALSE}}== |
||
<lang false></lang> |
|||
=={{header|Fantom}}== |
|||
=={{header|Fantom}}== class Main |
|||
{ |
{ |
||
public static Void main () {} |
public static Void main () {} |
||
}=={{header|Fish}}== Actually the shortest valid program is a space (not empty file!), which is an infinite loop, though. (It keeps looping around) |
|||
}</lang> |
|||
An empty program is invalid; the interpreter will give an error. |
|||
The shortest program that will actually finish is a ;, which will end the program immediately: |
|||
=={{header|Fish}}== |
|||
; |
|||
Actually the shortest valid program is a space (not empty file!), which is an infinite loop, though. (It keeps looping around) |
|||
<lang Fish> </lang> |
|||
An empty program is invalid; the interpreter will give an error.<br/> |
|||
The shortest program that will actually finish is a <tt>;</tt>, which will end the program immediately: |
|||
<lang Fish>;</lang> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
<lang forth></lang> |
|||
For a Forth script to be used from a shell, you usually want the last command to be BYE in order to exit the interpreter when finished. |
|||
<lang forth>bye</lang> |
|||
For a Forth script to be used from a shell, you usually want the last command to be BYE in order to exit the interpreter when finished. bye=={{header|Fortran}}== end=={{header|Frink}}== Empty programs are valid. |
|||
=={{header|Fortran}}== |
|||
<lang fortran> end</lang> |
|||
=={{header| |
=={{header|Gecho}}== Empty programs are valid. |
||
Empty programs are valid. |
|||
<lang frink></lang> |
|||
=={{header|Gema}}== An empty program will copy input stream to output stream unchanged. |
|||
=={{header|Gecho}}== |
|||
Empty programs are valid. |
|||
<lang gecho></lang> |
|||
=={{header| |
=={{header|Genyris}}== |
||
An empty program will copy input stream to output stream unchanged. |
|||
<lang gema></lang> |
|||
=={{header|Genyris}}== |
|||
<pre></pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
package main |
|||
func main() { } |
func main() { } |
||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
<lang groovy></lang> |
|||
=={{header|Haskell}}== |
|||
'''Standard:''' [[Haskell 98]] |
|||
The simplest possible program is a single module using the implicit module header " |
=={{header|Haskell}}== '''Standard:''' [[Haskell 98]] The simplest possible program is a single module using the implicit module header "module Main(main) where", and defining the action main to do nothing: |
||
main = return ()The simplest possible module other than Main is one which contains no definitions: module X where {} |
|||
<lang haskell>main = return ()</lang> |
|||
The simplest possible module other than Main is one which contains no definitions: |
|||
<lang haskell>module X where {}</lang> |
|||
=={{header|haXe}}== |
=={{header|haXe}}== |
||
class Program { |
|||
static function main() { |
static function main() { |
||
} |
} |
||
}Unlike most languages haXe doesn't have arguments in the main function because it targets different platforms (some which don't support program arguments, eg: Flash or Javascript). You need to use the specific libraries of the platform you are targeting to get those. =={{header|HicEst}}== END ! looks better, but is not really needed=={{header|HQ9+}}== An empty file is a valid HQ9+ program that does nothing. =={{header|Icon}} and {{header|Unicon}}== procedure main() # a null file will compile but generate a run-time error for missing main end |
|||
}</lang> |
|||
Unlike most languages haXe doesn't have arguments in the main function because it targets different platforms (some which don't support program arguments, eg: Flash or Javascript). You need to use the specific libraries of the platform you are targeting to get those. |
|||
=={{header|HicEst}}== |
|||
<lang hicest>END ! looks better, but is not really needed</lang> |
|||
=={{header|HQ9+}}== |
|||
An empty file is a valid HQ9+ program that does nothing. |
|||
=={{header|Icon}} and {{header|Unicon}}== |
|||
<lang Icon>procedure main() # a null file will compile but generate a run-time error for missing main |
|||
end</lang> |
|||
=={{header|IDL}}== |
=={{header|IDL}}== |
||
end |
|||
<lang idl>end</lang> |
|||
=={{header|Intercal}}== |
=={{header|Intercal}}== |
||
PLEASE GIVE UP |
|||
=={{header|Io}}== |
=={{header|Io}}== |
||
<pre></pre> |
|||
=={{header|J}}== |
=={{header|J}}== |
||
<lang j></lang> |
|||
It returns itself: |
It returns itself: |
||
'' -: ". '' |
|||
1 |
|||
1</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{works with|Java|1.5+}} |
{{works with|Java|1.5+}} |
||
public class EmptyApplet extends java.applet.Applet { @Override public void init() { } } |
|||
@Override public void init() { |
|||
} |
|||
}</lang> |
|||
public class EmptyMainClass { public static void main(String... args) { } }The "..." basically means "as many of these as the programmer wants." Java will put multiple arguments into an array with the given name. This will work for any method where an array is an argument, but with a twist. A call can be made like this: method(arg0, arg1, arg2, arg3)All of the args will be put into an array in the order they were in the call. {{works with|Java|1.0+}} public class EmptyMainClass { public static void main(String[] args) { } } |
|||
<lang java>public class EmptyMainClass { |
|||
public static void main(String... args) { |
|||
} |
|||
}</lang> |
|||
public class EmptyApplet extends java.applet.Applet { public void init() { } }@Override - Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message. It's present from JDK 5.0 (1.5.0) and up. Actually this is not strictly correct. The smallest possible correct program in Java is an empty source file. =={{header|JavaScript}}== The empty file is a valid program. |
|||
The "..." basically means "as many of these as the programmer wants." Java will put multiple arguments into an array with the given name. This will work for any method where an array is an argument, but with a twist. A call can be made like this: |
|||
=={{header|Joy}}== |
|||
<lang java>method(arg0, arg1, arg2, arg3)</lang> |
|||
All of the args will be put into an array in the order they were in the call. |
|||
=={{header|K}}== |
|||
{{works with|Java|1.0+}} |
|||
<lang java>public class EmptyMainClass { |
|||
public static void main(String[] args) { |
|||
} |
|||
}</lang> |
|||
<lang java>public class EmptyApplet extends java.applet.Applet { |
|||
public void init() { |
|||
} |
|||
}</lang> |
|||
@Override - Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message. It's present from JDK 5.0 (1.5.0) and up. |
|||
Actually this is not strictly correct. The smallest possible correct program in Java is an empty source file. |
|||
=={{header|JavaScript}}== |
|||
The empty file is a valid program. |
|||
<pre></pre> |
|||
=={{header|Joy}}== |
|||
<lang joy></lang> |
|||
=={{header|K}}== |
|||
<lang K></lang> |
|||
=={{header|KonsolScript}}== |
=={{header|KonsolScript}}== |
||
function main() { |
|||
} |
|||
}</lang> |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
end=={{header|Lisp}}== [[Category:Common Lisp]] Most Lisp dialects, including Common Lisp, will accept no text (no forms) as a valid program. |
|||
<lang lb>end</lang> |
|||
=={{header|Lisp}}== |
|||
[[Category:Common Lisp]] |
|||
Most Lisp dialects, including Common Lisp, will accept no text (no forms) as a valid program. |
|||
<lang lisp></lang> |
|||
=={{header|Logo}}== |
=={{header|Logo}}== |
||
<lang logo></lang> |
|||
or end a standalone script with "bye" |
|||
<lang logo>#! /usr/local/bin/logo |
|||
or end a standalone script with "bye" #! /usr/local/bin/logo |
|||
bye</lang> |
|||
bye=={{header|LSE64}}== As with [[Forth]], an empty file is the shortest program. To exit the interpreter at the end of a loaded file: bye =={{header|Lua}}== |
|||
=={{header|LSE64}}== |
|||
As with [[Forth]], an empty file is the shortest program. To exit the interpreter at the end of a loaded file: |
|||
bye |
|||
=={{header|Lua}}== |
|||
<lang Lua></lang> |
|||
=={{header|M4}}== |
=={{header|M4}}== |
||
<lang M4></lang> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |
||
<lang Mathematica></lang> |
|||
=={{header|MATLAB}}== |
=={{header|MATLAB}}== |
||
function [varargout] = emptyprogram(varargin) |
|||
=={{header|MAXScript}}== |
=={{header|MAXScript}}== An empty MAXScript file returns "OK" on execution =={{header|Metafont}}== end |
||
An empty MAXScript file returns "OK" on execution |
|||
=={{header|Metafont}}== |
|||
<lang metafont>end</lang> |
|||
=={{header|ML/I}}== |
=={{header|ML/I}}== |
||
<lang ML/I></lang> |
|||
=={{header|MMIX}}== |
=={{header|MMIX}}== |
||
LOC #100 |
|||
Main TRAP 0,Halt,0 // main (argc, argv) {} |
Main TRAP 0,Halt,0 // main (argc, argv) {} |
||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
MODULE Main; |
|||
BEGIN |
BEGIN |
||
END Main. |
END Main. |
||
=={{header|Modula-3}}== |
=={{header|Modula-3}}== |
||
MODULE Main; |
|||
BEGIN |
BEGIN |
||
END Main.=={{header|MUMPS}}== The empty file is a valid program. |
|||
END Main.</lang> |
|||
=={{header|MUMPS}}== |
|||
The empty file is a valid program. |
|||
<pre></pre> |
|||
=={{header|Nemerle}}== |
=={{header|Nemerle}}== |
||
Compiles with warnings: |
Compiles with warnings: |
||
null |
|||
<lang Nemerle>null</lang> |
|||
Compiles without warnings (so, more correct): |
Compiles without warnings (so, more correct): |
||
module Program |
|||
{ |
{ |
||
Main() : void |
Main() : void |
||
{ |
{ |
||
} |
} |
||
}=={{header|NetRexx}}== The following two samples both generate valid programs. This minimal example requires that the file be named to match the class: class emptyThis example will generate it's class based on the file name: method main(args = String[]) static=={{header|NewLISP}}== ; |
|||
}</lang> |
|||
=={{header| |
=={{header|Nimrod}}== |
||
The following two samples both generate valid programs. |
|||
This minimal example requires that the file be named to match the class: |
|||
<lang NetRexx>class empty</lang> |
|||
This example will generate it's class based on the file name: |
|||
<lang NetRexx>method main(args = String[]) static</lang> |
|||
=={{header|NewLISP}}== |
|||
<lang NewLISP>; </lang> |
|||
=={{header|Nimrod}}== |
|||
<pre></pre> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
bundle Default { class Empty { function : Main(args : String[]) ~ Nil { } } |
|||
<lang objeck>bundle Default { |
|||
class Empty { |
|||
function : Main(args : String[]) ~ Nil { |
|||
} |
|||
}</lang> |
|||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |
||
{{works with|gcc|4.0.1}} |
{{works with|gcc|4.0.1}} |
||
int main(int argc, const char **argv) { |
|||
return 0; |
return 0; |
||
}The minimal ''empty'' Cocoa/OpenStep application, useful as life-support for many examples given at RosettaCode, is #import |
|||
}</lang> |
|||
The minimal ''empty'' Cocoa/OpenStep application, useful as life-support for many examples given at RosettaCode, is |
|||
<lang objc>#import <Cocoa/Cocoa.h> |
|||
int main( int argc, const char *argv[] ) |
int main( int argc, const char *argv[] ) |
||
Line 471: | Line 224: | ||
[pool release]; |
[pool release]; |
||
return 0; |
return 0; |
||
} |
|||
}</lang> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
{{works with|Ocaml|3.09}} |
{{works with|Ocaml|3.09}} |
||
;;Actually, the smallest possible correct program in OCaml is an empty source file. =={{header|Octave}}== An empty text file can be a valid empty program, but since Octave has the concept of "function file" (a file containing a single function; the file is automatically loaded when a function with the same name of the file, save for the extension, is called, and the first function present in the file is used), the name of the empty file matters. E.g. calling an empty file as isempty.m makes unusable the builtin isemptyfunction. =={{header|Oz}}== === REPL === The simplest program that can be evaluated in the REPL (Emacs mode) is the empty program. |
|||
<lang ocaml>;;</lang> |
|||
=== Accepted by compiler === The simplest 'program' that can be compiled is a file which contains a single expression. unitSuch a 'program' cannot be executed, though. === Standalone === The simplest standalone program is a root functor that does not define anything. ("Functors" are first-class modules.) functor |
|||
Actually, the smallest possible correct program in OCaml is an empty source file. |
|||
=={{header|Octave}}== |
|||
An empty text file can be a valid empty program, but since Octave has the concept of "function file" (a file containing a single function; the file is automatically loaded when a function with the same name of the file, save for the extension, is called, and the first function present in the file is used), the name of the empty file matters. E.g. calling an empty file as <tt>isempty.m</tt> makes unusable the builtin <tt>isempty</tt> function. |
|||
=={{header|Oz}}== |
|||
=== REPL === |
|||
The simplest program that can be evaluated in the REPL (Emacs mode) is the empty program. |
|||
<lang oz></lang> |
|||
=== Accepted by compiler === |
|||
The simplest 'program' that can be compiled is a file which contains a single expression. |
|||
<lang oz>unit</lang> |
|||
Such a 'program' cannot be executed, though. |
|||
=== Standalone === |
|||
The simplest standalone program is a root functor that does not define anything. ("Functors" are first-class modules.) |
|||
<lang oz>functor |
|||
define |
define |
||
skip |
skip |
||
end |
end |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
<lang parigp></lang> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
program ProgramName; |
|||
begin |
begin |
||
end.The first line is not necessary in modern Pascal dialects. With today's most compilers, the empty program is just: begin end. |
|||
end.</lang> |
|||
The first line is not necessary in modern Pascal dialects. With today's most compilers, the empty program is just: |
|||
<lang pascal>begin end.</lang> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{works with|Perl|5.8.8}} |
{{works with|Perl|5.8.8}} |
||
#!/usr/bin/perl |
|||
1; |
1; |
||
#!/usr/bin/perl |
|||
exit; |
exit; |
||
#!/usr/bin/perl |
|||
# A program without a body will work too |
# A program without a body will work too |
||
#!/usr/bin/perlThe smallest possible program is an empty file (zero length). This requires you to specify the interpreter instead of relying on the shell's shebang magic, thus: '''perl empty.pl'''. The smallest possible Perl one-liner is '''perl -e0'''. =={{header|Perl 6}}== The empty program is valid and does nothing but return a successful exit code. =={{header|PHP}}== An empty text file is a correct PHP program that does nothing. =={{header|PicoLisp}}== (de foo ())=={{header|PIR}}== The ''':main''' pragma indicates that a subroutine is the program's entry point. However, if a subroutine is the first (or only, which would also have the effect of making it the first) routine in the program, Parrot will use that. So we may comfortably omit it in this case. .sub empty_program .end |
|||
<lang perl>#!/usr/bin/perl</lang> |
|||
The smallest possible program is an empty file (zero length). This requires you to specify the interpreter instead of relying on the shell's shebang magic, thus: '''perl empty.pl'''. |
|||
The smallest possible Perl one-liner is '''perl -e0'''. |
|||
=={{header|Perl 6}}== |
|||
The empty program is valid and does nothing but return a successful exit code. |
|||
=={{header|PHP}}== |
|||
An empty text file is a correct PHP program that does nothing. |
|||
=={{header|PicoLisp}}== |
|||
<lang PicoLisp>(de foo ())</lang> |
|||
=={{header|PIR}}== |
|||
The ''':main''' pragma indicates that a subroutine is the program's entry point. However, if a subroutine is the first (or only, which would also have the effect of making it the first) routine in the program, Parrot will use that. So we may comfortably omit it in this case. |
|||
<lang pir>.sub empty_program |
|||
.end</lang> |
|||
=={{header|Pike}}== |
=={{header|Pike}}== |
||
int main(){} |
|||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
s: proc options (main); |
|||
end; |
end; |
||
=={{header|PL/SQL}}== |
=={{header|PL/SQL}}== |
||
BEGIN |
|||
NULL; |
NULL; |
||
END;=={{header|Pop11}}== Pop11 has two compilers, incremental and batch compiler. For the incremental compiler one can use just empty program text (empty file), or a file containing nothing but a comment, e.g. ;;; This is a valid Pop11 program that does absolutely nothing.The batch compiler generates an executable which starts at a given entry point, so one should provide an empty function. If one wants program that works the same both with incremental compiler and batch compiler the following may be useful: compile_mode :pop11 +strict; |
|||
END;</lang> |
|||
=={{header|Pop11}}== |
|||
Pop11 has two compilers, incremental and batch compiler. For the incremental compiler one can use just empty program text (empty file), or a file containing nothing but a comment, e.g. |
|||
<lang pop11>;;; This is a valid Pop11 program that does absolutely nothing.</lang> |
|||
The batch compiler generates an executable which starts at a given entry point, so one should provide an empty function. If one wants program that works the same both with incremental compiler and batch compiler the following may be useful: |
|||
<lang pop11>compile_mode :pop11 +strict; |
|||
define entry_point(); |
define entry_point(); |
||
enddefine; |
enddefine; |
||
#_TERMIN_IF DEF POPC_COMPILING |
#_TERMIN_IF DEF POPC_COMPILING |
||
entry_point();Here the batch compiler will stop reading source before call to entry_point while incremental compiler will execute the call, ensuring that in both cases execution will start from the function entry_point. =={{header|PostScript}}== An empty file is a valid PostScript program that does nothing. Following good programming practice, however, and to ensure that a PostScript printer will interpret a file correctly, one should make the first 4 characters of the file be %!PSIf a particular version of the PS interpreter is needed, this would be included right there: %!PS-2.0 |
|||
entry_point();</lang> |
|||
Here the batch compiler will stop reading source before call to entry_point while incremental compiler will execute the call, ensuring that in both cases execution will start from the function entry_point. |
|||
=={{header|PostScript}}== |
|||
An empty file is a valid PostScript program that does nothing. |
|||
Following good programming practice, however, and to ensure that a PostScript printer will interpret a file correctly, one should make the first 4 characters of the file be |
|||
<lang postscript>%!PS</lang> |
|||
If a particular version of the PS interpreter is needed, this would be included right there: |
|||
<lang postscript>%!PS-2.0 |
|||
% ...or... |
% ...or... |
||
%!PS-3.0 |
%!PS-3.0 |
||
% etc=={{header|PowerShell}}== An empty text file is a correct Powershell script that does nothing. =={{header|PSQL}}== EXECUTE BLOCK |
|||
% etc</lang> |
|||
=={{header|PowerShell}}== |
|||
An empty text file is a correct Powershell script that does nothing. |
|||
=={{header|PSQL}}== |
|||
<lang sql>EXECUTE BLOCK |
|||
AS |
AS |
||
BEGIN |
BEGIN |
||
END=={{header|ProDOS}}== This is an acceptable program: IGNORELINE |
|||
END</lang> |
|||
=={{header|ProDOS}}== |
|||
This is an acceptable program: |
|||
<lang ProDOS>IGNORELINE</lang> |
|||
But also you could include a delimiter character recognized by the compiler/interpreter: |
But also you could include a delimiter character recognized by the compiler/interpreter: |
||
;=={{header|PureBasic}}== An empty file is a correct PureBasic program that does nothing. |
|||
<lang ProDOS>;</lang> |
|||
=={{header|Python}}== An empty text file is a correct Python program that does nothing. =={{header|R}}== An empty text file is a valid empty program =={{header|Raven}}== An empty text file is an empty program. =={{header|REBOL}}== The header section is mandatory if you want it to be recognized as a REBOL program. It doesn't have to be filled in though: REBOL []=={{header|Retro}}== An empty file is the smallest valid program. |
|||
=={{header|PureBasic}}== |
|||
An empty file is a correct PureBasic program that does nothing. |
|||
<lang PureBasic></lang> |
|||
To save an application doing nothing, you need to do a bit more work though: &bye is boot |
|||
=={{header|Python}}== |
|||
An empty text file is a correct Python program that does nothing. |
|||
=={{header|R}}== |
|||
An empty text file is a valid empty program |
|||
=={{header|Raven}}== |
|||
An empty text file is an empty program. |
|||
=={{header|REBOL}}== |
|||
The header section is mandatory if you want it to be recognized as a REBOL program. It doesn't have to be filled in though: |
|||
<lang REBOL>REBOL []</lang> |
|||
=={{header|Retro}}== |
|||
An empty file is the smallest valid program. |
|||
<lang Retro></lang> |
|||
To save an application doing nothing, you need to do a bit more work though: |
|||
<lang Retro>&bye is boot</lang> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
===version 1=== An empty file is a valid empty program; however, for some REXX implementation the first two characters must be /*(i.e. the first line must be a comment) in order to recognize the file as a REXX script: /* empty */ |
|||
===version 1=== |
|||
An empty file is a valid empty program; however, for some REXX implementation the first two characters must be <tt>/*</tt> (i.e. the first line must be a comment) in order to recognize the file as a REXX script: |
|||
<lang rexx>/* empty */</lang> |
|||
===version 2=== |
===version 2=== |
||
/**/ |
|||
<lang rexx>/**/</lang> |
|||
===version 3=== |
===version 3=== |
||
REXX on MVS/TSO requires REXX to be in the first line: |
REXX on MVS/TSO requires REXX to be in the first line: |
||
<lang rexx> |
|||
/* REXX */ |
/* REXX */ |
||
</lang> |
|||
=={{header|Rhope}}== |
|||
{{works with|Rhope|alpha 1}} |
|||
Main(0,0) |
|||
|: :| |
|||
=={{header|Rhope}}== {{works with|Rhope|alpha 1}} Main(0,0) |: :| =={{header|Ruby}}== An empty file is a valid Ruby program. However, in order to make it runnable on *nix systems, a shebang line is necessary: #!/usr/bin/env ruby |
|||
=={{header|Ruby}}== |
|||
An empty file is a valid Ruby program. However, in order to make it runnable on *nix systems, a shebang line is necessary: |
|||
<lang ruby>#!/usr/bin/env ruby</lang> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
object emptyProgram { def main(args: Array[String]) {} } |
|||
def main(args: Array[String]) {} |
|||
}</lang> |
|||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
<lang scheme></lang> |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
$ include "seed7_05.s7i"; const proc: main is noop; |
|||
const proc: main is noop;</lang> |
|||
=={{header|Slate}}== |
=={{header|Slate}}== |
||
<lang slate></lang> |
|||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
[]=={{header|SNUSP}}== $# '''$''' sets the instruction pointer (going right), and '''#''' halts the program (empty stack). =={{header|SNOBOL4}}== A valid program requires an '''end''' label. The shortest (virtually empty) program is then: end=={{header|Standard ML}}== ;Actually, the smallest possible correct program in Standard ML is an empty source file. =={{header|Suneido}}== function () { }=={{header|Tcl}}== Nothing is mandatory in Tcl, so an empty file named nothing.tclwould be a valid "empty program". |
|||
<lang smalltalk>[]</lang> |
|||
=={{header|SNUSP}}== |
|||
$# |
|||
'''$''' sets the instruction pointer (going right), and '''#''' halts the program (empty stack). |
|||
=={{header|SNOBOL4}}== |
|||
A valid program requires an '''end''' label. The shortest (virtually empty) program is then: |
|||
<lang snobol>end</lang> |
|||
=={{header|Standard ML}}== |
|||
<lang sml>;</lang> |
|||
Actually, the smallest possible correct program in Standard ML is an empty source file. |
|||
=={{header|Suneido}}== |
|||
<lang Suneido>function () { }</lang> |
|||
=={{header|Tcl}}== |
|||
Nothing is mandatory in Tcl, so an empty file named <tt>nothing.tcl</tt> would be a valid "empty program". |
|||
<lang tcl></lang> |
|||
=={{header|Toka}}== |
|||
For interpreted code, nothing is required, although '''bye''' is necessary for an empty script to exit (rather than wait for the user to exit the listener). Hence: |
|||
bye |
|||
Or, for a directly runnable script: |
|||
#! /usr/bin/toka |
|||
bye |
|||
For compiled code, the simplest program is an empty quote: |
|||
[ ] |
|||
Again, to exit the listener, you will still need user input if this is not followed with '''bye'''. |
|||
=={{header|TI-83 BASIC}}== |
|||
: |
|||
=={{header|TI-89 BASIC}}== |
|||
Prgm |
|||
EndPrgm |
|||
=={{header|Toka}}== For interpreted code, nothing is required, although '''bye''' is necessary for an empty script to exit (rather than wait for the user to exit the listener). Hence: bye Or, for a directly runnable script: #! /usr/bin/toka bye For compiled code, the simplest program is an empty quote: [ ] Again, to exit the listener, you will still need user input if this is not followed with '''bye'''. =={{header|TI-83 BASIC}}== : =={{header|TI-89 BASIC}}== Prgm EndPrgm =={{header|Trith}}== |
|||
=={{header|Trith}}== |
|||
<lang trith></lang> |
|||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
$$ MODE TUSCRIPT |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
{{works with|Bourne Shell}} |
{{works with|Bourne Shell}} |
||
#!/bin/sh |
|||
{{works with|Bourne Again SHell}} |
{{works with|Bourne Again SHell}} |
||
#!/bin/bash=={{header|Unlambda}}== i (See how i plays so many roles in unlambda?) =={{header|VBScript}}== An empty .vbs file is considered the smallest runnable code, but the following (a single apostrophe as comment marker) would also be acceptable (along with other non-executing instructions like option explicit.) |
|||
<lang bash>#!/bin/bash</lang> |
|||
'=={{header|VHDL}}== Compiled and simulated by Modelsim: entity dummy is end; architecture empty of dummy is begin end;=={{header|Visual Basic .NET}}== {{works with|Visual Basic .NET|2005}} Module General |
|||
=={{header|Unlambda}}== |
|||
i |
|||
(See how i plays so many roles in unlambda?) |
|||
=={{header|VBScript}}== |
|||
An empty .vbs file is considered the smallest runnable code, but the following (a single apostrophe as comment marker) would also be acceptable (along with other non-executing instructions like <code>option explicit</code>.) |
|||
<lang vb>'</lang> |
|||
=={{header|VHDL}}== |
|||
Compiled and simulated by Modelsim: |
|||
<lang VHDL>entity dummy is |
|||
end; |
|||
architecture empty of dummy is |
|||
begin |
|||
end;</lang> |
|||
=={{header|Visual Basic .NET}}== |
|||
{{works with|Visual Basic .NET|2005}} |
|||
<lang vbnet>Module General |
|||
Sub Main() |
Sub Main() |
||
End Sub |
End Sub |
||
End Module |
End Module |
||
=={{header|X86 Assembly}}== |
=={{header|X86 Assembly}}== |
||
{{works with|NASM|Linux}} |
{{works with|NASM|Linux}} |
||
section .text |
|||
global _start |
global _start |
||
Line 737: | Line 332: | ||
mov eax, 1 |
mov eax, 1 |
||
int 0x80 |
int 0x80 |
||
ret |
ret |
||
{{works with|MASM}} |
{{works with|MASM}} |
||
.386 |
|||
.model flat, stdcall |
.model flat, stdcall |
||
option casemap:none |
option casemap:none |
||
Line 746: | Line 341: | ||
start: |
start: |
||
ret |
ret |
||
end start |
end start |
||
=={{header|XQuery}}== |
=={{header|XQuery}}== |
||
.The dot selects the current context node and returns it unchanged. =={{header|XSLT}}== |
|||
<lang xquery>.</lang> |
|||
The dot selects the current context node and returns it unchanged. |
|||
=={{header|XSLT}}== |
|||
<lang xslt><?xml version="1.0" encoding="utf-8"?> |
|||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> |
|||
<!-- code goes here --> |
|||
</xsl:stylesheet></lang> |
|||
Add other namespaces to the stylesheet attributes (like xmlns:fo="http://www.w3.org/1999/XSL/Format") if you use them. |
|||
Since XSLT is XML, and |
Add other namespaces to the stylesheet attributes (like xmlns:fo="http://www.w3.org/1999/XSL/Format") if you use them. Since XSLT is XML, and transform is a synonym for stylesheet, the example above can be minified to: |
||
<lang xslt><transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"/></lang> |
|||
This stylesheet echoes the text content of an XML file. The shortest stylesheet without any output would be |
This stylesheet echoes the text content of an XML file. The shortest stylesheet without any output would be |
||
<lang xslt><transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> |
|||
<template match="/" /> |
|||
</transform></lang> |
|||
=={{header|xTalk}}== |
|||
{{works with|HyperCard}} |
|||
on startup |
|||
end startup |
|||
=={{header|Yorick}}== |
|||
An empty file is valid and does nothing. |
|||
<pre></pre> |
|||
=={{header|xTalk}}== {{works with|HyperCard}} on startup end startup =={{header|Yorick}}== An empty file is valid and does nothing. |
|||
=Markup Languages= |
|||
=Markup Languages= =={{header|HTML}}== HTML 5, [http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#optional-tags section 11.1.2.4 Optional tags], allows to omit ''html'', ''head'' and ''body'' tags. The implicit ''body'' element can be empty, but the implicit ''head'' element must contain a ''title'' element, says [http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-head-element section 4.2.1 The head element]. There seems no rule against an empty title. Therefore, the shortest correct HTML document is: |
|||
=={{header|HTML}}== |
|||
HTML 5, [http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#optional-tags section 11.1.2.4 Optional tags], allows to omit ''html'', ''head'' and ''body'' tags. The implicit ''body'' element can be empty, but the implicit ''head'' element must contain a ''title'' element, says [http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-head-element section 4.2.1 The head element]. There seems no rule against an empty title. Therefore, the shortest correct HTML document is: |
|||
<lang html5><!DOCTYPE html><title></title></lang> |
|||
The shortest correct XHTML document is: |
The shortest correct XHTML document is: |
||
<lang html5><html xmlns="http://www.w3.org/1999/xhtml"><head><title /></head><body /></html></lang> |
|||
=={{header|plainTeX}}== |
|||
<lang tex>\bye</lang> |
|||
=={{header|LaTeX}}== |
|||
<lang latex>\documentclass{article} |
|||
\begin{document} |
|||
\end{document}</lang> |
Revision as of 15:08, 30 June 2012
You are encouraged to solve this task according to the task description, using any language you may know.
In this task, the goal is to create the simplest possible program that is still considered "correct." =Programming Languages= ==Ada==
procedure Empty is begin null; end;==Agena== Actually nothing is valid code, too.
ALGOL 68
Brief form
~
BOLD form
SKIP
AmigaE
PROC main() ENDPROC==AppleScript== An empty .scpt file is considered the smallest runnable code, but the following would also be acceptable. return==Argile== The empty string or file are valid and do nothing.
==AutoHotkey== An empty script would be enough. Adding "#Persistent" makes it persistent. #Persistent==AutoIt== An a single comment can be considered a valid program that does nothing. ;nothing==AWK== The empty string (or file) is recognised as valid program that does nothing. The program 1is the simplest useful program: like the UNIX command 'cat', it prints every line of the files given as arguments, or (if no arguments are given) the standard input. ==BASIC==
10 END
On the ZX Spectrum, we can have a completely empty program with no lines. Here we attempt to run the empty program: RUN0 OK, 0:1 ==Batch File== An empty batch file is syntactically correct and does nothing.
But on windows 7 an empty .bat file is not recognized and thus a character must exist in it: REM==BBC BASIC== In BBC BASIC an empty program is syntactically correct.
==Befunge== @ The halt command @ is required because code wraps around. An empty file would be an infinite loop. ==Bracmat== An empty file is a valid program. However you need to load it, which requires a statement. In a Linux terminal, you could do touch empty bracmat 'get$empty'In DOS, you can do touch empty bracmat get$emptyIf we drop the requirement that the shortest program is stored in a file, we can do bracmat (Linux) or bracmat ""(Windows) If two quotes to demarcate an empty string are counted as bigger than a single undemarcated non-empty expression, we can do bracmat . The dot is a binary operator. So the input consists of three nodes: the operator and its lhs and rhs, both empty strings in this case. If three nodes is too much, consider a slightly bigger glyph, such as the hyphen, which is a prefix, not a binary operator: bracmat - You also can start Bracmat without arguments, in which case it will run in interactive mode. Now press the Enter key. You have just run the shortest valid Bracmat program. ==Brainf***== Empty program Note: this works as all non-instruction characters are considered comments. Alternatively, a zero-byte file also works. ==Brlcad== Pressing enter from the mged prompt, just returns another prompt, so I suppose that is the smallest possible program. However, before we can draw anything we at least need to open a database: opendb empty.g y==C== You'll notice that each example has an int return type, and returns 0. The meaning of the return value is system-dependent. argc contains the number of arguments. argv is an array containing those arguments as null-terminated strings. These memory for these strings are maintained by the runtime, and don't need to be manually freed. int main(int argc, char* argv[]) {
return 0;
}With some compilers, argc and argv may omitted.
int main ()
{
return 0;
}
C#
class Program {
static void Main() { }
}
C++
int main ( int /*argc*/, char * * /*argv*/ ) { // Unused arguments should not be named // There are variations: // 1: main may explicitly return a value // (other non-void-returning C++ functions must do so, // but there's a special exception for main that falling off it // without an explicit return is equivalent to a "return 0;" at // the end of the main function) // 2: The arguments may be omitted entirely }==Clean== module Empty Start world = worldCompile the project with No Console or No Return Type to suppress printing of the value of the world. ==Clojure== An empty file is the simplest valid Clojure program. ==CoffeeScript==
D
void main() {}
Dart
main() { }
Delphi
- See Pascal
E
The shortest possible program:
This is equivalent to: null
eC
or class EmptyApp : Application { void Main() { } }==Eiffel== A file called main.e: class MAIN
create main feature main do end
end==Erlang== An empty module: -module(empty). An empty Erlang script file (escript): main(_) -> 1.
eSQL
CREATE COMPUTE MODULE ESQL_Compute CREATE FUNCTION Main() RETURNS BOOLEAN BEGIN RETURN TRUE; END; END MODULE;
Euphoria
==F#== F# has an interactive mode and a compiled mode. The interactive interpreter will accept an empty file so the shortest valid program is an empty zero-length file with the .fsx extension. An empty compiled program is: [] let main args = 0
Factor
If you want to deploy a stand-alone application, that doesn't suffice though. Here's another version. IN: rosetta.empty : main ( -- ) ; MAIN: main
Falcon
> Prints an empty line. >> Prints nothing.
FALSE
==Fantom== class Main {
public static Void main () {}
}==Fish== Actually the shortest valid program is a space (not empty file!), which is an infinite loop, though. (It keeps looping around) An empty program is invalid; the interpreter will give an error. The shortest program that will actually finish is a ;, which will end the program immediately:
Forth
For a Forth script to be used from a shell, you usually want the last command to be BYE in order to exit the interpreter when finished. bye==Fortran== end==Frink== Empty programs are valid.
==Gecho== Empty programs are valid.
==Gema== An empty program will copy input stream to output stream unchanged.
Genyris
Go
package main func main() { }
Groovy
==Haskell== Standard: Haskell 98 The simplest possible program is a single module using the implicit module header "module Main(main) where", and defining the action main to do nothing: main = return ()The simplest possible module other than Main is one which contains no definitions: module X where {}
haXe
class Program {
static function main() { }
}Unlike most languages haXe doesn't have arguments in the main function because it targets different platforms (some which don't support program arguments, eg: Flash or Javascript). You need to use the specific libraries of the platform you are targeting to get those. ==HicEst== END ! looks better, but is not really needed==HQ9+== An empty file is a valid HQ9+ program that does nothing. ==Icon and Unicon== procedure main() # a null file will compile but generate a run-time error for missing main end
IDL
end
Intercal
PLEASE GIVE UP
Io
J
It returns itself:
-: ".
1
Java
public class EmptyApplet extends java.applet.Applet { @Override public void init() { } }
public class EmptyMainClass { public static void main(String... args) { } }The "..." basically means "as many of these as the programmer wants." Java will put multiple arguments into an array with the given name. This will work for any method where an array is an argument, but with a twist. A call can be made like this: method(arg0, arg1, arg2, arg3)All of the args will be put into an array in the order they were in the call.
public class EmptyMainClass { public static void main(String[] args) { } }
public class EmptyApplet extends java.applet.Applet { public void init() { } }@Override - Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message. It's present from JDK 5.0 (1.5.0) and up. Actually this is not strictly correct. The smallest possible correct program in Java is an empty source file. ==JavaScript== The empty file is a valid program.
Joy
K
KonsolScript
function main() {
}
Liberty BASIC
end==Lisp== Most Lisp dialects, including Common Lisp, will accept no text (no forms) as a valid program.
Logo
or end a standalone script with "bye" #! /usr/local/bin/logo
bye==LSE64== As with Forth, an empty file is the shortest program. To exit the interpreter at the end of a loaded file: bye ==Lua==
M4
Mathematica
MATLAB
function [varargout] = emptyprogram(varargin)
==MAXScript== An empty MAXScript file returns "OK" on execution ==Metafont== end
ML/I
MMIX
LOC #100 Main TRAP 0,Halt,0 // main (argc, argv) {}
Modula-2
MODULE Main;
BEGIN END Main.
Modula-3
MODULE Main;
BEGIN END Main.==MUMPS== The empty file is a valid program.
Nemerle
Compiles with warnings: null Compiles without warnings (so, more correct): module Program {
Main() : void { }
}==NetRexx== The following two samples both generate valid programs. This minimal example requires that the file be named to match the class: class emptyThis example will generate it's class based on the file name: method main(args = String[]) static==NewLISP== ;
Nimrod
Objeck
bundle Default { class Empty { function : Main(args : String[]) ~ Nil { } }
Objective-C
int main(int argc, const char **argv) {
return 0;
}The minimal empty Cocoa/OpenStep application, useful as life-support for many examples given at RosettaCode, is #import
int main( int argc, const char *argv[] ) {
NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; NSApp = [NSApplication sharedApplication]; [pool release]; return 0;
}
OCaml
- Actually, the smallest possible correct program in OCaml is an empty source file. ==Octave== An empty text file can be a valid empty program, but since Octave has the concept of "function file" (a file containing a single function; the file is automatically loaded when a function with the same name of the file, save for the extension, is called, and the first function present in the file is used), the name of the empty file matters. E.g. calling an empty file as isempty.m makes unusable the builtin isemptyfunction. ==Oz== === REPL === The simplest program that can be evaluated in the REPL (Emacs mode) is the empty program.
=== Accepted by compiler === The simplest 'program' that can be compiled is a file which contains a single expression. unitSuch a 'program' cannot be executed, though. === Standalone === The simplest standalone program is a root functor that does not define anything. ("Functors" are first-class modules.) functor define
skip
end
PARI/GP
Pascal
program ProgramName;
begin end.The first line is not necessary in modern Pascal dialects. With today's most compilers, the empty program is just: begin end.
Perl
- !/usr/bin/perl
1;
- !/usr/bin/perl
exit;
- !/usr/bin/perl
- A program without a body will work too
- !/usr/bin/perlThe smallest possible program is an empty file (zero length). This requires you to specify the interpreter instead of relying on the shell's shebang magic, thus: perl empty.pl. The smallest possible Perl one-liner is perl -e0. ==Perl 6== The empty program is valid and does nothing but return a successful exit code. ==PHP== An empty text file is a correct PHP program that does nothing. ==PicoLisp== (de foo ())==PIR== The :main pragma indicates that a subroutine is the program's entry point. However, if a subroutine is the first (or only, which would also have the effect of making it the first) routine in the program, Parrot will use that. So we may comfortably omit it in this case. .sub empty_program .end
Pike
int main(){}
PL/I
s: proc options (main); end;
PL/SQL
BEGIN
NULL;
END;==Pop11== Pop11 has two compilers, incremental and batch compiler. For the incremental compiler one can use just empty program text (empty file), or a file containing nothing but a comment, e.g. ;;; This is a valid Pop11 program that does absolutely nothing.The batch compiler generates an executable which starts at a given entry point, so one should provide an empty function. If one wants program that works the same both with incremental compiler and batch compiler the following may be useful: compile_mode :pop11 +strict; define entry_point(); enddefine;
- _TERMIN_IF DEF POPC_COMPILING
entry_point();Here the batch compiler will stop reading source before call to entry_point while incremental compiler will execute the call, ensuring that in both cases execution will start from the function entry_point. ==PostScript== An empty file is a valid PostScript program that does nothing. Following good programming practice, however, and to ensure that a PostScript printer will interpret a file correctly, one should make the first 4 characters of the file be %!PSIf a particular version of the PS interpreter is needed, this would be included right there: %!PS-2.0 % ...or... %!PS-3.0 % etc==PowerShell== An empty text file is a correct Powershell script that does nothing. ==PSQL== EXECUTE BLOCK AS BEGIN END==ProDOS== This is an acceptable program: IGNORELINE But also you could include a delimiter character recognized by the compiler/interpreter:
- ==PureBasic== An empty file is a correct PureBasic program that does nothing.
==Python== An empty text file is a correct Python program that does nothing. ==R== An empty text file is a valid empty program ==Raven== An empty text file is an empty program. ==REBOL== The header section is mandatory if you want it to be recognized as a REBOL program. It doesn't have to be filled in though: REBOL []==Retro== An empty file is the smallest valid program.
To save an application doing nothing, you need to do a bit more work though: &bye is boot
REXX
===version 1=== An empty file is a valid empty program; however, for some REXX implementation the first two characters must be /*(i.e. the first line must be a comment) in order to recognize the file as a REXX script: /* empty */
version 2
/**/
version 3
REXX on MVS/TSO requires REXX to be in the first line:
/* REXX */
==Rhope==
Main(0,0) |: :| ==Ruby== An empty file is a valid Ruby program. However, in order to make it runnable on *nix systems, a shebang line is necessary: #!/usr/bin/env ruby
Scala
object emptyProgram { def main(args: Array[String]) {} }
Scheme
Seed7
$ include "seed7_05.s7i"; const proc: main is noop;
Slate
Smalltalk
[]==SNUSP== $# $ sets the instruction pointer (going right), and # halts the program (empty stack). ==SNOBOL4== A valid program requires an end label. The shortest (virtually empty) program is then: end==Standard ML== ;Actually, the smallest possible correct program in Standard ML is an empty source file. ==Suneido== function () { }==Tcl== Nothing is mandatory in Tcl, so an empty file named nothing.tclwould be a valid "empty program".
Toka== For interpreted code, nothing is required, although bye is necessary for an empty script to exit (rather than wait for the user to exit the listener). Hence: bye Or, for a directly runnable script: #! /usr/bin/toka bye For compiled code, the simplest program is an empty quote: [ ] Again, to exit the listener, you will still need user input if this is not followed with bye. ==TI-83 BASIC== : ==TI-89 BASIC== Prgm EndPrgm ==Trith
TUSCRIPT
$$ MODE TUSCRIPT
UNIX Shell
- !/bin/sh
- !/bin/bash==Unlambda== i (See how i plays so many roles in unlambda?) ==VBScript== An empty .vbs file is considered the smallest runnable code, but the following (a single apostrophe as comment marker) would also be acceptable (along with other non-executing instructions like option explicit.)
'==VHDL== Compiled and simulated by Modelsim: entity dummy is end; architecture empty of dummy is begin end;==Visual Basic .NET==
Module General
Sub Main() End Sub
End Module
X86 Assembly
section .text global _start
_start: mov eax, 1 int 0x80 ret
.386 .model flat, stdcall option casemap:none
.code start: ret end start
XQuery
.The dot selects the current context node and returns it unchanged. ==XSLT==
Add other namespaces to the stylesheet attributes (like xmlns:fo="http://www.w3.org/1999/XSL/Format") if you use them. Since XSLT is XML, and transform is a synonym for stylesheet, the example above can be minified to:
This stylesheet echoes the text content of an XML file. The shortest stylesheet without any output would be
==xTalk==
on startup end startup ==Yorick== An empty file is valid and does nothing.
=Markup Languages= ==HTML== HTML 5, section 11.1.2.4 Optional tags, allows to omit html, head and body tags. The implicit body element can be empty, but the implicit head element must contain a title element, says section 4.2.1 The head element. There seems no rule against an empty title. Therefore, the shortest correct HTML document is:
The shortest correct XHTML document is:
- Programming Tasks
- Basic language learning
- Ada
- Agena
- ALGOL 68
- AmigaE
- AppleScript
- Argile
- AutoHotkey
- AutoIt
- AWK
- BASIC
- Batch File
- BBC BASIC
- Befunge
- Bracmat
- Brainf***
- Brlcad
- C
- C sharp
- C++
- Clean
- Clojure
- CoffeeScript
- D
- Dart
- Delphi
- E
- EC
- Eiffel
- Erlang
- ESQL
- Euphoria
- F Sharp
- Factor
- Falcon
- FALSE
- Fantom
- Fish
- Forth
- Fortran
- Frink
- Gecho
- Gema
- Genyris
- Go
- Groovy
- Haskell
- HaXe
- HicEst
- HQ9+
- Icon
- Unicon
- IDL
- Intercal
- Io
- J
- Java
- JavaScript
- Joy
- K
- KonsolScript
- Liberty BASIC
- Lisp
- Common Lisp
- Logo
- LSE64
- Lua
- M4
- Mathematica
- MATLAB
- MAXScript
- Metafont
- ML/I
- MMIX
- Modula-2
- Modula-3
- MUMPS
- Nemerle
- NetRexx
- NewLISP
- Nimrod
- Objeck
- Objective-C
- OCaml
- Octave
- Oz
- PARI/GP
- Pascal
- Perl
- Perl 6
- PHP
- PicoLisp
- PIR
- Pike
- PL/I
- PL/SQL
- Pop11
- PostScript
- PowerShell
- PSQL
- ProDOS
- PureBasic
- Python
- R
- Raven
- REBOL
- Retro
- REXX
- Rhope
- Ruby
- Scala
- Scheme
- Seed7
- Slate
- Smalltalk
- SNUSP
- SNOBOL4
- Standard ML
- Suneido
- Tcl
- Toka
- TI-83 BASIC
- TI-89 BASIC
- Trith
- TUSCRIPT
- UNIX Shell
- Unlambda
- VBScript
- VHDL
- Visual Basic .NET
- X86 Assembly
- XQuery
- XSLT
- XTalk
- Yorick
- HTML