1 Introduction
2 Interface
write-number-as-english
write-number-as-short-scale-english
write-number-as-long-scale-english
number->english
number->short-scale-english
number->long-scale-english
3 History
4 Legal
Version: 0.2

numspell: Spelling Numbers as English in Scheme

Neil Van Dyke

License: LGPL 3   Web: http://www.neilvandyke.org/numspell-scheme/

 (require (planet neil/numspell:1:1))

1 Introduction

The numspell library provides the ability to “spell” Scheme numbers in English. This is useful for writing numbers on banking checks and other legal documents, as well as for speech generation.

Most rational numbers in Scheme are presently supported. For example:

  (number->english 123456)
  ==> "one hundred twenty-three thousand four hundred fifty-six"
  (number->english (/ 4 -6))
  ==> "negative two over three"
  (number->english (exact->inexact (/ 4 -6)))
  ==> "negative zero point six six six six six six"

The number names supported by numspell are taken from a version of the Wikipedia “Names of large numbers” article. Both short and long scales are supported, through different procedures, with short scale being the default. For example:

  (number->english             (expt 10 15))
  ==> "one quadrillion"
  (number->short-scale-english (expt 10 15))
  ==> "one quadrillion"
  (number->long-scale-english  (expt 10 15))
  ==> "one thousand billion"

Note: Some numbers, such as very large and very small non-integers printed by some Scheme implementations in exponential notation, are not supported by the current version of numspell.

numspell requires R5RS, SRFI-6 (string ports), and SRFI-11 (let-values).

2 Interface

The public interface consists of a few procedures.

(write-number-as-english num port)  any/c
  num : any/c
  port : any/c

(write-number-as-short-scale-english num    
  port)  any/c
  num : any/c
  port : any/c

(write-number-as-long-scale-english num    
  port)  any/c
  num : any/c
  port : any/c

Spell number num to output port port. If num cannot be spelt, an error is signaled.

(number->english num)  any/c
  num : any/c

(number->short-scale-english num)  any/c
  num : any/c

(number->long-scale-english num)  any/c
  num : any/c

Yield a string that spells number num. If num cannot be spelt, an error is signaled.

3 History

4 Legal

Copyright (c) 2006–2009 Neil Van Dyke. This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License (LGPL 3), or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.