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 CoreASM

(Uses state transiton to instead of loops)

Date:04/02/10
Author:Serguei Michtchenko
URL:n/a
Comments:0
Info:http://www.coreasm.org/
Score: (3.50 in 2 votes)
CoreASM NinetyNineBottles

use Standard

derived MaxBottles = 99
function BottleCount : -> Integer

init InitRule

rule InitRule = {
	BottleCount := MaxBottles
	program(self) := @SingAndDrink
}

rule SingAndDrink = {
	if BottleCount > 0 then {
		let n = BottleCount in
		print Bottles(n) + " of beer on the wall, " + Bottles(n) + " of beer.\n"
			+ "Take one down and pass it around, " + Bottles(n-1) + " of beer on the wall.\n"
		
		BottleCount := BottleCount - 1
	}
	else {
		print "No more bottles of beer on the wall, no more bottles of beer.\n"
			+ "Go to the store and buy some more, " 
			+ Bottles(MaxBottles) + " of beer on the wall."
			 
		program(self) := undef
	}
}

rule Bottles(n) = 
	return str in
		if      n > 1 then str := n + " bottles"
		else if n = 1 then str := n + " bottle"
		else if n = 0 then str := "no more bottles"

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
1Oleg Nabiullin08/16/080

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: