Annotation of researchv10dc/cmd/icon/tests/speller.icn, revision 1.1

1.1     ! root        1: procedure spell(n)
        !             2:    local m
        !             3:    n := integer(n)
        !             4:    return (
        !             5:       if n <= 12 then
        !             6:          "0zero,1one,2two,3three,4four,5five,6six,7seven,8eight,_
        !             7:             9nine,10ten,11eleven,12twelve," ? {
        !             8:                tab(find(n))
        !             9:                move(*n)
        !            10:                tab(upto(","))
        !            11:                }
        !            12:       else if n <= 19 then
        !            13:          spell(n[2] || "0") ?
        !            14:             (if ="for" then "four" else tab(find("ty"))) || "teen"
        !            15:       else if n <= 99 then
        !            16:          "2twen,3thir,4for,5fif,6six,7seven,8eigh,9nine," ? {
        !            17:             tab(upto(n[1]))
        !            18:             move(1)
        !            19:             tab(upto(",")) || "ty" ||
        !            20:                if n[2] ~= 0 then "-" || spell(n[2])
        !            21:             }
        !            22:       else if n <= 999 then
        !            23:          spell(n[1]) || " hundred" ||
        !            24:             (if (m := n[2+:2]) ~= 0 then " and " || spell(m))
        !            25:       else if n <= 999999999 then
        !            26:          spell(n[1:-3]) ?
        !            27:             (tab(find("thousand")) || (move(8) & "million") | "") ||
        !            28:             tab(0) ||
        !            29:             " thousand" ||
        !            30:             (if (m := n[-3:0]) ~= 0 then ", " || spell(m))
        !            31:       else
        !            32:          "number too large"
        !            33:       )
        !            34: end
        !            35: 
        !            36: procedure spellw(n)
        !            37:    write(n, "  ", spell(n))
        !            38:    return
        !            39: end
        !            40: 
        !            41: procedure main()
        !            42:    every spellw(1 to 25)
        !            43:    every spellw(30 to 110 by 3)
        !            44:    spellw(945123342)
        !            45:    every spellw(10000000 to 10000500)
        !            46: end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.