Empty program: Difference between revisions
pass is not needed |
|||
Line 268: | Line 268: | ||
==[[Ruby]]== |
==[[Ruby]]== |
||
[[Category:Ruby]] |
[[Category:Ruby]] |
||
'''Interpreter:''' [[Ruby]] 1.8.5 |
|||
#!/usr/bin/env ruby |
|||
Starting an Interactive RuBy shell |
|||
irb |
|||
==[[Tcl]]== |
==[[Tcl]]== |
Revision as of 19:30, 13 September 2007
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
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
Compiler: GCC 4.1.2
procedure Empty is begin null; end;
AppleScript
An empty .scpt file is considered the smallest runnable code, but the following would also be acceptable.
return
AWK
Interpreter: AWK Compilers: awka awkcc (untested)
BEGIN{}
BASIC
Interpreter: QBASIC
10 END
Befunge
@
The halt command @ is required because code wraps around. An empty file would be an infinite loop.
Brainf***
Empty program
Note: this works as all non-instruction characters are considered comments. Alternatively, a zero-byte file also works.
C
Compiler: GCC 4.0.3
int main (int argc, char *argv[]) { // Note: The arguments may be omitted return 0; }
C#
Compiler: Visual C# 2005
static class Program { static void Main(string[] args) { } }
C++
Compiler: GCC 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 }
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.
D
Compiler: DMD 1.002
void main() { }
Delphi
Compiler: ALL
Program Shortest; Begin end.
E
The shortest possible program:
This is equivalent to:
null
Forth
: main ;
Fortran
program nothing end
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 {}
IDL
end
Java
Compiler: Sun javac, JDK 1.5.0 and up
public class EmptyApplet extends java.applet.Applet { @Override public void init() { } }
Compiler: Sun javac, JDK 1.0 and Up
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.
LISP
()
This is also the shortest LISP program that prints its own source upon execution.
OCaml
Interpreter/Compiler: Ocaml 3.09
;;
Actually, the smallest possible correct program in OCaml is an empty source file.
Pascal
Compiler: Borland Pascal
program ProgramName; begin end.
Perl
Interpreter: Perl 5.8.8
#!/usr/bin/perl 1;
#!/usr/bin/perl exit;
#!/usr/bin/perl # A program without a body will work too
#!/usr/bin/perl
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.
PHP
<?php ?>
PL/SQL
BEGIN NULL; END;
Pop11
Pop11 has two compilers, incremental and batch compiler. For incremental compiler one can use just empty program text (empty file). 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 usefull:
compile_mode :pop11 +strict; define entry_point(); enddefine;
#_TERMIN_IF DEF POPC_COMPILING entry_point();
Here 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
In general, the first 4 characters of the file have to 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
Python
Interpreter: Python 2.4.3
An empty text file is an empty program:
#!/usr/bin/env python
Ruby
Tcl
Nothing is mandatory in Tcl, so an empty file named nothing.tcl would be a valid "empty program".
Toka
[ ]
UNIX Shell
Interpreter: bourne SHell
#!/bin/sh
Interpreter: Bourne Again SHell
#!/bin/bash
Unlambda
i
(See how i plays so many roles in unlambda?)
Visual Basic .NET
Compiler: Visual Basic .NET 2005
Module General Sub Main() End Sub End Module
xTalk
Interpreter: HyperCard
on startup end startup
eSQL
CREATE COMPUTE MODULE ESQL_Compute CREATE FUNCTION Main() RETURNS BOOLEAN BEGIN RETURN TRUE; END; END MODULE;
Markup Languages
LaTeX
Compiler: pdfeTeXk, Version 3.141592-1.30.4-2.2 (Web2C 7.5.5), LaTeX2e (2003/12/01)
\documentclass{article} \begin{document} \end{document}