二元变量的表示
Representation of a binary variable
您将如何找出 SBCL(可能还有其他 common-lisp 编译器)如何表示类型化变量。例如,SBCL 将类型为 (member +1 -1)
的变量转换为类型 (or (integer 1 1) (integer -1 -1))
。但这是一个位,一个 fixnum,或者甚至是 bignum?
嗯。很容易检查:
(type-of 1)
; ==> BIT
(type-of -1)
; ==> (integer -281474976710656 (0))
所以 -1
和 1
是不同的类型,但是在 CL 中有多重继承,所以 1
和 -1
确实是许多其他类型共同点:
(typep 1 'integer) ; ==> t
(typep 1 'fixnum) ; ==> t
(typep 1 'number) ; ==> t
(typep 1 't) ; ==> t
(typep 1 'bignum) ; ==> nil
(typep -1 'integer) ; ==> t
(typep -1 'fixnum) ; ==> t
(typep -1 'number) ; ==> t
(typep -1 't) ; ==> t
(typep -1 'bignum) ; ==> nil
当然还有:
(typep -1 '(member +1 -1)) ; ==> t
(typep 1 '(member +1 -1)) ; ==> t
所以只有1
是一点,都是fixnum,none都是bignums。这些值很可能存储在执行此操作的 CL 实现中的指针中。请注意,类型与实际存储关系不大。这两个值很可能存储为一个完整的机器字,在我的例子中是指针中的 8 个字节(64 位)。对于 bignum,您有 8 个字节指向堆对象,该对象已为实际值分配了额外的 space。
您将如何找出 SBCL(可能还有其他 common-lisp 编译器)如何表示类型化变量。例如,SBCL 将类型为 (member +1 -1)
的变量转换为类型 (or (integer 1 1) (integer -1 -1))
。但这是一个位,一个 fixnum,或者甚至是 bignum?
嗯。很容易检查:
(type-of 1)
; ==> BIT
(type-of -1)
; ==> (integer -281474976710656 (0))
所以 -1
和 1
是不同的类型,但是在 CL 中有多重继承,所以 1
和 -1
确实是许多其他类型共同点:
(typep 1 'integer) ; ==> t
(typep 1 'fixnum) ; ==> t
(typep 1 'number) ; ==> t
(typep 1 't) ; ==> t
(typep 1 'bignum) ; ==> nil
(typep -1 'integer) ; ==> t
(typep -1 'fixnum) ; ==> t
(typep -1 'number) ; ==> t
(typep -1 't) ; ==> t
(typep -1 'bignum) ; ==> nil
当然还有:
(typep -1 '(member +1 -1)) ; ==> t
(typep 1 '(member +1 -1)) ; ==> t
所以只有1
是一点,都是fixnum,none都是bignums。这些值很可能存储在执行此操作的 CL 实现中的指针中。请注意,类型与实际存储关系不大。这两个值很可能存储为一个完整的机器字,在我的例子中是指针中的 8 个字节(64 位)。对于 bignum,您有 8 个字节指向堆对象,该对象已为实际值分配了额外的 space。