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

(Conventional solution with expr module)

Date:03/12/12
Author:Pete Elmore
URL:http://debu.gs/
Comments:0
Info:http://www.vitanuova.com/inferno/papers/sh.html
Score: (3.00 in 6 votes)
#!/dis/sh
# Accepts an optional argument for a number of bottles to start at.
load std expr echo

fn pluralize_bottles() {
	b := $1^' bottles'
	if {~ $1 1} {
		b = '1 bottle'
	} {~ $1 0} {
		b = 'No more bottles'
	}
	echo $b
}

bottles = $1
if {no $bottles} { bottles = 99 }

for i in `{echo ${expr $bottles 1 seq}} {
	b := `{pluralize_bottles $i}
	bn := `{pluralize_bottles ${expr $i 1 -}} 

	echo $b of beer on the wall,
	echo $b of beer!
	echo Take one down, pass it around,
	echo $bn of beer on the wall.
	echo
}

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: