Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of # in Scheme number literals

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?

like image 251
Abhay Buch Avatar asked Jun 07 '12 15:06

Abhay Buch


People also ask

What is the word meaning means?

meaning. / (ˈmiːnɪŋ) / noun. the sense or significance of a word, sentence, symbol, etc; import; semantic or lexical content. the purpose underlying or intended by speech, action, etc.

What is inshallah meaning?

Definition of inshallah : if Allah wills : God willing.


2 Answers

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

like image 116
soegaard Avatar answered Oct 16 '22 18:10

soegaard


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

  • R4RS 6.5.4 Syntax of numerical constants
  • R5RS 6.2.4 Syntax of 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.

like image 29
Dave Newton Avatar answered Oct 16 '22 18:10

Dave Newton