Jump to content

Empty program

From Rosetta Code
Task
Empty program
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Create the simplest possible program that is still considered "correct."

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

Return to caller

         BR    14           
         END

4ME v1/Rewriten 4ME

An empty .wm (.4 if your programing in Rewriten 4ME) file is considerd as a valid 4ME program.

4ME v1.1

There are two ways to make an empty program in 4ME

P:
E:

or

P:

and if you try to remove the P: command. The interpriter will emit:

S1245
P: IS MISSING

Commodore 64

org $0801                                                      ;start assembling at this address
db $0E,$08,$0A,$00,$9E,$20,$28,$32,$30,$36,$34,$29,$00,$00,$00 ;required init code
rts                                                            ;return to basic

Nintendo Entertainment System

Without an infinite loop the program counter will execute undefined behavior, depending on how "empty" bytes are padded. If we're generous and assume that empty bytes are padded with NOP, eventually the program counter will attempt to execute the interrupt vectors as executable code. If we assume that an "empty program" needs to not crash (even though you really can't tell the difference with nothing on screen), we need a way to "trap" the program counter.

.org $8000                                                     ;usually $8000 but it depends on the mapper.
RESET:                                                         ;execution starts here
JMP RESET  


NMI:                                                           ;NMI can't happen if the screen is off. No need for RTI

IRQ:                                                           ;this will never occur without a CLI command.

.org $FFFA 
;all 6502 based hardware uses this section of memory to hold the addresses of interrupt routines
;as well as the entry point.
dw NMI   ;FFFA-FFFB
dw RESET ;FFFC-FFFD ;this has to be defined or else the program counter will jump to an unknown location
dw IRQ   ;FFFE-FFFF

This mostly depends on the implementation, but JMP * will typically suffice for embedded hardware.

NEOGEO

After you get to the main program, you'll need to kick the watchdog every frame to prevent the BIOS from resetting the machine. This is done by writing any byte to memory address 0x00300001. Other than that, an endless loop will suffice (assuming you have a proper cartridge header and a vBlank routine that does nothing except check for bios vblank and return.)

forever:
MOVE.B D0,$300001
JMP forever

Continuously loops.

ORG RESET 
jmp $

Boot Sector Program

main segment
start:
jmp start        ;2 bytes
padding byte 508 dup (90h)
bootcode byte 55h,0AAh
main ends

If your assembler assembles the code above as an EXE file, you'll need to use a hex editor to strip the EXE header so that it fits exactly into 512 bytes.


16-Bit x86 for EXE Files

.model small  ;.exe file
.stack 1024   ;this value doesn't matter, I chose this arbitrarily
.data
              ;not needed in an empty program
.code
mov ax,4C00h
int 21h       ;exit this program and return to MS-DOS

32-Bit x86

end

However, if the program needs to exit with an exit code of zero:

    segment .text
    global _start

_start:
    mov eax, 60
    xor edi, edi
    syscall
    end

Simulates system call exit(0). In AArch64, the system call number is passed via x8, and the syscall number for exit is 93.

.text
.global _start

_start:
        mov x0, #0
        mov x8, #93
        svc #0

ArkScript source files must contain at least one valid node. The smallest one that does nothing is the begin node.

{}

Which can also be written

(begin)

Note that the statement "start-of-selection." is implicitly added. This event block needs to be present in executable programs, it's comparable to the main function in other programming languages.

report z_empty_program.
Output:

Screenshot from Atari 8-bit computer

Works with: GCC version 4.1.2
procedure Empty is 
begin 
   null; 
end;

Actually nothing is valid code, too.

The nil input is a valid program.

'BEGIN' 'END'

Brief form

~

BOLD form

SKIP

In Algol W, a blank statement is a valid statement and a program is a statement followed by a dot. Hence "." is the smallest valid program.

.
PROC main()
ENDPROC

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

return

The empty string or file are valid and do nothing.

GNU/Linux RaspberryPi

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

Game Boy Advance

The Nintendo logo is loaded from the cartridge, and the Game Boy Advance's firmware won't boot the game without it. So an empty program can't be run at all. Thus a minimum of a valid cartridge header is required for an empty program that the Game Boy Advance can actually run. The first four bytes of the cartridge header are an unconditional branch instruction to the program's start. Simply duplicate this instruction at that address and voila:

ProgramStart:
b ProgramStart ;don't do this on a real game boy, you'll drain the batteries faster than usual.

Hardware interrupts will not occur if you never enable them, so there is no need to store the interrupt service procedure's address in address $03FFFFFC to prevent a crash. The Game Boy Advance has no "exit" SWI call (the closest is the undocumented hard reset) so this is as close as you can get.

IT'S SHOWTIME
YOU HAVE BEEN TERMINATED

A completely empty script is a valid Arturo program.

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

#Persistent

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

;nothing

Avail files require a header block (that is generally omitted from the examples here). The shortest valid header would only include the module name, which can be reduced to 1 character, assuming the filename is set to match. For "a.avail", this gives the empty program:

Module "a"
Body

This can be further shortened by removing unambiguous whitespace to:

Module"a"Body

For all practical purposes, this header is useless in any other program. It does not import the standard library "Avail" (or any alternatives), so it has access to no methods, types, or values. Here's a short program capable of output:

Module"a"Uses"Avail"Body Print:"!";

Or with more traditional spacing:

Module "a"
Uses "Avail"
Body
Print:"!";

Note however that this output is only available as a compile-time side effect. A program defining a run-time entry point would include an Entries header section, or export its content for an entry point in another module to run.

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

The program

    1

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.

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

:.PRGMNAME
:

A program consisting of an empty .bal file compiles and runs fine.

Works with: QBASIC
Works with: Quick BASIC
Works with: FreeBASIC
Works with: uBasic/4tH

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:

RUN
0 OK, 0:1

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 : @ %

:

In BaCon an empty program is a valid program.

In BBC BASIC an empty program is syntactically correct.

An empty file is a valid program.

