Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Squirrel

(Uses tail recursion and coroutines)

Date:02/01/06
Author:Joe Andrusyszyn
URL:n/a
Comments:0
Info:http://www.squirrel-lang.org/
Score: (3.00 in 6 votes)
function first(i)
{
	if(i>1)
		suspend(i + " bottles of beer on the wall, " + i  + " bottles of beer.");
	if(i==1)
		suspend(i + " bottle of beer on the wall, " + i  + " bottle of beer.");
	if(i<1)
		return null;
	return second(i);
}

function second(i)
{
	if(i>2)
		suspend("Take one down and pass it around, " + (i-1) + " bottles of beer on  the wall.");
	if(i==2)
		suspend("Take one down and pass it around, " + (i-1) + " bottle of beer on  the wall.");
	if(i==1)
		suspend("Take one down and pass it around, no more bottles of beer on  the wall.");
	i--;
	return first(i);
}

local songthread = newthread(first);
local line;
print(songthread.call(99)+"\n");
while(line = songthread.wakeup())
	print(line + "\n");

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: