Interlude · Pierre Menard

The same task, written three times.

Borges imagined a writer who produced a few chapters of Don Quixote word for word, and argued they meant something new because of who wrote them and when. Here the opposite: the same program, three hands, three different texts. Shorter does not always win, and Aleph is not always shorter.

Task: Print fizzbuzz from 1 to 30.

Aleph4 lines · 150 chars · +4 examples
fn fizz n:i64 -> str
 ex fizz 3 = "fizz"
 ex fizz 5 = "buzz"
 ex fizz 15 = "fizzbuzz"
 ex fizz 7 = "7"
 if == 0 % n 15 "fizzbuzz" if == 0 % n 3 "fizz" if == 0 % n 5 "buzz" show n
fn main -> unit
 print join map @fizz range 1 31 "\n"
Python11 lines · 220 chars
def fizz(n):
    if n % 15 == 0:
        return "fizzbuzz"
    if n % 3 == 0:
        return "fizz"
    if n % 5 == 0:
        return "buzz"
    return str(n)

def main():
    for n in range(1, 31):
        print(fizz(n))
C16 lines · 336 chars
#include <stdio.h>

int main(void) {
    int n;

    for (n = 1; n <= 30; n += 1) {
        if (n % 15 == 0) {
            puts("fizzbuzz");
        } else if (n % 3 == 0) {
            puts("fizz");
        } else if (n % 5 == 0) {
            puts("buzz");
        } else {
            printf("%d\n", n);
        }
    }
    return 0;
}

Aleph is shortest: one expression per rule, no loop boilerplate.

Sources: tests/aph/bench_*.aph, bench/ref/py, bench/ref/c. Comments, docstrings and the Python main guard removed; Aleph characters counted without its examples, which the others do not have. Tokens with real tokenizers: not measured yet.

Next · PostscriptWhat has actually been seen so far →