14 Feb 2014 shimniok   » (Journeyer)

Infinite Output in Different Languages

I enjoy the Olimex Weekend Programming Challenge. I missed #33 but it's one of my favorites so far: generate infinite output with the smallest programs possible in different languages. How many languages can you do it in?


Above is how you'd enter the code in Commodore 64 BASIC (the listing would expand the keywords), The ? is PRINT, the G shift-O (right angle character) is GOTO.

Here are the solutions Olimex received. I've selected a few interesting solutions and added some of my own:


brainf***
+[.]

This is a cool language. Utterly useless, but cool. And this is a family-friendly blog so I'm not spelling out the name.

python
  while(1):
print "."

Perl
print 1 while 1;

I program Perl with a thick C accent, so I didn't know you could do this.

lisp
(loop(princ 1))

I haven't written anything lispy in years. I doubt I ever wrote a loop in that language.

Here's some other languages that weren't submitted...

Pascal
Program z(output);
begin
while true
do begin
writeln('x');
end;
end.

Yeah, a bit wordy. That's Pascal for ya. Haven't written Pascal since the late 80's during my first CS class in College.

FORTRAN
PROGRAM Z
1 PRINT *, "x"
GO TO 1
END PROGRAM Z

Less wordy. I don't know why but I love Fortran. It just seems so simple and transparent.

Lua
repeat
print("x")
until false

I'm curious about 
Lua. It seems neat and is supposed to be lightweight and great for embedded microcontrollers.

RedCode
MOV 0, 1

This is code used in CoreWar. It doesn't output to a screen. RedCode can only modify the core's memory. Although the RedCode VM displays memory as output so I guess you could argue... but I'll spare us all.

DCL
$ loop:
$ write sys$output "x"
$ goto loop

Or something like that. I couldn't find an online DCL interpreter and I'm fresh out of OpenVMS systems to test on. I used to write a ton of DCL scripts. I grew up on VMS in college before migrating to Unix.

Icon
procedure main()
repeat write ( 'x' );
end

I learned a bit of Icon at the University of Arizona where it was developed. It evolved from SNOBOL.

Alright, your turn. What obscure languages can you throw at me?

Can you think of any languages that don't support infinite loops? I think APL might be one.

Post in the comments...

Syndicated 2014-02-14 17:00:00 (Updated 2014-02-22 04:30:37) from Michael Shimniok

Latest blog entries     Older blog entries

X
Share this page