Re: Speed/safety trade-offs and types vs. system classes



On Feb 20, 11:28 am, p...@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)
wrote:

Trying to get more answers by disassembling everyhing piece by piece.

Another thing which is related to my problem is that CLISP
automatically chooses between bit, (integer 0 16777215) and (integer
(16777215)) for the representation of numbers, and that type
declarations on lexical variables are ignored.

That's not so, and again, it is not something specific to clisp.

What is the type of 42?

(every (lambda (type) (typep 42 type))
      '( (integer 42 42) (integer 40 44) (integer 30 50) (integer 0 1000)
         fixnum integer real number
         (signed-byte 7) (signed-byte 9) (signed-byte 10) (signed-byte 73)
         (unsigned-byte 6) (unsigned-byte 16) (unsigned-byte 42) (unsigned-byte 5600)
         (member :a 'hello 42) (member 101010 42 '|THE-answer|)
         ;; ...
         ))

Types are sets and values are elements.  When you have a single
element, it may belong to an infinite number of sets, therefore it has
an infinite number of types.

When I write the next thing, what does it really mean ?

(let
((a 0))
(declare (type (integer 10 12) a))
(setf a 10)
(setf a 13))

I would expect it to mean that a should only hold numbers of fixed
size, with a value between 10 and 12 inclusive. Based upon this
assumption, I would expect the program to throw an exception (or a fit
maybe), because I initialise it with zero, or either at the place
where I assign 13 to the variable. However, it returns 13, which is
correct as far as the pure functionality of the statement goes.

Then what are type declarations in CL really usable for? I would
assume either to impose more correctness and validation upon the
program, which I suppose would be the case in any CL implementation,
or to do possible optimisations, which certainly works with SBCL.

Regards,

Jurgen
.



Relevant Pages

  • Re: please review my code
    ... or just say my code sucks and/or i'm ... This can break code using lexical variables of same ... (setf (aref column position) ...
    (comp.lang.lisp)
  • Re: Writing a Compiler: Lisp or Scheme or Haskell?
    ... Declarations are for these things. ... Macros are a last resort when you cannot get the compiler to act ... for in (reverse mparams) ... (setf body ``(multiple-value-bind,',(reverse names) ...
    (comp.lang.lisp)
  • Re: passing parameters by reference
    ... > operators in C for Lisp lexical variables. ... (setf (dereference ref) ... so that the list of store variables can be dotted. ... MULTIPLE-VALUE-BIND &REST as a lexical variable. ...
    (comp.lang.lisp)
  • Re: Ultimate debunking of Cantors Theory
    ... people will make declarations, such as that there ... are no infinite sets, ... They say it as if it is revealed truth. ... totality of natural numbers is an infinite totality. ...
    (sci.math)
  • Re: Ultimate debunking of Cantors Theory
    ... people will make declarations, such as that there ... are no infinite sets, ... They say it as if it is revealed truth. ... totality of natural numbers is an infinite totality. ...
    (sci.math)

Loading