The Programming Language Landscape
The Programming Language Landscape
Stephen A. Edwards
Columbia University
Fall 2014
99 Bottles of Beer
Java
class Bottles {
public static void main(String args[]) {
String s = "s";
for (int beers=99; beers>-1;) {
System.out.print(beers+" bottle"+s+" of beer on the wall, ");
System.out.println(beers + " bottle" + s + " of beer, ");
if (beers==0) {
System.out.print("Go to the store, buy some more, ");
System.out.println("99 bottles of beer on the wall.\n");
System.exit(0);
} else
System.out.print("Take one down, pass it around, ");
s = (--beers == 1)?"":"s";
System.out.println(beers+" bottle"+s+" of beer on the wall.\n");
}
}
}
Sean Russell,
http://www.99-bottles-of-beer.net/language-java-4.html
Java
class Bottles {
public static void main(String
args[])
{ Sun, 1991
Gosling
et al.,
String s = "s";
for (int beers=99; beers>-1;)
{
Imperative,
object-oriented,
System.out.print(beers+" bottle"+s+" of beer on the wall, ");
threaded
System.out.println(beers + " bottle" + s + " of beer, ");
if (beers==0) {
Based
on C++,
C,some
Algol,
etc.");
System.out.print("Go to
the store,
buy
more,
System.out.println("99 bottles of beer on the wall.\n");
Statically typed
System.exit(0);
} else
Automatic
garbage
collection
System.out.print("Take
one down, pass
it around,
");
s = (--beers == 1)?"":"s";
Architecturally
neutral
System.out.println(beers+"
bottle"+s+" of
beer on the wall.\n");
}
}
Defined on a virtual machine (Java
}
Bytecode)
Sean Russell,
http://www.99-bottles-of-beer.net/language-java-4.html
C
#define MAXBEER 99
void chug(int beers);
int main()
{
int beers;
for(beers = MAXBEER; beers; chug(beers--)) ;
puts("\nTime to buy more beer!\n");
return 0;
}
void chug(int beers)
{
char howmany[8], *s;
s = beers != 1 ? "s" : "";
printf("%d bottle%s of beer on the wall,\n", beers, s);
printf("%d bottle%s of beeeeer . . . ,\n", beers, s);
printf("Take one down, pass it around,\n");
if (--beers) sprintf(howmany, "%d", beers);
else strcpy(howmany, "No more");
s = beers != 1 ? "s" : "";
printf("%s bottle%s of beer on the wall.\n", howmany, s);
}
C
#define MAXBEER 99
void chug(int beers);
int main()
{
Dennis Ritchie, Bell Labs,
int beers;
for(beers = MAXBEER; beers; chug(beers--)) ;
Procedural, imperative
puts("\nTime to buy more beer!\n");
return 0;
Based on Algol, BCPL
}
1969
operating systems
FORTRAN
1
2
3
4
10
*
20
30
program ninetyninebottles
integer bottles
bottles = 99
format (I2, A)
format (A)
format (I2, A, /)
format (A, /)
write (*,1) bottles, bottles of beer on the wall,
write (*,1) bottles, bottles of beer.
write (*,2) Take one down, pass it around...
if (bottles - 1 .gt. 1) then
write (*,3) bottles - 1, bottles of beer on the wall.
else
write (*,3) bottles - 1, bottle of beer on the wall.
end if
bottles = bottles - 1
if (bottles - 1) 30, 20, 10
Last verse
write (*,1) bottles, bottle of beer on the wall,
write (*,1) bottles, bottle of beer.
write (*,2) Take one down, pass it around...
write (*,4) No bottles of beer on the wall.
stop
end
FORTRAN
1
2
3
4
10
*
20
30
program ninetyninebottles
integer bottles
Backus, IBM, 1956
bottles = 99
format (I2, A)
Imperative language for science
format (A)
and engineering
format (I2, A, /)
format (A, /)
First compiled
write (*,1) bottles, bottles
of beer language
on the wall,
write (*,1) bottles, bottles of beer.
Fixedpass
format
lines (for punch cards)
write (*,2) Take one down,
it around...
if (bottles - 1 .gt. 1) then
Arithmetic
expressions,
and
write (*,3) bottles 1, bottles
of beer on If,
theDo,
wall.
else
Goto statements
write (*,3) bottles - 1, bottle of beer on the wall.
end if
Scalar (number) and array types
bottles = bottles - 1
if (bottles - 1) 30, 20, 10
Limited string support
Last verse
write (*,1) bottles, bottle of beer on the wall,
Still common in high-performance
write (*,1) bottles, bottle of beer.
computing
write (*,2) Take one down,
pass it around...
write (*,4) No bottles of beer on the wall.
stop
Inspired most modern languages,
end
especially BASIC
AWK
BEGIN {
for(i = 99; i >= 0; i--) {
print ubottle(i), "on the wall,", lbottle(i) "."
print action(i), lbottle(inext(i)), "on the wall."
print
}
}
function ubottle(n) {
return sprintf("%s bottle%s of beer", n?n:"No more", n-1?"s":"")
}
function lbottle(n) {
return sprintf("%s bottle%s of beer", n?n:"no more", n-1?"s":"")
}
function action(n) {
return sprintf("%s", n ? "Take one down and pass it around," : \
"Go to the store and buy some more,")
}
function inext(n) {
return n ? n - 1 : 99
}
OsamuAoki,
http://www.99-bottles-of-beer.net/language-awk-1623.html
AWK
BEGIN {
for(i = 99; i >= 0; i--) {
print ubottle(i), "on the wall,", lbottle(i) "."
print action(i), lbottle(inext(i)), "on the wall."
print
}
Aho, Weinberger, and Kernighan,
}
Bell Labs, 1977
function ubottle(n) {
return sprintf("%s bottle%s of beer", n?n:"No more", n-1?"s":"")
Interpreted domain-specific
}
function lbottle(n) {
scripting language for text
return sprintf("%s bottle%s of beer", n?n:"no more", n-1?"s":"")
processing
}
function action(n) {
Pattern-action
statements
matched
return sprintf("%s", n ? "Take
one down and
pass it around,"
: \
"Go
to theinput
storelines
and buy some more,")
against
}
function inext(n) {
C-inspired syntax
return n ? n - 1 : 99
}
OsamuAoki,
http://www.99-bottles-of-beer.net/language-awk-1623.html
Wilhelm Weske,
BEGIN{
split( \
"no mo"\
"rexxN"\
"o mor"\
"exsxx"\
"Take "\
"one dow"\
"n and pas"\
"s it around"\
", xGo to the "\
"store and buy s"\
"ome more, x bot"\
"tlex of beerx o"\
"n the wall" , s,\
"x"); for( i=99 ;\
i>=0; i--){ s[0]=\
s[2] = i ; print \
s[2 + !(i) ] s[8]\
s[4+ !(i-1)] s[9]\
s[10]", " s[!(i)]\
s[8] s[4+ !(i-1)]\
s[9]".";i?s[0]--:\
s[0] = 99; print \
s[6+!i]s[!(s[0])]\
s[8] s[4 +!(i-2)]\
s[9]s[10] ".\n";}}
http://www.99-bottles-of-beer.net/language-awk-1910.html
Python
for quant in range(99, 0, -1):
if quant > 1:
print quant, "bottles of beer on the wall,", \
quant, "bottles of beer."
if quant > 2:
suffix = str(quant - 1) + " bottles of beer on the wall."
else:
suffix = "1 bottle of beer on the wall."
elif quant == 1:
print "1 bottle of beer on the wall, 1 bottle of beer."
suffix = "no more beer on the wall!"
print "Take one down, pass it around,", suffix
print ""
Gerold Penz,
http://www.99-bottles-of-beer.net/language-python-808.html
Python
for quant in range(99, 0, -1):
Guido van Rossum, 1989
if quant > 1:
print quant, "bottles of beer on the wall,", \
Object-oriented,
imperative
quant, "bottles of
beer."
if quant > 2:
suffix = str(quant - General-purpose
1) + " bottles of scripting
beer on the wall."
else:
language
suffix = "1 bottle of beer on the wall."
elif quant == 1:
Indentation indicates grouping
print "1 bottle of beer on the wall, 1 bottle of beer."
suffix = "no more beer on the wall!"
Dynamically typed
print "Take one down, pass it around,", suffix
print ""
Gerold Penz,
http://www.99-bottles-of-beer.net/language-python-808.html
APL
http://www.99-bottles-of-beer.net/language-apl-715.html
APL
Iverson, IBM, 1960
Imperative, matrix-centric
E.g., perform an operation on each
element of a vector
Uses own specialized character set
Concise, effectively cryptic
Primarily symbols instead of words
Dynamically typed
Odd left-to-right evaluation policy
Useful for statistics, other
matrix-oriented applications
http://www.99-bottles-of-beer.net/language-apl-715.html
FORTH
: .bottles ( n -- n-1 )
dup 1 = IF ." One bottle of beer on the wall," CR
." One bottle of beer," CR
." Take it down,"
ELSE dup . ." bottles of beer on the wall," CR
dup . ." bottles of beer," CR
." Take one down,"
THEN
CR
." Pass it around," CR
1?dup IF dup 1 = IF ." One bottle of beer on the wall;"
ELSE dup . ." bottles of beer on the wall;"
THEN
ELSE ." No more bottles of beer on the wall."
THEN
CR
;
: nbottles ( n -- )
BEGIN .bottles ?dup NOT UNTIL ;
99 nbottles
Dan Reish,
http://www.99-bottles-of-beer.net/language-forth-263.html
FORTH
: .bottles ( n -- n-1 )
Moore,
NRAO,
1973 CR
dup 1 = IF ." One bottle of
beer on
the wall,"
." One bottle of beer," CR
Stack-based imperative language
." Take it down,"
ELSE dup . ." bottles of beer on the wall," CR
Trivial,CR
RPN-inspired grammar
dup . ." bottles of beer,"
." Take one down,"
Easily becomes cryptic
THEN
CR
Untyped
." Pass it around," CR
1Low-level,
?dup IF dup 1 = IF ." One
bottle of very
beer lightweight
on the wall;"
ELSE dup . ." bottles of beer on the wall;"
THEN
Highly extensible: easy to make
ELSE ." No more bottles of beer on the wall."
programs compile themselves
THEN
CR
Used in some firmware boot
;
systems (Apple, IBM, Sun)
: nbottles ( n -- )
BEGIN .bottles ?dup NOT UNTIL ;
99 nbottles
Dan Reish,
http://www.99-bottles-of-beer.net/language-forth-263.html
Prolog
bottles :bottles(99).
bottles(1) :write(1 bottle of beer on the wall, 1 bottle of beer,), nl,
write(Take one down, and pass it around,), nl,
write(Now they are all gone.), nl,!.
bottles(X) :write(X), write( bottles of beer on the wall,), nl,
write(X), write( bottles of beer,), nl,
write(Take one down and pass it around,), nl,
NX is X - 1,
write(NX), write( bottles of beer on the wall.), nl, nl,
bottles(NX).
Prolog
bottles :bottles(99).
bottles(1) :Programs
relations:
facts and
write(1 bottle of beer on
the wall,are
1 bottle
of beer,),
nl,
write(Take one down, and rules
pass it around,), nl,
write(Now they are all gone.), nl,!.
bottles(X) :Program execution consists of
write(X), write( bottles of beer on the wall,), nl,
trying to satisfy queries
write(X), write( bottles of beer,), nl,
write(Take one down and pass it around,), nl,
Designed for natural language
NX is X - 1,
write(NX), write( bottles
of beer on expert
the wall.),
nl, and
nl,
processing,
systems,
bottles(NX).
theorem proving
SQL
SELECT
CASE (bottlecount)
WHEN 0 THEN No more bottle of beer on the wall, no more bottles of
Go to the store and buy some more, 99 bottles of beer
WHEN 1 THEN 1 bottle of beer on the wall, 1 bottle of beer. ||
Take one down and pass it around, no more bottles of b
WHEN 2 THEN 2 bottles of beer on the wall, 2 bottles of beer. ||
Take one down and pass it around, 1 bottle of beer on
ELSE
rtrim (cast((BottleCount) as char(2))) || bottles of beer on th
rtrim (cast((BottleCount) as char(2))) || bottles of beer. ||
Take one down and pass it around, ||
rtrim (cast((BottleCount)-1 as char(2))) || bottles of beer on
END
FROM
(
SELECT avalue * 10 + bvalue as bottlecount
FROM
(VALUES (9), (8), (7), (6), (5), (4), (3), (2), (1), (0)) a(avalue)
(VALUES (9), (8), (7), (6), (5), (4), (3), (2), (1), (0)) b(bvalue)
) as valuelist;
Kent Olsen,
http://www.99-bottles-of-beer.net/language-sql-967.html
SQL
SELECT
CASE (bottlecount)
WHEN 0 THEN No more bottle of beer on the wall, no more bottles of
Go to the store and buy some more, 99 bottles of beer
WHEN 1 THEN 1 bottle of beer on the wall, 1 bottle of beer. ||
Take one down and pass it around, no more bottles of b
WHEN 2 THEN 2 bottles of beer on the wall, 2 bottles of beer. ||
Take one down and pass it around, 1 bottle of beer on
Chamberlin and Boyce, IBM, 1974
ELSE
rtrim (cast((BottleCount) as char(2))) || bottles of beer on th
Declarative
language
for databases
rtrim (cast((BottleCount)
as char(2)))
|| bottles
of beer. ||
Take one down and pass it around, ||
rtrim (cast((BottleCount)-1
as char(2)))
bottles
of beer on
Semantics
based ||
onthe
relational
END
model
FROM
(
Queries on tables: select with
SELECT avalue * 10 + bvalue as bottlecount
predicates, joining, aggregating
FROM
(VALUES (9), (8), (7), (6), (5), (4), (3), (2), (1), (0)) a(avalue)
(VALUES (9), (8), (7), (6),
(5), (4),
(3), optimization:
(2), (1), (0)) b(bvalue)
Database
query
) as valuelist;
declaration to procedure
Kent Olsen,
http://www.99-bottles-of-beer.net/language-sql-967.html
LISP
jimka, http://www.99-bottles-of-beer.net/language-lisp-1465.html
LISP
McCarthy, MIT, 1958
jimka, http://www.99-bottles-of-beer.net/language-lisp-1465.html
Haskell
bottles ::
bottles n
| n == 0
| n == 1
| n > 1
Simon Johansson,
http://www.99-bottles-of-beer.net/language-haskell-1613.html
Haskell
bottles ::
bottles n
| n == 0
| n == 1
| n > 1
Functional
no side-effects
system research
main
Simon Johansson,
http://www.99-bottles-of-beer.net/language-haskell-1613.html