Emacs Lisp: number-to-words-clisp and number-to-words functions using CLISP to get cardinal English numbers

Emacs Lisp: number-to-words-clisp and number-to-words functions using CLISP to get cardinal English numbers

Emacs Lisp does not have a built in function as Common Lisp to quickly return cardinal English numbers in words, so this function uses the external program CLISP or GNU Common Lisp to get the representation. Then a number 4 can be converted to word “four”

Good example is here, you may try to evalute the function:

(number-to-words-clisp 12800754)

It will return back the result such as twelve million, eight hundred thousand, seven hundred and fifty-four.

All this of course could be implemented in Emacs Lisp as well. This is quick workaround.

It is very handy when sending number of attachments from Dired through Emacs Lisp to friends and business associates. This function can then tell in the subject how many attachments are there, it alerts the receiver.

(defun number-to-words-clisp (n)
  "Returns the cardinal English number representation, for example if N is 4, it would return \"four\""
  (let* ((command (format "clisp -q -norc -x '(format t \"~R\" %d)'" n))
     (lines (split-string (shell-command-to-string command) "\n")))
    (car lines)))

(defun number-to-words (n)
  "Interactive function that returns written number representation by using CLISP and kills it into memory"
  (interactive "nNumber: ")
  (let ((number (number-to-words-clisp n)))
    (kill-new number)
    (message number)))

Leave Your Comment or Contact GNU.Support

Contact GNU.Support now. There is a simple rule at GNU.Support: if we can help you, we do, whenever and wherever necessary, and it's the way we've been doing business since 2002, and the only way we know


Full name:


E-mail:


Message: