[comp.lang.scheme] Are numbers self evaluating?

amh@cunixb.cc.columbia.edu (Adam M. Heyman) (02/27/91)

While fooling around with MIT Scheme 7.1, found this interesesting phenomena.
Apparently, multidigit numbrs are not self evaluating, they need to go through
adds (+) and multiplies (*) in order to evaluate.
What follows is an edited journal of a session:

	(trace +)
	Automagically impurifying an object...  ;;What the heck does this mean?
	;No value

	1
	;Value: 1
	10
	[Entering #[compound-procedure 2 +]
	    Args: 10
        	  0]
	[10
	      <== #[compound-procedure 2 +]
	    Args: 10
	          0]
	;Value: 10
	123
	[Entering #[compound-procedure 2 +]
	    Args: 10
	          2]
	[12
	      <== #[compound-procedure 2 +]
	    Args: 10
	          2]
	[Entering #[compound-procedure 2 +]
	    Args: 120
	          3]
	[123
	      <== #[compound-procedure 2 +]
	    Args: 120
	          3]
	;Value: 123

etc.

This phenomena holds also for negative numbers, i.e. only -9,-8,...0,...9 are
evaluated without supporting math functions, and can also be seen by tracing
* instead of +.
If anyone out there has some insight as to why Scheme is doing this, please
let me know. I would be very interested to learn why it decomposes numbers,
and then builds them back up (from the point of view of the user, I realize
that the decomposition is probably just the way the input handler functions,
but this is pure conjecture), especially since numbers in scheme are supposed
to be self evaluating.

 Adam Heyman
 amh@cunixb.cc.columbia.edu

jinx@zurich.ai.mit.edu (Guillermo J. Rozas) (02/27/91)

In article <1991Feb26.205210.21352@cunixf.cc.columbia.edu> amh@cunixb.cc.columbia.edu (Adam M. Heyman) writes:

   Path: ai-lab!mintaka!snorkelwacker.mit.edu!usc!wuarchive!bcm!dimacs.rutgers.edu!rutgers!cunixf.cc.columbia.edu!cunixb.cc.columbia.edu!amh
   From: amh@cunixb.cc.columbia.edu (Adam M. Heyman)
   Newsgroups: comp.lang.scheme
   Date: 26 Feb 91 20:52:10 GMT
   Sender: news@cunixf.cc.columbia.edu (The Daily News)
   Organization: Columbia University
   Lines: 53

   While fooling around with MIT Scheme 7.1, found this interesesting
   phenomena.  Apparently, multidigit numbrs are not self evaluating,
   they need to go through adds (+) and multiplies (*) in order to
   evaluate.  What follows is an edited journal of a session:

[journal deleted]

   If anyone out there has some insight as to why Scheme is doing
   this, please let me know. I would be very interested to learn why
   it decomposes numbers, and then builds them back up (from the
   point of view of the user, I realize that the decomposition is
   probably just the way the input handler functions, but this is
   pure conjecture), especially since numbers in scheme are supposed
   to be self evaluating.


You are confusing reading with evaluation.

Self evaluation means that the value of a numeral is the number it
represents without needing to quote it.

You are right in assuming that the process that you've discovered is
the act of constructing the number from the individual characters that
compose the numeral, but it is not the evaluation of the number.

The interpreter is given character sequences which must be converted
to Scheme objects before they can be evaluated.  Numbers are built one
digit at a time by the process that you noticed.  Once they are built,
evaluation is idempotent on them.

In other words, what you saw was READ doing its job.  Your input had
not yet been given to EVAL (and will never be, since EVAL does not
deal with character strings).

If you think about it, you'll realize that C's scanf, Pascal's read
and almost every other language's formatted reader must do something
equivalent.  C and Pascal compilers use similar things for
constructing self-evaluating numbers at compile time.

BTW, the message in

	(trace +)
	Automagically impurifying an object...  ;;What the heck does this mean?
	;No value

means that the value of + was in a static area of memory that cannot
be written (pure space).  Thus when you asked for it to be traced
(which involves a side effect), it needed to be moved out before your
request could be honored.  The message is a notification that an
object was being moved out of pure space.  I personally think that
such messages should not appear unless explicitly allowed by the user,
but...

alms@cambridge.apple.com (Andrew L. M. Shalit) (02/27/91)

In article <1991Feb26.205210.21352@cunixf.cc.columbia.edu> amh@cunixb.cc.columbia.edu (Adam M. Heyman) writes:

   While fooling around with MIT Scheme 7.1, found this interesesting phenomena.
   Apparently, multidigit numbrs are not self evaluating, they need to go through
   adds (+) and multiplies (*) in order to evaluate.

My guess is that the reader uses + to add up the digits of a multi-digit
number.  This doesn't mean that such numbers aren't self-evaluating.
They are.  It just means that + is used to convert them from text to
objects.

    -andrew

mkatz@garlic.stanford.EDU (Morris Katz) (02/28/91)

   Date: 26 Feb 91 20:52:10 GMT
   From: "Adam M. Heyman" <amh@cunixb.cc.columbia.edu>
   Organization: Columbia University

   While fooling around with MIT Scheme 7.1, found this interesesting phenomena.
   Apparently, multidigit numbrs are not self evaluating, they need to go through
   adds (+) and multiplies (*) in order to evaluate.
   What follows is an edited journal of a session:

	   (trace +)
	   Automagically impurifying an object...  ;;What the heck does this mean?

The MIT Cscheme heap is divided into three sections: constant space, pure
space, and the normal heap.  Pure space contains objects which contain ,no
pointers back to objects in the normal heap.  This means that objects in pure
space do not have to be scanned at GC time.  This is basically a poor mans
generation scheme.  When you trace a procedure in Cscheme, a field in the
closure for that procedure is modifed to point to the trace code.  This code
lives in the normal heap.  Since + is installed in pure space by default,
tracing it would cause a pointer to exist from pure space to the normal heap,
violating the invarient.  The Cscheme system handles this problem by
impurifying + by moving it from pure space to the normal heap before instaling
the tracing pointer in the closure.
--------------------
Morry Katz
katz@cs.stanford.edu
--------------------