Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

sort-body-stable-en

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Syntax:

Category#

collection

None.

Examples#

radix/corpus/sort/body-stable-en.fab (canonical · concept)#

# A body returns the sort key. Ties keep source order in both directions:
# descending is not the reverse of ascending.
class Person {
    mut string name
    mut int age
}

fn names(list<Person> ps) → string {
    mut string out ← ""
    for from ps let p {
        if out ≡ "" {
            out ← p.name
        } else {
            out ← out + " " + p.name
        }
    }
    return out
}

main {
    let list<Person> people ← [
        Person { name = "Livia", age = 30 },
        Person { name = "Marcus", age = 30 },
        Person { name = "Aulus", age = 25 },
        Person { name = "Cornelia", age = 25 },
        Person { name = "Titus", age = 40 }
    ]
    let list<Person> young ← sort via asc from people let p { return p.age }
    let list<Person> old ← sort via desc from people let p { return p.age }
    print names(young)
    print names(old)
    print names(people)
}

Expected output:

Aulus Cornelia Livia Marcus Titus
Titus Livia Marcus Aulus Cornelia
Livia Marcus Aulus Cornelia Titus