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 Vala

(Signals)

Date:03/26/10
Author:Hohoo
URL:n/a
Comments:1
Info:http://live.gnome.org/Vala/
Score: (2.78 in 9 votes)
class Bottles {
    private int amount = 99;
    private signal void bottles (bool on_the_wall);
    private signal void drink ();
    
    public Bottles () {
        bottles.connect (on_bottles);
        drink.connect (on_drink);
        
        sing ();
    }
    
    private void sing () {
        for (int i = 99; i >= 0; i--) {
            bottles (true);
            bottles (false);
            drink ();
            bottles (true);
            if (i != 0) {
                stdout.printf ("\n");
            }
        }
    }
    
    private void on_bottles (bool on_the_wall) {
        var w_end = "";
        var s_end = "";
        
        if (on_the_wall) {
            w_end = " on the wall";
        }
        
        if (amount != 1) {
            s_end = "s";
        }
        
        stdout.printf ("%d bottle%s of beer%s\n", amount, s_end, w_end);
    }
    
    private void on_drink () {
        if (amount != 0) {
            stdout.printf ("Take one down and pass it around\n");
            amount--;
        } else {
            stdout.printf ("Go to the store and buy some more\n");
            amount = 99;
        }
    }
    
    public static int main (string[] args) {
        Bottles b = new Bottles ();
        
        return 0;
    }
}

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
1Kahnamta04/16/072

Comments

>>  Jeremy List said on 08/12/10 03:09:26

Jeremy List I like vala, although this code has reduced my enthusiasm for it.

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: