Empty program

From Rosetta Code
Jump to: navigation, search
Empty program
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."


[edit] Programming Languages

[edit] 360 Assembly

Return to caller

         BR    14           

[edit] 8051 Assembly

Continuously loops.

jmp $

[edit] Ada

Works with: GCC version 4.1.2
procedure Empty is 

[edit] Agena

Actually nothing is valid code, too.


[edit] Aime

The nil input is a valid program.


[edit] ALGOL 60


[edit] ALGOL 68

[edit] Brief form


[edit] BOLD form


[edit] ALGOL W

begin end.

[edit] AmigaE

PROC main()

[edit] AppleScript

An empty .scpt file is considered the smallest runnable code, but the following would also be acceptable.


[edit] Argile

The empty string or file are valid and do nothing.


[edit] ARM Assembly

GNU/Linux RaspberryPi example.

.global _start
mov r0, #0
mov r7, #1
svc #0

[edit] AutoHotkey

An empty script would be enough. Adding "#Persistent" makes it persistent.


[edit] AutoIt

A single comment can be considered a valid program that does nothing.


[edit] AWK

The empty string (or file) is recognised as valid program that does nothing.

The program


is the simplest useful program, equivalent to

// {print}

I.e. match every input-line, and print it.
Like the UNIX command 'cat', it prints every line of the files given as arguments, or (if no arguments are given) the standard input.

[edit] Axe

Most Axe examples omit the executable name, but it is shown in this example for completeness.


[edit] BASIC

Works with: QBASIC
Works with: Quick BASIC
Works with: FreeBASIC

An empty file is a correct program. It won't be near empty as an executable file, though.

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:

0 OK, 0:1

[edit] Applesoft BASIC


[edit] Batch File

On Windows XP and older, 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. Some valid characters are : @ %


[edit] BBC BASIC

In BBC BASIC an empty program is syntactically correct.


[edit] bc

An empty file is a valid program.

[edit] Befunge


The halt command @ is required because code wraps around. An empty file would be an infinite loop.

[edit] 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$empty

If we drop the requirement that the shortest program is stored in a file, we can do

bracmat ''

(Linux) or

bracmat ""


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.

[edit] Brainf***

Empty program

Note: this works as all non-instruction characters are considered comments. Alternatively, a zero-byte file also works.

[edit] 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

[edit] C

Works with: C89
return 0;

As of C99 the return type is required, but the return statement is not.

Works with: C99
int main() { }

[edit] C#

class Program
static void Main()

[edit] C++

Works with: g++ version 4.8.1
int main(){}

[edit] Clean

module Empty
Start world = world

Compile the project with No Console or No Return Type to suppress printing of the value of the world.

[edit] Clojure

An empty file is the simplest valid Clojure program.

[edit] COBOL

Works with: OpenCOBOL version 2.0

[edit] CoffeeScript


[edit] Common Lisp


[edit] Component Pascal

BlackBox Component Builder;

END Main.

[edit] D

void main() {}

[edit] Dart

