tichy <ssbm2@...> writes:
> Hi. Is this ok ?
> CL-USER> (type-of (expt 10 10000))
> (INTEGER 536870912)
> I expected BIGNUM.
Why did you expect BIGNUM? The answer sbcl gave you is reasonable, is
it not? (What are you using TYPE-OF /for/? There are very few uses
for it in reasonable user code, I think.)
> CL-USER> (type-of (- (expt 10 10000)))
> hm.... bug? or I missed something ?
You missed something.
Specifically, you missed the requirement that the type specifier that
TYPE-OF returns must be a recognizable subtype of all built-in types
of which its argument is an element.
So (expt 10 10000) is an element both of unsigned-byte and of bignum,
so the type returned from TYPE-OF must be subtypep both of those;
however, (- (expt 10 10000)) is not an element of unsigned-byte, so
the system can return the bignum specifier.
Thank you very much for the explanations.
Christophe Rhodes wrote:
> (What are you using TYPE-OF /for/? There are very few uses
> for it in reasonable user code, I think.)
I want to write short tutorial (to cl) in my native language (Polish)
because there is no one worth mentioning :/
I think that I should write about DESCRIBE, APROPOS, INSPECT at the
very beginning of the tutorial:
CL-USER> (describe "Hello World")
"Hello World" is a vector with 11 elements.
Its element type is specialized to CHARACTER.
CL-USER> (describe 0)
0 is a BIT.
CL-USER> (describe 2)
2 is a (INTEGER 0 536870911).
CL-USER> (describe -2)
-2 is a FIXNUM.
It's ok, but not in first page of the tut...