At 4 bits, or half a byte, the smallest BLC program is `cat' :

00 10

corresponding to the smallest valid lambda term, the identity function \x.x

using System;
class Program
{
  public static void Main()
  {
  }
}
*

(create 6 bees moving in all 6 cardinal directions) or

\

(create 2 bees moving in “northwest” and “southeast” directions) or

_

(create 2 bees moving left and right) or

/

(create 2 bees moving in “northeast” and “southwest” directions)

A valid beeswax program needs at least one of these bee spawning symbols, as a program without bees is not executable. All bees that step off the honeycomb (program area) are automatically deleted, and the program ends if no bees are left.

@

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

An empty program in BQN produces an error. There must be at least one line which returns a value.

Any valid literal works to make a program run. The shortest way is to use a single digit, or a predefined constant, like π or .


Try It!

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 ""

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

Empty program

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

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

The smallest program in bruijn is the identity function (\x.x) and returns its input:

main [0]

C

Works with: C89
main()
{
  return 0;
}

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

Works with: C99
int main() { }

This is technically undefined behavior but on 8086 compatible processors 195 corresponds to the ret assembly instruction.

const main = 195;

As of C# 9.0, an empty text file is a correct C# program that does nothing.

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

Prints nothing.

module Empty

Start world = world

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

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

An empty file is the simplest valid Clojure program.

This is the shortest program that actually produces a working executable (that does nothing).

start_up = proc () 
end start_up

Portable CLU will compile the empty file without complaint, but not produce an object file.

Works with: OpenCOBOL version 2.0
()
.

BlackBox Component Builder;

MODULE Main;
END Main.

The smallest legal program is a single Stop instruction.

        STP

D

void main() {}
main() {}

An empty file is a valid program.

An empty file is a valid program.

See Pascal

"Nothing will come of nothing."

$ duckdb < /dev/null
$ echo '' | duckdb
$ duckdb -c ''
$

Dyalect is not very happy with a completely empty source code file, however a pair of curly brackets would do:

{}

This program would evaluate and return "nil".

DuckDB handles a null or empty program graciously:

$ duckdb < /dev/null
$ echo "" | duckdb 
$

A good candidate for the simplest non-empty program would be the `.quit` command:

$ duckdb <<< .quit
$

Shortest module that works with !import:

{}

E

The shortest possible program:


This is equivalent to:

null
#

or

class EmptyApp : Application
{
    void Main()
    {

    }
}
module EmptyProgram {
    void run() {
    }
}


The smallest program that will load and run without error. Apart from ZF, the 'stop' order, it consists solely of directives to the loader.

T64K  [ set load point ]
GK    [ set base address ]
ZF    [ stop ]
EZPF  [ begin at load point ]

The smallest program contains nothing.

General program

package programs;

program Empty_program type BasicProgram {}
	function main()
	end
end

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()
	end	
end

A file called root.e:

class
    ROOT

create
    make

feature
    make
        do
           
        end
end

ELENA 4.x

public program()
{
}
--Language prints the text in " "
import Html
main =
 Html.text"empty"

The empty script is valid and does nothing.

An empty module:

-module(empty).

An empty Erlang script file (escript):

main(_) -> 1.
PROGRAM EMPTY
BEGIN
END PROGRAM
CREATE COMPUTE MODULE ESQL_Compute
  CREATE FUNCTION Main() RETURNS BOOLEAN
  BEGIN
    RETURN TRUE;
  END;
END MODULE;

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:

[<EntryPoint>]
let main args = 0

If you want to deploy a stand-alone application, that doesn't suffice though. Here's another version.

IN: rosetta.empty
: main ( -- ) ;
MAIN: main
>

Prints an empty line.

>>

Prints nothing.

class Main
{
  public static Void main () {}
}

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:

#APPTYPE CONSOLE
PAUSE

Output:

Press any key to continue...

Graphics mode:

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

Output: GUI Form

Minimum empty Dynamic Assembler block:

DYNASM Foo()

RET ; mandatory

END DYNASM

Minimum empty Dynamic C block:

DYNC Foo()

void main(void)
{
return; // optional
}

END DYNC

;

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:

;

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
       end

A completely empty program compiles and runs fine:

Empty programs are valid, but are useless.

Empty programs are valid.

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

Any Futhark program must have a main function. Alternatively, a Futhark library can be an empty file.

let main = 0
HandleEvents

Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.

Programs in Fōrmulæ are created/edited online in its website.

In this page you can see and run the program(s) related to this task and their results. You can also change either the programs or the parameters they are called with, for experimentation, but remember that these programs were created with the main purpose of showing a clear solution of the task, and they generally lack any kind of validation.

Solution

The following is the simplest expression: the Null expression. When it is run, it does not reduce to anything else, because there should not be rewriting rules for a null expression:

Public Sub Main()
End

Empty programs are valid.

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



This program is intended for use with the HS Global Script and uses its syntax for imperative programs.

λ _. impunit 〈〉
package main
func main() { }

Just prints the input (appended w/ a newline).


Output:
% echo Hello world! | ruby gs.rb empty.gs
Hello world!

% ruby gs.rb empty.gs

% ruby gs.rb empty.gs | wc -c
       1

An empty text file is a correct GW-BASIC program that does nothing.

export fn main() void = void;

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 {}
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.

END ! looks better, but is not really needed

An empty file is the simplest valid HolyC program and returns 0.

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

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

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

The shortest correct XHTML document is:

<html xmlns="http://www.w3.org/1999/xhtml"><head><title /></head><body /></html>
main(){}

i

software{}
record main()

This program creates an empty record of type main and exits. An empty file will compile but generate a run-time error for missing a main procedure. This solution comes from here.

end
X is a room

Inform 7 is a language built for making interactive fiction, so a room needs to be defined for the player to start in.

PLEASE GIVE UP

J

''

It returns itself:

   '' -: ". ''
1
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.

The empty file is a valid program.



.

A program in Joy is a sequence of zero or more factors followed by a full stop.

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

empty

Julia accepts an empty file as a program.

Output:
$ wc empty_program.jl
0 0 0 empty_program.jl
$ julia empty_program.jl
$

K

function main() {
  
}

The empty string is the smallest program.

fun main() {}

An empty string is a valid program.

The empty file is a valid program.



exit

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  ?>
<?=  ?>
\documentclass{minimal}
\begin{document}
\end{document}

The only thing you absolutely need is a directive telling the assembler to stop assembling code (which in this case it has not actually started doing).

        .END
end

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 {

    }
  }
}

"Program" doesn't really apply to Lingo. A Director projector (exe/app) doesn't have to contain any scripts/code. For scripts, the shortest possible code is:

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

V1.3 of Peter Higginson's implementation of Little Man Computer accepts an empty program. If it is assembled then ran in it, a single fetch cycle is performed, which adds 1 to the program counter, which was previously 0, then the address register then the instruction register, both of which were previously blank, are changed to 0. Similar behavior is seen in 101 Computing's implementation of Little Man Computer, in which all CPU registers start at 00, then the program counter changes to 1, the MAR to 0 and the MDR and CIR to 000.

Assembly

HLT
or
COB

Machine code

0

or end a standalone script with "bye"

#! /usr/local/bin/logo

bye

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

bye

Open M2000 Environment, type Edit A and place one space or insert a new line, then exit pressing Esc and write Save Empty (press enter). Now write New (press enter). Now write Load Empty (press enter) and execute it: write A (press enter). Now you can close environment: write End (press enter).

To open file Empty.gsb, as text file (without loading to list of modules) use Edit "Empty.Gsb". To open it in notepad, we can use this command from M2000 console: win "notepad", dir$+"empty.gsb"

We can open explorer for dir$ (the m2000 user directory) using Win Dir$ (we can use paths without quotes if no space includes, so win c:\ open explorer to c:)

File saved as:

MODULE GLOBAL A {
}

Because we make it in "level 0" (from console) this is a global module. A global module which loaded from console, or was a module loaded from a file at command line, when opening the environment, erased with an End, or a New, or a Start statement (reset of environment by software), or a Break by keyboard (although a dialog ask for proceed the breaking, the reset of environment) , or in some situation by using End Process from Task Manager.

If we wish to run it from command line (by clicking the file in explorer, and let m2000.exe open gsb files), we have to consider the first that this file not contain an execute statement, and that if we didn't use an input statement/function which need console, then console stay hide. To be sure that console open we have to use Show statement. To run A we have to include A at the last line (or append a line and write A). So we write in first line Show (press Esc to return to prompt) and save the file as Save Empty, A so we get this:

MODULE GLOBAL A {Show
}
A

We can open it with Edit "empty.gsb" add some statements between A and block of module, to make some globals, say a DIM a(10) which stay there until the end of current interpreter run (interpreter may run multiple times simultaneously). All globals are globals for current interpreter only.

We can run empty.gsb now (supposed we save it as Save Empty, A), from explorer or using a command in M2000 console which opens another interpreter (and can feed it with some numbers or and strings, but this is another story):

Use empty

So now we see environment again, with open console and at prompt (execution done, and stay open because no End statement executed after the A, or inside module as Set End). Set used to send commands to prompt by code.

Finally this is the code in a file (say Empty.gsb) to open, display something, waiting for a key (now a Show automatic happen) and then finish. We have to write it, in M2000 editor, and save it using Save Empty, A or in any editor and save it as empty.gsb in your desired folder. sav

MODULE GLOBAL A {
Print "Hello World"
a$=Key$
Set End
}
A

We can save it scrabbled text using Save "empty" @, A (not readable, but environment can revert the process using a unique key)

(m2000 is open source so key is not a mystery, but you can make your own clone, and use own key)

 function [varargout] = emptyprogram(varargin)
block()$

An empty MAXScript file returns "OK" on execution

end
Output:


Works with: min version 0.19.3

Linux

This just exits the program with exit code 0 (exit_success)

	.text
main: 	li 	$v0, 10
	syscall

Nintendo 64

In addition to a proper cartridge header, CRCs, and footer, you'll need to write a value of 8 to address 0xBFC007FC so that the cartridge can boot correctly. (Nintendo 64 is big-endian, so the 8 is actually stored at 0xBFC007FF, but every example I've seen stores the value as a uint32 so that's what I'm going with.)

After that, just enter an infinite loop and you're done.

la $t0,0xBFC007FC
li $t1,8
sw $t1,0($t0)

halt:
nop   ;not actually needed by real hardware, but Project 64 doesn't like infinite loops.
b halt
nop
С/П
	LOC	#100
Main	TRAP	0,Halt,0	// main (argc, argv) {}
MODULE Main;

BEGIN
END Main.
MODULE Main;

BEGIN
END Main.

The empty file is a valid program.



10 rem

An empty input file is valid, but if the output is Postscript or PDF, most PDF viewers will suffer. However, that's the PDF viewer's fault; the typesetter is still okay with an empty file. If one wants grace for the PDF viewers, import a macro that, at the very least, defines some proper margins and pagination as in the following code:

Works with: GNU TROFF version 1.22.2
.mso me.tmac

Empty files are valid Nanoquery programs that do nothing.

Compiles with warnings:

null

Compiles without warnings (so, more correct):

module Program
{
    Main() : void
    {
    }
}

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
;


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



An empty nom program should be valid but may not be.

nop; # no operation, does nothing

or read; print; clear; which just prints the standard input to the standard output.

MODULE Main;

BEGIN
END Main.
bundle Default {
  class Empty {
    function : Main(args : String[]) ~ Nil {
    }
}
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;
}
Works with: Ocaml version 3.09
;;

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

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.

package main
main :: proc() {}

An empty file is a valid oforth file

oforth empty.of

Without file, interpreter can just evaluate bye :

oforth --P"bye"

An empty file is considered the smallest runnable code.

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

A file with any one-digit number ("0", "1", .. "9") or one-character function like "+", "-", etc.) is smallest non empty runnable code.

0

The Compiler will accept an empty file:

We can run OpenLisp in shell mode with an empty program as follows. This is for the Linux version of OpenLisp.

#!/openlisp/uxlisp -shell
()

The smallest possible program is a single space character:

Accepted by compiler

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

unit

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

functor
define
   skip
end
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.
##

For typing:

#include default-libraries

#author .

class .:

For importing:

While • is valid, the example below is the smallest possible "compiled" program that can be made normally.

•dl◘.◙

In the Peri language, a text file with a length of zero bytes is a correct program, but it does nothing. Similarly, a text file that consists of all whitespace characters is also a correct program that does nothing.

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

Of course, this then requires you to specify the interpreter on the command line (i.e. perl empty.pl). So slightly more correct as a stand-alone program, is:

#!/usr/bin/perl

The smallest possible Perl one-liner is perl -e0.

Library: Phix/basics

An empty file is a valid program. When compiled however, it is far from empty as it contains most of the VM and a full run-time diagnostics kit (together about 202K).

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

By default, Picat calls the main/0 predicate:

main.
Output:
$ picat empty_program.pi

An shorter way is this program

x.

but then an explicit goal at command line (-g x) must be given.

Output:
$ picat -g x empty_program2.pi

(de foo ())
int main(){}

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

Any text longer than 0 characters is valid, otherwise resulting in a "The file is empty or does not exist" error. In this example, a space character is used.

s: proc options (main);
end;
BEGIN
    NULL;
END;
To run:
\bye


actor Main new create(e: Env) => ""

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.

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

%!PS

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

%!PS-2.0
% ...or...
%!PS-3.0
% etc

An empty script block. A script block is a nameless (lamda) function.

&{}
Output:


An empty .pde sketch file.

When run this will produce a 200x200 inactive default gray canvas.

This is an acceptable program:

IGNORELINE

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

;

For typing:

For importing:

At best, the code can have one line, which is empty. The smallest way to achieve this is to type nothing. However, this is the smallest possible "compiled" program that can be generated via the compiler:

[

If you try to empty the memory and run it, you get this:

Which is funny because the other BASIC-like languages support empty memory.

you can use the REM command and it will basicly do nothing if you run the program. But the no memory error won't be emited

10 REM COMMENTS DO NOTHING


EXECUTE BLOCK
AS
BEGIN
END

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

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

An empty file named __init__.py even has a structural purpose in Python of declaring that a directory is a Package.

1
QUIT

An empty string or text file is a valid Quackery program that does nothing.

Output:


R

An empty text file is a valid empty program

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

#lang racket

(formerly 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 Raku:

use v6;

or even:

v6;

An empty text file is an empty program.

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

An empty file is the smallest valid program.

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

Some REXX implementations require a special comment   [1st word in the comment must be   REXX   (in upper/lower/mixed) case]
to distinguish from other types of scripting languages,   and the comment must be the 1st line as well as the   REXX   word.


But a null program (or a program with only blanks in it)   in those other scripting languages is also considered a valid program.

version 1

This program can be empty (no characters),   or a program with (only) one or more blanks.

version 2

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

/*REXX*/
Works with: Rhope version alpha 1
Main(0,0)
|: :|
≪  ≫

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
end  ' actually a blank is ok
fn main(){}

Scala 2

object emptyProgram extends App {}

Scala 3

@main def a = ()

An empty program is invalid because it gives an [Err: Undefined] error. This behaviour still applies when the program isn't running. Due to this error, a program containing only an empty comment is the smallest possible valid program.

//

A totally empty program is valid, and just copies the input unmodified. The same effect can be achieved with a single b command (which might be more convenient when called from the command line).

sed "" input.txt
# vs
sed b input.txt
$ include "seed7_05.s7i";
 
const proc: main is noop;
Works with: SIMULA-67
BEGIN
END
[]

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

end
$#

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

Works with: Db2 LUW

With SQL only:

SELECT 1 FROM sysibm.sysdummy1;

Output:

db2 -t
db2 => SELECT 1 FROM sysibm.sysdummy1;

1        
------------
           1

  1 record(s) selected.
Works with: Db2 LUW

With SQL PL:

--#SET TERMINATOR @

CREATE PROCEDURE myProc ()
 BEGIN
 END @

Output:

db2 -td@
db2 => CREATE PROCEDURE myProc ()
...
db2 (cont.) =>  END @
DB20000I  The SQL command completed successfully.
Works with: Db2 LUW

version 9.7 or higher.

With SQL PL:

BEGIN
END;

Output:

db2 -t
db2 => BEGIN
db2 (cont.) => END;
DB20000I  The SQL command completed successfully.

A completely empty program—all store bits clear, just power the machine up and hit Run—is meaningful in SSEM code and even does something, although not something desirable:

00000000000000000000000000000000   0. 0 to CI    jump to store(0) + 1
00000000000000000000000000000000   1. 0 to CI    jump to store(0) + 1

Since the number in address 0 is 0, this is equivalent to

    goto 1;
1:  goto 1;

and has the effect of putting the machine into an infinite loop.

The smallest program that will terminate is:

00000000000001110000000000000000   0. Stop
;

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

Stata does not accept an empty program, so we have to do something. Here we only declare the minimum version of the interpreter for the program.

program define nop
        version 15
end

It's also possible to define an empty function in Mata.

function nop() {}
  • Prints first line (if input has multiple lines).
  • Prints last parsed item of line (if input has single line).

Try it here

function () { }

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

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

:
Disp
Return
Stop
PROGRAM:EMPTY
:AsmPrgmC9
Prgm
EndPrgm

An empty program works just fine.

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.

END
$$ MODE TUSCRIPT


Works with: Bourne Shell
#!/bin/sh
Works with: Bourne Again SHell
#!/bin/bash
Works with: Korn SHell
#!/bin/ksh
i

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

The Cygnus/X Ursa interpreter has no problems with empty files, so the shortest program is an empty file.

void main() {}
0000  0000     1 .entry	main,0	;register save mask
  04  0002     2 	ret	;return from main procedure
      0003     3 .end	main	;start address for linker

Same as Visual Basic, VB6, etc.

Sub Demo()
End Sub

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

'

An empty file is the smallest valid script, but running it does nothing.

module main;
endmodule

Compiled and simulated by Modelsim:

entity dummy is
end;

architecture empty of dummy is
begin
end;

An empty file is a valid program.

Works with: VB6

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

V (Vlang) can compile a 0 length, or whitespace only file as "empty", and "correct".


Output:
prompt$ ls -s blank.v
0 blank.v
prompt$ v run blank.v
prompt$ echo $?
0

A more reasonable example, that someone might guess was a V program, and not just an emptiness:

{}

For an even better chance at guessing that the file is meant as V source code:

module main
pub fn main() {}


An empty 'file' is a valid WDTE script. That being said, WDTE has no inherent concept of scripts being in files, so a zero-length input may be a better description.

Library: WASI
(module
    ;;The entry point for WASI is called _start
    (func $main (export "_start")
    
    )
)
Works with: NASM version Linux
section .text
	global _start
	
	_start:
		mov eax, 1
		int 0x80
		ret
Works with: MASM
.386
.model flat, stdcall
option casemap:none

.code
start:
ret
end start
Works with: Windows XBasic
Works with: Linux XBasic
PROGRAM	"Empty program"

DECLARE FUNCTION  Entry ()

FUNCTION  Entry ()

END FUNCTION
END PROGRAM

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



.

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

<?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>

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="/" />
</transform>
Works with: HyperCard
Works with: LiveCode
on startup
  
end startup
<?xml version="1.0"?>

An empty file is valid and does nothing.



Amstrad CPC, ZX Spectrum, etc.

Most 8-bit computers work in a similar fashion: The BASIC interpreter acts as an operating system, and your entire program is essentially a subroutine that BASIC will CALL. If you "return" from your program the computer will go back to BASIC.

ret

Game Boy

Translation of: Game Boy Advance

The Nintendo logo is loaded from the cartridge header, and the Game Boy's firmware won't boot the game without it. In addition, the firmware also reads a checksum of the cartridge contents and won't boot the game if it doesn't match the checksum stored in the header. So a truly "empty" program can't be run at all. Thus a minimum of a valid cartridge header is required for an empty program that the Game Boy can actually run. The beginning of the cartridge header is a jump to the program's start.

ProgramStart:
nop ;not sure if this is needed but Game Boy is somewhat buggy at times and the tutorials I used all did it
di  ;disable interrupts
foo:
jp foo ;trap the program counter here. (Don't do this on a real Game Boy, you'll drain the batteries much faster than usual.)
pub fn main() void {}

An empty file/string is valid.


c:=Compiler.Compiler.compileText("");
c() //--> Class(RootClass#)
program: empty

Empty Program

For typing:

For importing:

If nothing is entered into the "Import program" textbox, the code of the program that was already in the editor will remain.

¶0¶

See BASIC
Cookies help us deliver our services. By using our services, you agree to our use of cookies.