Re: Speed/safety trade-offs and types vs. system classes
- From: chthon <jurgen.defurne@xxxxxxxxxx>
- Date: Fri, 20 Feb 2009 03:56:31 -0800 (PST)
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
.
- Follow-Ups:
- Re: Speed/safety trade-offs and types vs. system classes
- From: Thomas A. Russ
- Re: Speed/safety trade-offs and types vs. system classes
- From: Tobias C. Rittweiler
- Re: Speed/safety trade-offs and types vs. system classes
- References:
- Speed/safety trade-offs and types vs. system classes
- From: jurgen_defurne
- Re: Speed/safety trade-offs and types vs. system classes
- From: Pascal J. Bourguignon
- Speed/safety trade-offs and types vs. system classes
- Prev by Date: Re: Trying to make some sense of these HW questions... (Here is what I have so far)
- Next by Date: Re: Trying to make some sense of these HW questions... (Here is what I have so far)
- Previous by thread: Re: Speed/safety trade-offs and types vs. system classes
- Next by thread: Re: Speed/safety trade-offs and types vs. system classes
- Index(es):
Relevant Pages
|
Loading