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 ITCL Shell

Date:04/20/05
Author:Steven Grady
URL:n/a
Comments:0
Info:n/a
Score: (2.89 in 9 votes)
#!/usr/local/bin/itcl_sh
# [incr Tcl] version of "99 bottles of beer"
# Author: Steven Grady
# grady@xcf.berkeley.edu

itcl_class bottle {
	constructor {config} {
		incr numBottles
	}

	destructor {
		incr numBottles -1
	}

	method drink {} {
		puts "Take one down, pass it around,"
		$this delete
	}

	proc numBottleStr {} {
		switch $numBottles {
		  0 {
			return "No more bottles of beer"
		  }
		  1 {
			return "1 bottle of beer"
		  }
		  default {
			return "$numBottles bottles of beer"
		  }
		}
	}

	proc numBottles {} {
		return $numBottles
	}

	common numBottles 0
}

proc createBottles {numBottles} {
	for {set i 0} {$i < $numBottles} {incr i} {
		bottle #auto
	}
}

createBottles 99
foreach b [itcl_info objects -class bottle] {
	set str [bottle :: numBottleStr]
	puts "$str on the wall, $str"
	$b drink
	puts "[bottle :: numBottleStr] on the wall."
}

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: