Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

JavaLisp

Name: Anonymous 2012-06-25 3:32


function Account(balance) {
    function deposit(amount) {
        balance += amount;
    }
    function withdraw(amount) {
        balance -= amount;
    }
    function dispatch(msg) {
        switch (msg) {
            case 'deposit': return deposit;
            case 'withdraw': return withdraw;
        }
    }
    return dispatch;
}

acc = Account(300);
acc('deposit')(50);
acc('withdraw')(10);

Name: Anonymous 2012-06-25 7:32

PHP doesn't allow function chaining...
Even C allows it. PHP truly is amazingly bad.

#include <stdio.h>

int (*get_puts(void))(const char*)
{   
        return puts;
}

int main()
{
        get_puts()("Hello, world!");
        return 0; 
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List