Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:237:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: SELECT data, created, headers, expire, serialized FROM cache_menu WHERE cid = 'links:navigation:page-cid:node/6348:1'\";s:5:\"%file\";s:43:\"/home/javamx/public_html/includes/cache.inc\";s:5:\"%line\";i:26;}', 3, '', 'http://www.javamexico.org/foros/ceylon/string_calculator_en_ceylon', '', '54.81.17.43', 1435854704) in /home/javamx/public_html/includes/database.mysql.inc on line 128

Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:259:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: SELECT data, created, headers, expire, serialized FROM cache_menu WHERE cid = 'links:navigation:tree-data:c1af39c84b626b00e4b096f086edaa77'\";s:5:\"%file\";s:43:\"/home/javamx/public_html/includes/cache.inc\";s:5:\"%line\";i:26;}', 3, '', 'http://www.javamexico.org/foros/ceylon/string_calculator_en_ceylon', '', '54.81.17.43', 1435854704) in /home/javamx/public_html/includes/database.mysql.inc on line 128

Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:152770:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: UPDATE cache_menu SET data = 'a:2:{s:4:\\"tree\\";a:60:{i:1;a:2:{s:4:\\"link\\";a:37:{s:14:\\"load_functions\\";s:0:\\"\\";s:16:\\"to_arg_functions\\";s:0:\\"\\";s:15:\\"access_callback\\";s:1:\\"1\\";s:16:\\"access_arguments\\";s:6:\\"a:0:{}\\";s:13:\\"page_callback\\";s:16:\\&q in /home/javamx/public_html/includes/database.mysql.inc on line 128

Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:346:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: UPDATE cache_menu SET data = 'links:navigation:tree-data:c1af39c84b626b00e4b096f086edaa77', created = 1435854704, expire = 0, headers = '', serialized = 0 WHERE cid = 'links:navigation:page-cid:node/6348:1'\";s:5:\"%file\";s:43:\"/home/javamx/public_html/includes/cache.inc\";s:5:\"%line\";i:109;}', 3, '', 'http://www.javamexico.org/foros/ceylon/string_calculator_en_ceylon', � in /home/javamx/public_html/includes/database.mysql.inc on line 128

Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:240:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: SELECT data, created, headers, expire, serialized FROM cache_menu WHERE cid = 'links:primary-links:page-cid:node/6348:1'\";s:5:\"%file\";s:43:\"/home/javamx/public_html/includes/cache.inc\";s:5:\"%line\";i:26;}', 3, '', 'http://www.javamexico.org/foros/ceylon/string_calculator_en_ceylon', '', '54.81.17.43', 1435854704) in /home/javamx/public_html/includes/database.mysql.inc on line 128

Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:262:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: SELECT data, created, headers, expire, serialized FROM cache_menu WHERE cid = 'links:primary-links:tree-data:bb8683b943afb88b137c1a0df7d90318'\";s:5:\"%file\";s:43:\"/home/javamx/public_html/includes/cache.inc\";s:5:\"%line\";i:26;}', 3, '', 'http://www.javamexico.org/foros/ceylon/string_calculator_en_ceylon', '', '54.81.17.43', 1435854704) in /home/javamx/public_html/includes/database.mysql.inc on line 128

Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:18417:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: UPDATE cache_menu SET data = 'a:2:{s:4:\\"tree\\";a:10:{i:77;a:2:{s:4:\\"link\\";a:37:{s:14:\\"load_functions\\";N;s:16:\\"to_arg_functions\\";N;s:15:\\"access_callback\\";N;s:16:\\"access_arguments\\";N;s:13:\\"page_callback\\";N;s:14:\\"page_arguments\\";N;s:5:\\"title\\";N;s:14:\\"title_callback\\"; in /home/javamx/public_html/includes/database.mysql.inc on line 128

Warning: Table './javamexicoorg_javamexicoorg/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:352:\"Table './javamexicoorg_javamexicoorg/cache_menu' is marked as crashed and should be repaired\nquery: UPDATE cache_menu SET data = 'links:primary-links:tree-data:bb8683b943afb88b137c1a0df7d90318', created = 1435854704, expire = 0, headers = '', serialized = 0 WHERE cid = 'links:primary-links:page-cid:node/6348:1'\";s:5:\"%file\";s:43:\"/home/javamx/public_html/includes/cache.inc\";s:5:\"%line\";i:109;}', 3, '', 'http://www.javamexico.org/foros/ceylon/string_calculator_en_ceylon' in /home/javamx/public_html/includes/database.mysql.inc on line 128
String Calculator en Ceylon | Java México

String Calculator en Ceylon

Ya otros miembros de la comunidad pusieron aquí su solución a la kata de String Calculator, en Groovy y Kawa y creo que hay otras también.

Aquí está mi solución en Ceylon:

Integer add(String numbers) {
    if (numbers.empty) {
        return 0;
    }
    {String*} parts;
    if (numbers.startsWith("//")) {
        doc "Para indicar delimitador propio, debe haber al menos dos lineas"
        assert(exists firstNewline = numbers.firstOccurrence("\n"));
        value delim = numbers[2..firstNewline-1];
        if (delim.startsWith("[") && delim.endsWith("]")) {
            value delims = StringBuilder();
            for (d in delim.split("[]")) {
                delims.append(d);
            }
            parts = numbers[firstNewline+1:numbers.size].split(delims.string);
        } else {
            parts = numbers[firstNewline+1:numbers.size].split(delim);
        }
    } else {
        parts = numbers.split(",\n");
    }
    value nums = { for (s in parts) if (exists i=parseInteger(s.trimmed)) i>1000 then 0 else i };
    if (nonempty n=nums.filter((Integer i) => i<0).sequence) {
        throw Exception("Negatives not allowed: ``n``");
    } else if (nonempty n=nums.sequence) {
        return sum(n);
    }
    return 0;
}

void run() {
    assert(add("")==0);
    assert(add("1")==1);
    assert(add("1,2")==3);
    assert(add("1
                2"
)==3);
    assert(add("//;
                1;2"
)==3);
    try {
        add("-1,2,-3,4");
        doc "Negative numbers shouldn't be allowed"
        assert(false);
    } catch (Exception e) {
        print(e.message);
    }
    assert(add("2,1001")==2);
    assert(add("2,1000")==1002);
    assert(add("//[AB][cd]
                1cd2AB3"
)==6);
    print("ok");
}

El módulo de lenguaje no incluye expresiones regulares, pero para los requerimientos de la kata realmente no se necesitan.