[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]

It strikes me that there should be a way in LISP to specify that a certain
value locally will be fixnum or flonum. The case arises in Fortran and all
sorts of crockish ways have been devised (and (sigh) are being used) to
conquer the problem. (ARRAYCALL FIXNUM N 5.) will declare locally that N
is a fixnum array -- this is not necessarily the case, but acts as a local
declaration to the compiler saying compile a fixnum call the the N array
anyway, and screw me if I am wrong.  I don't have a similar mechanism however
that will cause an efficient compilation of: (LESSP (CAR A) 3.) since I can't
declare that (CAR A) is a fixnum. There are several alternatives:

[1] As JONL suggested, either by macro or explicitly I could use
    (LESSP (+ (CAR A)) 3.) which will act as an explicit declaration
    to the compiler that (CAR A) is fixnum. This is OK, but is an awfully
    unclean way to go about it. I hope one of these other suggestions will
    be taken in LISP and/or NIL.

[2] Create primitives of the form DECLARE-FIX, DECLARE-FLOAT, etc., which
    would have the following effect -- in interpreted lisp they could be
    either something trivial like (LAMBDA (X) X) or something more complex
    that either did a (LHS X 0.) on it to actually change its type,
    or did a (LAMBDA (X) (COND ((FIXP X) X) (T (ERR)))) to flag an error if
    the thing was not the right type -- I am not really concerned with
    what it does in the interpreter, but hopefully in the compiler
    something like (LESSP (DECLARE-FIX (CAR A)) 3.) would be converted to
    (< (CAR A) 3.) 

[3] An alternative (probably too advanced for MacLISP but maybe not for NIL
    is something JM brought up - LISP's big weakness is the locality of
    structure - LIST's lose becuz they are assumed to be completely random
    in content) would be to allow a declaration of the form
    which would say that A is a list of first element fixnum, second
    element NOTYPE, third elem FIXNUM, and some optional elements also
    NO-TYPE following. If the * were omitted it would mean that
    (LENGTH A) would be compilable as the constant 3, but could still be
    referenced as (LENGTH A) in the code without loss of efficiency and
    allowing the user to change his data easily by just modifying the

Choice 2 I would like to see in MacLISP very soon if there are not too
many objections. It certainly wouldn't screw anyone's code and would be a
very nice feature for me. I would not object if it were even implemented
in the compiler as (DEFUN DECLARE-FIX MACRO (X) (LIST '+ (CADR X))) as
long as it was not me that had to guarantee its efficiency. For me to
be responsible for such a thing means that my software is relying upon
a given implementation of the compiler, etc., which I think is non-optimal.

Your opinions please? Thanx --kmp