real language

Bookmarking Digg Diigo DZone Earthlink Google
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Magik

Author:Neil Pawson
Score: (2.83 in 6 votes)
## A nice, sturdy wall to put our bottles on
def_slotted_exemplar(:wall, { {:num_bottles,   _unset},
			      {:start_bottles, _unset}}, {})

## The number of bottles we started with
wall.define_slot_access(:start_bottles, :writable, :private)

## The number of bottles we have left
wall.define_slot_access(:num_bottles, :writable, :private)


	## Create a new wall with START_BOTTLES of beer sitting on it
	>> _clone.init(start_bottles)

_private _method wall.init(start_bottles)

	## Initialise the amount of beer to START_BOTTLES
	_self.num_bottles << _self.start_bottles << start_bottles

	>> _self  

_private _method wall.no_beer?
	## Are there any bottles of beer left?
	>> _self.num_bottles < 1
_private _method wall.beer_string(_optional uc_first?)

	## Return a string which says how many bottles of beer we have
	## left on the wall.
	## If UC_FIRST? is true and we have no beer left then the first
	## letter is capitalised.

	_if _self.no_beer?
		_if uc_first? _is _true _then num << "No more" _else num << "no more" _endif
		num << _self.num_bottles
	_if num _isnt 1 _then s << %s _else s << "" _endif

	>> write_string(num, " bottle", s, " of beer")

_private _method wall.drink_bottle()

	## Drink a bottle of beer and show how many we have left
	_self.num_bottles -<< 1
	write("Take one down and pass it around, ", _self.beer_string(), " on the wall.")

_method wall.drink_all_beer()

	## Drink all the bottles of beer we have on the wall, printing
	## out the lyrics on the way.

	# Drink until dry
		write(_self.beer_string(_true), " on the wall, ", _self.beer_string(), %.)
		_if _self.no_beer? _then _leave _endif

	_self.num_bottles << _self.start_bottles
	write("Go to the store and buy some more, ", _self.beer_string(), " on the wall.")

# Create a new wall stocked with beer, then drink it

Download Source | Write Comment

Alternative Versions


>>  Swetha Prasanna said on 09/23/09 10:31:52

Swetha Prasanna Good..Infact!!
Any other such things from you. I am just eager to see and try.

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!




Security Code: