constant/constantp




On Wed, 22 Jul 2009, Robert Dodier wrote:

< On Wed, Jul 22, 2009 at 1:13 PM, Richard Fateman<fateman at cs.berkeley.edu> wrote:
< 
< > The way I understand the declarations ?(like float, ) is that they do
< > not inhibit assignment of values that disagree with the declarations.
< > They are advice to the compiler that should enable it to compile code
< > that is more specific, and will work faster. ?If object of the wrong
< > type are used, the computation may be incorrect.

This is the theory, but see below.

< 
< The point of declarations is to allow the application of identities which
< are true for any value in the declared class.
< (This subsumes compiler advice and lots more.)
< If later on you substitute an element from outside the declared class,
< you'll very likely get an incorrect result.

I think that maxima is inconsistent in these regards. Here are some examples:

(%i2) define_variable(xt,[],list);

(%o2) []
(%i3) xt : 1;

Error: xt was declared mode list, has value: 1
 -- an error.  To debug this try debugmode(true);
(%i4) define_variable(yt,0,integer);

(%o4) 0
(%i5) yt : %e;

Error: yt was declared mode fixnum, has value: %e
 -- an error.  To debug this try debugmode(true);
(%i6) define_variable(zt,0.0,float);

(%o6) 0.0
(%i7) zt : [];

(%o7) []


You can see that the the assignment operator ':' does some type-checking, 
but it is inconsistent. It was the first 2 examples that prompted my
original question. Also, when I looked at 'mset' in src/mlisp.lisp, I
could see that there is some type-checking (notably, for 'sysconst').

I have since realised that the online documentation for define_variable
explains how to force type-checking, so that one can hack a 'const'
class, for example.

Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.