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

Date:08/16/08
Author:Oleg Nabiullin
URL:n/a
Comments:0
Info:http://www.coreasm.org
Score: (2.86 in 7 votes)
// CoreASM specification 
// Written 08/16/08 by Oleg Nabiullin
// URL: www.coreasm.org

CoreASM Song_of_99_bottles

use Standard

function Bottles:-> Integer

derived MaxBottles = 99

init InitRule

rule InitRule =
	par
		Bottles := MaxBottles
		program(self) := @Main
	endpar

rule GetCorrectBottlesTense(bottles) =
	return res in
  		if bottles > 1 then
    		res := bottles + " bottles"
  		else if bottles = 1 then
    		res := bottles + " bottle"
  		else
    		res := "No more bottles"

rule Main =
	seq
		while (Bottles > 0) do
		par
    		print 
    			GetCorrectBottlesTense(Bottles) + " of beer on the wall,\n" +
				GetCorrectBottlesTense(Bottles) + " of beer.\n" +
				"Take one down, pass it around.\n" +
				GetCorrectBottlesTense(Bottles - 1) + " of beer on the wall.\n"
			Bottles := Bottles - 1
		endpar
  	next
  		par
    		print
				"No more bottles of beer on the wall,\n" +
				"No more bottles of beer.\n" +
				"Go to the store, get some more!\n" +
				MaxBottles + " bottles of beer on the wall.\n"
			program(self) := undef
		endpar

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Uses state transiton to instead of loopsSerguei Michtchenko04/02/100

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: