real language

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

Language BeanShell

Author:Tom Edelson
Score: (3.33 in 3 votes)
// 99bottles.bsh
// Tom Edelson, last modified 2005-06-18

// This is BeanShell, a scripting language based on, and implemented in,
// Java.
// Mostly, the BeanShell language just is Java; but type declarations
// on variables are optional, and some scripting-friendly features
// have been added.  One of these features is the ability of a method
// to return a "closure", which is a bundle of [persistent] data and
// code; thus, like an object, but not derived from a class.
// In this example, each of the methods "newWall" and "newSinger" creates and
// returns a closure, whose content is defined by statements,
// and nested method definitions, within the "constructor" itself.

// For more information on BeanShell, and to download it, visit

formatBottleCount (number) {

    if (number == 0) {
        return "No bottles ";

    if (number == 1) {
        return "One bottle ";

    return number + " bottles ";

} // end method formatBottleCount

newWall (initialCount) {

    count = initialCount;

    getCount () {
        return count;

    hasBottles () {
        return count > 0;

    takeOne () {
        return count;

    return this;

} // end method newWall

newSinger (wallRef) {

    wall = wallRef;
    count = wall.getCount();
    countString = formatBottleCount (count);
    print ("");

    singVerse () {

        print (countString + "of beer on the wall,");
        print (countString + "of beer;");

        count = wall.takeOne();
        print ("Take one down, pass it around,");

        countString = formatBottleCount (count);
        print (countString + "of beer on the wall.");
        print ("");
    } // end method singVerse

    finish () {
        print ("Gotta be another beer wall around here somewhere ...");
        print ("");

    return this;

} // end method newSinger

// Main program code:

wall = newWall (99);

singer = newSinger (wall);

while (wall.hasBottles()) {


// end of file "99bottles.bsh".

Download Source | Write Comment

Alternative Versions


>>  LUCYjS said on 02/07/10 04:02:52

LUCYjS I think it's charismatic, because it exhibit a very academic-focussed attitude. Preserving the honesty of the academic system seems to be a greatest importance, although directly enjoin refunded ads for such a service seems a forceless response. When the firm is known by your friends who were animated with the results of the alliance, about this good topic . But don't foreget always to use <a href="">plagiarism checker</a> run them through this plagiarism detection system for absolute checking and make sure that your material is authentic.

>>  cosplay said on 06/09/10 08:42:47

cosplay <a href="">top jewelry </a>
<a href="">fashion blog</a>
<a href="">life world</a>
<a href="">choose handbag</a>
<a href="">Tiffany Jewellery</a>
<a href="">fashion life</a>
<a href="">manoloblahnik sale</a>
<a href="" >xmas gift</a>
<a href="">Ckloo</a>
<a href=""> jewellery</a>
<a href="">dresses </a>
<a href="">shoes blog</a>
<a href="">jewellery</a>
<a href="">ed hardy blog </a>
<a href="">wedding sale</a>

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: