xyzzy
2009-02-05
Introduction
This is the classical "Hello, World!" example, in a slightly more original form. It serves as a test of how much boilerplate is required to write a minimal program.
Ada
In Ada, the program can be rendered as follows:
with Ada.Text_IO; use Ada.Text_IO;
procedure Xyzzy is
begin
Put("Nothing happens.");
end Xyzzy;
The program uses the procedure Put
from
the package Ada.Text_IO
. The package is made available to
the program by with Ada.Text_IO;
. The code use
Ada.Text_IO;
imports all definitions from the package into the
program's namespace, so that we can refer to the Put
function
simply as Put
. An alternative would have been to omit the
use
clause and refer to the function as
Ada.Text_IO.Put
. The program itself is a single procedure
called Xyzzy
which calls Ada.Text_IO.Put
.
The program above contains 12 words.
C
In C, the program is as follows:
#include <stdio.h>
int main(int argc, char **argv) {
puts("Nothing happens.");
return 0;
}
As you can see, some boilerplate is required. First, we
need to include a header file, as even something as basic as
I/O is not built into C. Then, we need to define a
function named main
, which will be called when the program
is executed. This function takes some arguments related to the arguments
passed to our program on the command line; we make no use of them
here. This function returns an integer, which will also be the exit
code of the program. Zero means success, any other value means
failure; we return zero here.
It is worth noting that many C compilers will also accept this
program if we don't include the header file, don't let main
take any arguments, and don't let it return a value. However, the
version above is the technically correct one.
The program above contains 13 words.
OCaml
This is the OCaml version:
print_endline "Nothing happens."
A simple function call only. 3 words.
Ruby
And this is the same program in Ruby:
puts 'Nothing happens.'
One function call is all it takes. 3 words.
Common Lisp
The Common Lisp version is this:
(format t "Nothing happens.~%")
Common Lisp requires no boilerplate around the program,
but the program itself may require some explanation. The function
format
very powerful and very complex, but what's important
here is that the first argument, t
, causes
format
to print to standard output, and that the second
argument specifies what is to be printed; in this case, all characters
it contains are printed literally, except ~%
, which causes
a newline to be printed.
The program contains 4 words.