chickadee » numspell

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

numspell

Description

Spelling Numbers as English in Scheme.

Author

Neil van Dyke

Requirements

numbers

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.

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.

Version

0.5
always uses numbers egg, now
0.4
Ported to Chicken 4
0.3
Initial release

License

Copyright 2006 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 2.1 of the License, 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/copyleft/lesser.html for details. For other license options and consulting, contact the author.