Quam's really long list of infinite loops in many languages
Horrible. Awful! Thousands of programming languages, and you guys only come up with infinite loops in two? Not to mention that we don't even get a whole C program! You think we can just dredge up that #include<stdio.h> int main(int argc, char** argv){} stuff from memory? Really, really unfit behavior.
Well, here's the list. The real list. Infinite loops in every language I deem significant. I plan to eventually include examples in erlang, bc, bash, Mumps, xBase, SQL (some dialect), lua, Javascript, assembler (probably MIX), Tcl, OCaml, Pascal/Delphi and whatever else looks good.
If you're already thinking of this as a waste of time, think of it not as a dictionary of totally useless programs but as a series of fetal Operating Systems.
Operating environment will be Ubuntu. I'll provide install and build instructions where necessary. Feel free to send in more, especially in unrepresented languages. The list will is categorized by programming language, and each may have multiple programs with explanatory titles.
Keep in mind that some of these programs will eventually fill all memory and swap. Don't run them if you don't know how to stop them. Anything that loops or recurses infinitely gets in. Solutions that quickly blow up the stack and die will be pointed out with the words "Stack Overflow" in the title. I will not venture guesses on ones that do not die within a few second; some of them may use constant space, and some may not store stack on the Unix stack area.
And remember, you brought this on yourselves. Basic and C. Christwagons.
Installation: Install package 'gnat'
Run: Put program in loop_forever.adb, run "gnatmake loop_forever", run loop_forever
One: What do you mean "Statement Expected"?
procedure Loop_Forever is
X : Integer := 0;
begin
loop
X := 0;
end loop;
end Loop_Forever;
Two: The compiler warned me this would happen. (stack overflow)
procedure Loop_Forever is
begin
Loop_Forever;
end Loop_Forever;
Installation: Install package 'mzscheme'; go to http://arclanguage.org/install and follow instructions
Run: See installation instructions for REPL
One: On a Horse With No Name
([_ _] [_ _])
Run with awk -- 'program text'
One and only: While
BEGIN { while(1){} }
Sorry, this is rumor and conjecture for now.
One: Left and right
><
Two: Just left
<
Installation: install package libncurses-dev and opencobol
Usage: cobc program.cob, run program
One: I hold E.W. Djikstra fully responsible
IDENTIFICATION DIVISION.
PROGRAM-ID. InfiniteLoop.
PROCEDURE DIVISION.
PERFORM UNTIL 1 < 0
END-PERFORM
STOP RUN.
Installation: Install package 'cmucl'
Use: "cmucl -eval 'program'" or "cmucl" and enter program at REPL
One: Loop
(loop)
Two: Do (stack overflow)
(do ()(nil))
Three: Infinite format control string loop (I'm not kidding about this)
(format t "~{~^~}" '(1))
Four: Recursively called format control string (I'm certainly not kidding about this but stack overflow)
(format t "~@{~}" "~:*~@{~}" 1)
Usage: dc program.dc
One: Alonzo Church would be angered (stack overflow)
[dx]dx
Two: Recursively called macro (Stack overflow)
1[dd=x]dsxx
Usage: Run emacs, enter program text and evaluate each line with Ctrl-j
One: Totally not copied from the Common Lisp section
(require 'cl)
(loop)
Two: Whiltey?
(while 't)
(Thanks to RPGeek who came in the middle of the night and chased off the ghost of Alonzo Church with a stick before giving me these)
Installation: install gfortran package
Run: Run command 'gfortran program.f90' - file extension is important
One: Good old fashioned Fortran
program InfiniteLoop
100 goto 100
end program InfiniteLoop
Two: Newfangled and clearly not hardcore Fortran 95
program InfiniteLoop
do
end do
end program InfiniteLoop
Three: I'm guessing Fortran doesn't have anonymous recursive functions, so... (Stack overflow)
recursive subroutine infinity
call infinity
end subroutine infinity
program RecursiveLoop
call infinity
end program RecursiveLoop
(A dozen or so thanks to Resiak who painstakingly crafted these)
Installation: Install package ghc
Run: Run 'ghc program.hs' then run a.out or program, whichever comes out >:|
One: The main... uh... example.
main = main
Two: Haskell people have the longest
main = do print (length [0..])
Usage: m4 program.m4
One: Why does m4 have them funny slanty quotes
define(`_',`_')dnl
_
Two: The egg came first; this is just an optimization
define(`chicken',`egg')dnl
define(`egg',`chicken')dnl
chicken
Installation: Already installed
Use: perl program.pl or perl -e 'program text'
One: Redo
{redo}
Two: While
0while(1)
Three: For
for(;;){}
Four: The Ghost Of Alonzo Church is going to kill me for this (stack overflow)
&{sub{&{$_0}($_0)}}(sub{&{$_0}($_0)})
Five: Like four, but with a fixed point like a normal people use
sub f { f() }
f()
Six: Objects make everything better! Seriously.
{
package Recursor;
sub new { bless {}, shift } # Subclassable!
sub recurse_forever {
my $class = ref(shift); # Get my own class (subclassable!)
$class->new->recurse_forever;
}
}
Recursor->new->recurse_forever;
Seven: Even goto is shorter in perl
a: goto a
Run with python program.py
One: This may be the only time you will ever notice the subtle problems with significant whitespace
while 1:
pass
Two: Plain recursive (Stack overflow)
def f():
f()
f()
Three: Alonzo Church is still going to kill me for the Perl one (Stack overflow)
(lambda x: x(x))(lambda x: x(x))
Installation: Install package 'irb'
Use: Run ruby program.rb
One: Loop
loop {}
Two: Recursive (stack overflow)
def f();f;end
f()
Three: Why the Lucky Stiff and Alan Kay will both find and kill me (stack overflow)
Class C; def f;C.new.f;end;end
C.new.f
Four: Guy Steele will find me and make me read the Fortress spec (stack overflow)
f = nil
callcc { |x| f = x }
f.call()
Installation: Install package 'mzscheme'
Run: Are you actually running all of these? What a rube. I mean, they work, but still.
One: Maybe Alonzo Church will forgive me if I act fast
((lambda (x) (x x)) (lambda (x) (x x)))
Two: Recursive, fixed-point
(define (f) (f))
(f)
Three: With some kind of actual loop syntax
(let loop () (loop))
Four: With call/cc, bane of human understanding
(let ((f '())) (call-with-current-continuation (lambda (x) (set! f x))) (f))
Run with sed -f program.sed and then give at least one line of input before closing input with Ctrl-D
One: GB2:B
: b
b b
Install: Install package squeak
Run: Uh, run Squeak with the image, open the Tools tab, click and drag out a "Workspace", type program text into it, middle-click and click "do it"
true whileTrue
Installation: Screw you, man. I'm tired.
Run: Far and fast. You don't want in on this shit.
One: One.
End of List
Well, there you have it, folks. There's the rundown.
You didn't think I was gonna use some pansy language like Java, did you?