main() {

[edit] dc

An empty file is a valid program.

[edit] DCL

An empty file is a valid program.

[edit] Déjà Vu


Shortest module that works with !import:


[edit] Delphi

See Pascal

[edit] E

The shortest possible program:

This is equivalent to:


[edit] eC


class EmptyApp : Application
void Main()

[edit] EchoLisp


[edit] EGL

General program

package programs;
program Empty_program type BasicProgram {}
function main()

Rich UI handler (but also without 'initialUI = [ ui ], onConstructionFunction = start' it would have been valid.)

package ruihandlers;

import com.ibm.egl.rui.widgets.Div;

handler Empty_program type RUIhandler {initialUI = [ ui ], onConstructionFunction = start}
	ui Div{};
	function start()

[edit] Eiffel

A file called root.e:


[edit] Elixir


[edit] Erlang

An empty module:


An empty Erlang script file (escript):

main(_) -> 1.

[edit] ERRE


[edit] eSQL


[edit] Euphoria


[edit] 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

[edit] 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

[edit] Falcon


Prints an empty line.


Prints nothing.

[edit] FALSE


[edit] Fantom

class Main
public static Void main () {}

[edit] FBSL

An empty string is a valid FBSL script in both uncompiled and compiled form. It won't however produce any visible output on the screen. The minimum implementations for the user to see the result are presented below:

Console mode:



Press any key to continue...

Graphics mode:

SHOW(ME) ' all FBSL scripts are #APPTYPE GUI on default

Output: GUI Form

Minimum empty Dynamic Assembler block:


RET ; mandatory


Minimum empty Dynamic C block:

DYNC Foo()

void main(void)
return; // optional


[edit] 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:


[edit] 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.


[edit] Fortran


[edit] friendly interactive shell

Empty programs are valid, but are useless.


[edit] Frink

Empty programs are valid.


[edit] FunL

An empty text file is a valid FunL program that does nothing.


[edit] Gecho

Empty programs are valid.


[edit] Gema

An empty program will copy input stream to output stream unchanged.


[edit] Genyris

[edit] Go

package main
func main() { }

[edit] Groovy


[edit] 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 {}

[edit] 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.

[edit] HicEst

END ! looks better, but is not really needed

[edit] HQ9+

An empty file is a valid HQ9+ program that does nothing.

[edit] Icon and Unicon

procedure main()   # a null file will compile but generate a run-time error for missing main

[edit] IDL


[edit] Intercal


[edit] Io

[edit] J


It returns itself:

   '' -: ". ''

[edit] Java

Works with: Java version 1.5+
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.

Works with: Java version 1.0+
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.

[edit] JavaScript

The empty file is a valid program.

[edit] Joy


[edit] Jq

The “empty” filter ignores its input and outputs nothing.


[edit] Julia

Julia accepts an empty file as a program.

$ wc empty_program.jl
0 0 0 empty_program.jl
$ julia empty_program.jl

[edit] K


[edit] KonsolScript

function main() {

[edit] Lang5


[edit] Lasso

Lasso will parse any file thrown at it. It will ignore everything except what's inside specific Lasso delimiters. Thus a valid program that did nothing, could be an empty file. Perhaps more correct would be a file that had the specific delimiters and then nothing inside them.

<?lasso  ?>
<?=  ?>

[edit] Liberty BASIC


[edit] Lilypond

According to the manual, all lilypond programs should contain a version statement expressing the minimum version number. If this is missing then a warning will be emitted.

\version "2.6.12"

An input file should really have a basic structure as follows. The compiler automatically adds some of the structure components if they are not present in the source code. However, explicit definition should be used to prevent the compiler from creating unwanted contexts (which can cause side effects):

\version "2.16.2"
\header {
\book {
\score {
\new Staff {
\new Voice {
\layout {

[edit] Lisp

Most Lisp dialects, including Common Lisp, will accept no text (no forms) as a valid program.




or end a standalone script with "bye"

#! /usr/local/bin/logo

[edit] LSE64

As with Forth, an empty file is the shortest program. To exit the interpreter at the end of a loaded file:


[edit] Lua


[edit] M4


[edit] Maple


[edit] Mathematica / Wolfram Language


[edit] MATLAB

 function [varargout] = emptyprogram(varargin) 

[edit] Maxima


[edit] MAXScript

An empty MAXScript file returns "OK" on execution

[edit] Metafont


[edit] МК-61/52


[edit] ML/I


[edit] MMIX

	LOC	#100
Main TRAP 0,Halt,0 // main (argc, argv) {}

[edit] Modula-2

END Main.

[edit] Modula-3

END Main.

[edit] MUMPS

The empty file is a valid program.

[edit] Nemerle

Compiles with warnings:


Compiles without warnings (so, more correct):

module Program
Main() : void

[edit] NetRexx

The following two samples both generate valid programs.

This minimal example requires that the file be named to match the class:

class empty

This example will generate its class based on the file name:

method main(args = String[]) static

[edit] NewLISP


[edit] Nim

[edit] Nit

Although a Nit module (file) usually include a module declaration, an empty module is a valid Nit program.

[edit] Objeck

bundle Default {
class Empty {
function : Main(args : String[]) ~ Nil {

[edit] Objective-C

Works with: gcc version 4.0.1
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 <Cocoa/Cocoa.h>
int main( int argc, const char *argv[] )
@autoreleasepool {
[NSApplication sharedApplication];
return 0;

[edit] OCaml

Works with: Ocaml version 3.09

Actually, the smallest possible correct program in OCaml is an empty source file.

[edit] 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 isempty function.

[edit] Oforth

An empty file is a valid oforth file

oforth empty.of

Without file, interpreter can just evaluate bye :

oforth --P"bye"

[edit] OOC

The Compiler will accept an empty file:


[edit] OxygenBasic

The smallest possible program is a single space character:


[edit] Oz

[edit] Accepted by compiler

The simplest 'program' that can be compiled is a file which contains a single expression.


Such a 'program' cannot be executed, though.

[edit] Standalone

The simplest standalone program is a root functor that does not define anything. ("Functors" are first-class modules.)


[edit] PARI/GP


[edit] Pascal

program ProgramName;

The first line is not necessary in modern Pascal dialects. With today's most compilers, the empty program is just:

begin end.

[edit] Perl

Works with: Perl version 5.8.8
# A program without a body will work too

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.

[edit] Perl 6

The empty program is valid and does nothing but return a successful exit code.

It is also possible to just specify that the program is written in Perl6:

use v6;

or, for relax mode (not yet implemented in rakudo, though):


or even:


[edit] Phix


[edit] PHP

An empty text file is a correct PHP program that does nothing.

[edit] PicoLisp

(de foo ())

[edit] Pike

int main(){}

[edit] 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

[edit] PL/I

s: proc options (main);

[edit] PL/SQL


[edit] 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();

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.

[edit] 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


If a particular version of the PS interpreter is needed, this would be included right there:

% ...or...
% etc

[edit] PowerShell

An empty text file is a correct Powershell script that does nothing.

[edit] ProDOS

This is an acceptable program:


But also you could include a delimiter character recognized by the compiler/interpreter:


[edit] PSQL


[edit] PureBasic

An empty file is a correct PureBasic program that does nothing.


[edit] Python

An empty text file is a correct Python program that does nothing.



[edit] R

An empty text file is a valid empty program

[edit] Racket

The following shows an empty program in Racket's default language. Other Racket languages may impose different conditions on the empty program.

#lang racket

[edit] Raven

An empty text file is an empty program.

[edit] 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 []

[edit] 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

[edit] REXX

An empty (or blank) file is a valid REXX program.

[edit] version 0


[edit] version 1

However, for some REXX implementations the first line has to begin with a REXX comment (that is,   /*   --- namely a slash followed by an asterisk)   in order to recognize that the file is a REXX script/EXEC/program:


Some environments   (TSO under "MVS", certain IBM SAA environments, and possibly others)   require that the first line begin with a (REXX) comment, and the (four) letters   REXX   be somewhere on the first line (within the comment).
The   REXX   character string may be in any case (lower/upper/mixed) and cannot contain imbedded whitespace.

SAA:   (IBM's)   Systems Application Architecture

[edit] version 2


[edit] version 3

REXX on MVS/TSO requires REXX to be in within a REXX comment that begins on the first line:

/*this REXX program calculates if a date is a workday for the XYZ Company.*/

[edit] Rhope

Works with: Rhope version alpha 1
|: :|

[edit] 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

[edit] Rust

fn main(){}

[edit] Scala

object emptyProgram extends App {}

[edit] Scheme


[edit] Scilab


[edit] Seed7

$ include "seed7_05.s7i";
const proc: main is noop;

[edit] Sidef


[edit] Simula

Works with: SIMULA-67

[edit] Slate


[edit] Smalltalk


[edit] SNOBOL4

A valid program requires an end label. The shortest (virtually empty) program is then:


[edit] SNUSP


$ sets the instruction pointer (going right), and # halts the program (empty stack).

[edit] Sparkling


[edit] Standard ML


Actually, the smallest possible correct program in Standard ML is an empty source file.

[edit] Suneido

function () { }

[edit] Swift


[edit] Tcl

Nothing is mandatory in Tcl, so an empty file named nothing.tcl would be a valid "empty program".


[edit] TI-83 BASIC


Displays "Done". If an empty program isn't valid, there are numerous other one-byte solutions:


[edit] TI-89 BASIC


[edit] 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:


Or, for a directly runnable script:

#! /usr/bin/toka

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.

[edit] Trith




[edit] UNIX Shell

Works with: Bourne Shell
Works with: Bourne Again SHell

[edit] Unlambda


(See how i plays so many roles in unlambda?)

[edit] 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.)


[edit] VHDL

Compiled and simulated by Modelsim:

entity dummy is
architecture empty of dummy is

[edit] Vim Script

An empty file is a valid program.

[edit] Visual Basic

Works with: VB6

Sub Main()
End Sub

[edit] Visual Basic .NET

Works with: Visual Basic .NET version 2005
Module General
Sub Main()
End Sub
End Module

[edit] Wart

[edit] X86 Assembly

Works with: NASM version Linux
section .text
global _start
mov eax, 1
int 0x80
Works with: MASM
.model flat, stdcall
option casemap:none
end start

[edit] XPL0

An empty file compiles and builds an EXE file with a single RET instruction, but of course does nothing when executed.

[edit] XQuery


The dot selects the current context node and returns it unchanged.

[edit] 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 -->

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:

<transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"/>

This stylesheet echoes the text content of an XML file. The shortest stylesheet without any output would be

<transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<template match="/" />

[edit] xTalk

Works with: HyperCard
on startup
end startup

[edit] XUL

<?xml version="1.0"?>

[edit] Yorick

An empty file is valid and does nothing.

[edit] Z80 Assembly


[edit] zkl

An empty file/string is valid.

c() //--> Class(RootClass#)

[edit] Markup Languages

[edit] HTML

HTML 5, section 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:

<!DOCTYPE html><title></title>

The shortest correct XHTML document is:

<html xmlns="http://www.w3.org/1999/xhtml"><head><title /></head><body /></html>

[edit] LaTeX


[edit] plainTeX

Personal tools