This is neat...

Miscellaneous Forums/General Discussion/This is neat...

Lisp rocks. It has a format form that behaves kind of like printf in C. One of the directives to format automatically prints a number as a word.

For instance

(format nil "~r" 3523)

prints "three thousand five hundred twenty-three"

Just messing around I found that it can print this...

(format nil "~r" 160693804425899027554196209234434342342423424354353525335235235233)

"one hundred sixty vigintillion six hundred ninety-three novemdecillion eight hundred four octodecillion four hundred twenty-five septendecillion eight hundred ninety-nine sexdecillion twenty-seven quindecillion five hundred fifty-four quattuordecillion one hundred ninety-six tredecillion two hundred nine duodecillion two hundred thirty-four undecillion four hundred thirty-four decillion three hundred forty-two nonillion three hundred forty-two octillion four hundred twenty-three septillion four hundred twenty-four sextillion three hundred fifty-four quintillion three hundred fifty-three quadrillion five hundred twenty-five trillion three hundred thirty-five billion two hundred thirty-five million two hundred thirty-five thousand two hundred thirty-three"


Now that's cool.

Vigintillion, novemdecillion .. you what?! Never new such number existed.

can it go higher? I know there are higher numbers named than that... try getting it out to a googol.

This particular lisp implentation (Allegro Common Lisp) only goes that high. Any higher and it spits out an error "return too long to print in english" or something to that effect.

I tested a couple of other lisp implementations and none of them went quite as high as the above number.

(well, actually the above number could be bigger...it could handle 999 vigintilion, but can't handle an extra digit)

The power of that function alone is amazing...for instance the following line

(format t "~{~{~a:~10t~a~%~}~%~}" *db*))

does a double (nested) loop (where the '{' intiates the loop) over the *db* variable, printing it's values in a tab column 10 spaces wide. So if *db* is a variable that contains a list of lists representing say audio cd entries, it might print the following

TITLE: Black Album
ARTIST: Metallica
RATING: 5
RIPPED: T

TITLE: Dark Side of the Moon
ARTIST: Pink Floyd
RATING: 10
RIPPED: T

etc...

(example taken from the free online book at http://www.gigamonkeys.com/book/)

Another cool example is

(format nil "~d" (/ 14124 52))

which prints 3531/13 <-- the simplified version of the expression 14124/52 which is what the (/ 14124 52) represents. Lisp handles fractions properly. It converts ints to bignums ...it can handle any size number

So the following, which is 4 * the huge number... returns the proper result

(* 4 222222222222222222222222222222222222222222222222222222222222222222222222222222222)

returns

888888888888888888888888888888888888888888888888888888888888888888888888888888888

Well.. that is the begining of a good music collection at least.