14

DrRacket running R5RS says that 1### is a perfectly valid Scheme number and prints a value of 1000.0. This leads me to believe that the pound signs (#) specify inexactness in a number, but I'm not certain. The spec also says that it is valid syntax for a number literal, but it does not say what those signs mean.

Any ideas as to what the # signs in Scheme number literals signifiy?

2 Answers 2

16

The hash syntax was introduced in 1989. There were a discussion on inexact numbers on the Scheme authors mailing list, which contains several nice ideas. Some caught on and some didn't.

http://groups.csail.mit.edu/mac/ftpdir/scheme-mail/HTML/rrrs-1989/msg00178.html

One idea that stuck was introducing the # to stand for an unknown digit. If you have measurement with two significant digits you can indicate that with 23## that the digits 2 and 3 are known, but that the last digits are unknown. If you write 2300, then you can't see that the two zero aren't to ne trusted. When I saw the syntax I expected 23## to evaluate to 2350, but (I believe) the interpretation is implementation dependent. Many implementation interpret 23## as 2300.

The syntax was formally introduced here:

http://groups.csail.mit.edu/mac/ftpdir/scheme-mail/HTML/rrrs-1989/msg00324.html

EDIT

From http://groups.csail.mit.edu/mac/ftpdir/scheme-reports/r3rs-html/r3rs_8.html#SEC52

An attempt to produce more digits than are available in the internal machine representation of a number will be marked with a "#" filling the extra digits. This is not a statement that the implementation knows or keeps track of the significance of a number, just that the machine will flag attempts to produce 20 digits of a number that has only 15 digits of machine representation:

3.14158265358979##### ; (flo 20 (exactness s))

EDIT2

Gerald Jay Sussman writes why the introduced the syntax here:

http://groups.csail.mit.edu/mac/ftpdir/scheme-mail/HTML/rrrs-1994/msg00096.html

2
  • +1, much more useful than mine, but I'll leave it for the links. Is this specified anywhere else in RnRS? Jun 8, 2012 at 0:41
  • 1
    It is difficult to find much. One tidbit is from the R3RS manual on the format section. If an implementation is asked to write a number with 20 digits, but only 15 digits in the internal representation is known, then it can write # in place of the unknown digits. Since write can produce these numbers, the procedure read must also handle these.
    – soegaard
    Jun 8, 2012 at 11:13
8

Here's the R4RS and R5RS docs regarding numerical constants:

To wit:

If the written representation of a number has no exactness prefix, the constant may be either inexact or exact. It is inexact if it contains a decimal point, an exponent, or a "#" character in the place of a digit, otherwise it is exact.

Not sure they mean anything beyond that, other than 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.