17 Unsafe Operations
| (require racket/unsafe/ops) | package: base |
racket/base 和 racket 提供的所有函数和形式都会检查其参数,以确保参数符合合约和其他约束。例如,vector-ref 检查其参数以确保第一个参数是 vector,第二个参数是精确整数,且第二个参数在 0 到 vector 长度减一之间(含)。
racket/unsafe/ops 提供的函数是 不安全(unsafe)的。它们有特定的约束,但这些约束不会被检查,这使得系统能够生成和执行更快的代码。如果参数违反了不安全函数的约束,该函数的行为和结果是不可预测的,整个系统可能会崩溃或损坏。
racket/unsafe/ops 的所有导出绑定都受 protect-out 意义上的保护,因此可以通过调整代码检查器来阻止对不安全操作的访问(参见 Code Inspector)。
17.1 Unsafe Numeric Operations
procedure
(unsafe-fx+ a ...) → fixnum?
a : fixnum?
procedure
(unsafe-fx- a b ...) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fx* a ...) → fixnum?
a : fixnum?
procedure
(unsafe-fxquotient a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxremainder a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxmodulo a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxabs a) → fixnum?
a : fixnum?
Changed in version 7.0.0.13 of package base: 允许 unsafe-fx+ 和 unsafe-fx* 接受零个或多个参数,并允许 unsafe-fx- 接受一个或多个参数。
procedure
(unsafe-fxand a ...) → fixnum?
a : fixnum?
procedure
(unsafe-fxior a ...) → fixnum?
a : fixnum?
procedure
(unsafe-fxxor a ...) → fixnum?
a : fixnum?
procedure
(unsafe-fxnot a) → fixnum?
a : fixnum?
procedure
(unsafe-fxlshift a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxrshift a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxrshift/logical a b) → fixnum?
a : fixnum? b : fixnum?
Changed in version 7.0.0.13 of package base: 允许 unsafe-fxand、unsafe-fxior 和 unsafe-fxxor 接受零个或多个参数。
Changed in version 8.8.0.5: 添加了 unsafe-fxrshift/logical。
procedure
(unsafe-fxpopcount a) → fixnum?
a : (and/c fixnum? (not/c negative?))
procedure
(unsafe-fxpopcount32 a) → fixnum?
a : (and/c fixnum? (integer-in 0 #xFFFFFFFF))
procedure
(unsafe-fxpopcount16 a) → fixnum?
a : (and/c fixnum? (integer-in 0 #xFFFF))
Added in version 8.5.0.6 of package base.
procedure
(unsafe-fx+/wraparound a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fx-/wraparound [a] b) → fixnum?
a : fixnum? = 0 b : fixnum?
procedure
(unsafe-fx*/wraparound a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxlshift/wraparound a b) → fixnum?
a : fixnum? b : fixnum?
Added in version 7.9.0.6 of package base.
Changed in version 8.15.0.12: 将 unsafe-fx-/wraparound 改为接受单个参数。
procedure
(unsafe-fx= a b ...) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx< a b ...) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx> a b ...) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx<= a b ...) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx>= a b ...) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fxmin a b ...) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxmax a b ...) → fixnum?
a : fixnum? b : fixnum?
Changed in version 7.0.0.13 of package base: 允许一个或多个参数,而非仅允许两个。
procedure
(unsafe-fl+ a ...) → flonum?
a : flonum?
procedure
(unsafe-fl- a b ...) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-fl* a ...) → flonum?
a : flonum?
procedure
(unsafe-fl/ a b ...) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-flabs a) → flonum?
a : flonum?
Changed in version 7.0.0.13 of package base: 允许 unsafe-fl+ 和 unsafe-fl* 接受零个或多个参数,并允许 unsafe-fl- 和 unsafe-fl/ 接受一个或多个参数。
procedure
(unsafe-fl= a b ...) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl< a b ...) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl> a b ...) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl<= a b ...) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl>= a b ...) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-flmin a b ...) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-flmax a b ...) → flonum?
a : flonum? b : flonum?
Changed in version 7.0.0.13 of package base: 允许一个或多个参数,而非仅允许两个。
procedure
(unsafe-flround a) → flonum?
a : flonum?
procedure
(unsafe-flfloor a) → flonum?
a : flonum?
procedure
(unsafe-flceiling a) → flonum?
a : flonum?
procedure
(unsafe-fltruncate a) → flonum?
a : flonum?
procedure
(unsafe-flsingle a) → flonum?
a : flonum?
Added in version 7.8.0.7 of package base.
procedure
(unsafe-flbit-field a start end) → exact-nonnegative-integer?
a : flonum? start : (integer-in 0 64) end : (integer-in 0 64)
Added in version 8.15.0.3 of package base.
procedure
(unsafe-flsin a) → flonum?
a : flonum?
procedure
(unsafe-flcos a) → flonum?
a : flonum?
procedure
(unsafe-fltan a) → flonum?
a : flonum?
procedure
(unsafe-flasin a) → flonum?
a : flonum?
procedure
(unsafe-flacos a) → flonum?
a : flonum?
procedure
(unsafe-flatan a) → flonum?
a : flonum?
procedure
(unsafe-fllog a) → flonum?
a : flonum?
procedure
(unsafe-flexp a) → flonum?
a : flonum?
procedure
(unsafe-flsqrt a) → flonum?
a : flonum?
procedure
(unsafe-flexpt a b) → flonum?
a : flonum? b : flonum?
procedure
→
(and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c)))) a : flonum? b : flonum?
procedure
(unsafe-flreal-part a) → flonum?
a :
(and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c))))
procedure
(unsafe-flimag-part a) → flonum?
a :
(and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c))))
procedure
(unsafe-fx->fl a) → flonum?
a : fixnum?
procedure
(unsafe-fl->fx a) → fixnum?
a : flonum?
Changed in version 7.7.0.8 of package base: 将 unsafe-fl->fx 改为截断。
procedure
(unsafe-flrandom rand-gen) → (and flonum? (>/c 0) (</c 1))
rand-gen : pseudo-random-generator?
17.2 Unsafe Character Operations
procedure
(unsafe-char=? a b ...) → boolean?
a : char? b : char?
procedure
(unsafe-char<? a b ...) → boolean?
a : char? b : char?
procedure
(unsafe-char>? a b ...) → boolean?
a : char? b : char?
procedure
(unsafe-char<=? a b ...) → boolean?
a : char? b : char?
procedure
(unsafe-char>=? a b ...) → boolean?
a : char? b : char?
procedure
(unsafe-char->integer a) → fixnum?
a : char?
Added in version 7.0.0.14 of package base.
17.3 Unsafe Compound-Data Operations
procedure
(unsafe-car p) → any/c
p : pair?
procedure
(unsafe-cdr p) → any/c
p : pair?
procedure
(unsafe-mcar p) → any/c
p : mpair?
procedure
(unsafe-mcdr p) → any/c
p : mpair?
procedure
(unsafe-set-mcar! p v) → void?
p : mpair? v : any/c
procedure
(unsafe-set-mcdr! p v) → void?
p : mpair? v : any/c
procedure
(unsafe-list-ref lst pos) → any/c
lst : pair? pos : (and/c exact-nonnegative-integer? fixnum?)
procedure
(unsafe-list-tail lst pos) → any/c
lst : any/c pos : (and/c exact-nonnegative-integer? fixnum?)
procedure
(unsafe-set-immutable-car! p v) → void?
p : pair? v : any/c
procedure
(unsafe-set-immutable-cdr! p v) → void?
p : pair? v : any/c
使用 unsafe-set-immutable-car! 和 unsafe-set-immutable-cdr! 的一些陷阱:
消费 pair 的函数可能会利用不可变性,例如计算列表的长度一次并期望列表保持该长度,或根据合约检查列表并期望合约此后保持。
对 pair 调用 list? 的结果可能在内部缓存,因此将 pair 的 cdr 从列表改为非列表或反之可能会导致 list? 产生错误的值—
对于被修改的 pair 或到达被修改 pair 的其他 pair。 编译器可能基于 pair 是不可变的理由,重新排序甚至优化掉对 car 或 cdr 的调用,在这种情况下,unsafe-set-immutable-car! 或 unsafe-set-immutable-cdr! 可能不会对 car 或 cdr 的使用产生影响。
Added in version 7.9.0.18 of package base.
procedure
(unsafe-unbox b) → any/c
b : box?
procedure
(unsafe-set-box! b k) → void?
b : box? k : any/c
procedure
(unsafe-unbox* v) → any/c
v : (and/c box? (not/c impersonator?))
procedure
(unsafe-set-box*! v val) → void?
v : (and/c box? (not/c impersonator?)) val : any/c
procedure
(unsafe-box*-cas! loc old new) → boolean?
loc : box? old : any/c new : any/c
vector 的大小永远不能大于 fixnum,因此即使是 vector-length 也总是返回 fixnum。
Changed in version 6.11.0.2 of package base: 添加了 unsafe-vector*-cas!。
Changed in version 8.11.1.9: 添加了 unsafe-vector-copy、unsafe-vector*-copy、unsafe-vector-set/copy、unsafe-vector*-set/copy、unsafe-vector-append 和 unsafe-vector*-append。
procedure
→ (and/c vector? immutable?) v : (and/c vector? (not/c impersonator?))
Added in version 7.7.0.6 of package base.
procedure
(unsafe-string-length str) → fixnum?
str : string?
procedure
(unsafe-string-ref str k)
→ (and/c char? (lambda (ch) (<= 0 (char->integer ch) 255))) str : string? k : fixnum?
procedure
(unsafe-string-set! str k ch) → void?
str : (and/c string? (not/c immutable?)) k : fixnum? ch : char?
procedure
→ (and/c string? immutable?) str : string?
Added in version 7.7.0.6 of package base.
procedure
(unsafe-bytes-length bstr) → fixnum?
bstr : bytes?
procedure
(unsafe-bytes-ref bstr k) → byte?
bstr : bytes? k : fixnum?
procedure
(unsafe-bytes-set! bstr k b) → void?
bstr : (and/c bytes? (not/c immutable?)) k : fixnum? b : byte?
procedure
(unsafe-bytes-copy! dest dest-start src [ src-start src-end]) → void? dest : (and/c bytes? (not/c immutable?)) dest-start : fixnum? src : bytes? src-start : fixnum? = 0 src-end : fixnum? = (bytes-length src)
Changed in version 7.5.0.15 of package base: 添加了 unsafe-bytes-copy!。
procedure
→ (and/c bytes? immutable?) bstr : bytes?
Added in version 7.7.0.6 of package base.
procedure
v : fxvector?
procedure
(unsafe-fxvector-ref v k) → fixnum?
v : fxvector? k : fixnum?
procedure
(unsafe-fxvector-set! v k x) → void?
v : fxvector? k : fixnum? x : fixnum?
procedure
v : flvector?
procedure
(unsafe-flvector-ref v k) → flonum?
v : flvector? k : fixnum?
procedure
(unsafe-flvector-set! v k x) → void?
v : flvector? k : fixnum? x : flonum?
procedure
(unsafe-f64vector-ref vec k) → flonum?
vec : f64vector? k : fixnum?
procedure
(unsafe-f64vector-set! vec k n) → void?
vec : f64vector? k : fixnum? n : flonum?
procedure
(unsafe-s16vector-ref vec k) → (integer-in -32768 32767)
vec : s16vector? k : fixnum?
procedure
(unsafe-s16vector-set! vec k n) → void?
vec : s16vector? k : fixnum? n : (integer-in -32768 32767)
procedure
(unsafe-u16vector-ref vec k) → (integer-in 0 65535)
vec : u16vector? k : fixnum?
procedure
(unsafe-u16vector-set! vec k n) → void?
vec : u16vector? k : fixnum? n : (integer-in 0 65535)
procedure
(unsafe-stencil-vector mask v ...) → stencil-vector?
mask : (integer-in 0 (sub1 (expt 2 (stencil-vector-mask-width)))) v : any/c
procedure
→ (integer-in 0 (sub1 (expt 2 (stencil-vector-mask-width)))) vec : stencil-vector?
procedure
→ (integer-in 0 (sub1 (stencil-vector-mask-width))) vec : stencil-vector?
procedure
(unsafe-stencil-vector-ref vec pos) → any/c
vec : stencil-vector? pos : exact-nonnegative-integer?
procedure
(unsafe-stencil-vector-set! vec pos v) → void?
vec : stencil-vector? pos : exact-nonnegative-integer? v : any/c
procedure
(unsafe-stencil-vector-update vec remove-mask add-mask v ...) → stencil-vector? vec : stencil-vector? remove-mask : (integer-in 0 (sub1 (expt 2 (stencil-vector-mask-width)))) add-mask : (integer-in 0 (sub1 (expt 2 (stencil-vector-mask-width)))) v : any/c
Added in version 8.5.0.7 of package base.
procedure
(unsafe-struct-ref v k) → any/c
v : any/c k : fixnum?
procedure
(unsafe-struct-set! v k val) → void?
v : any/c k : fixnum? val : any/c
procedure
(unsafe-struct*-ref v k) → any/c
v : (not/c impersonator?) k : fixnum?
procedure
(unsafe-struct*-set! v k val) → void?
v : (not/c impersonator?) k : fixnum? val : any/c
procedure
(unsafe-struct*-cas! v k old-val new-val) → boolean?
v : (not/c impersonator?) k : fixnum? old-val : any/c new-val : any/c
Changed in version 6.11.0.2 of package base: 添加了 unsafe-struct*-cas!。
procedure
v : any/c
Added in version 8.8.0.3 of package base.
procedure
(unsafe-mutable-hash-iterate-first hash) → (or/c #f any/c)
hash : (and/c hash? (not/c immutable?) hash-strong?)
procedure
(unsafe-mutable-hash-iterate-next hash pos) → (or/c #f any/c)
hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c
procedure
(unsafe-mutable-hash-iterate-key hash pos) → any/c
hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c
procedure
(unsafe-mutable-hash-iterate-key hash pos bad-index-v) → any/c hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c bad-index-v : any/c
procedure
(unsafe-mutable-hash-iterate-value hash pos) → any/c hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c
procedure
(unsafe-mutable-hash-iterate-value hash pos bad-index-v) → any/c hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c bad-index-v : any/c
procedure
(unsafe-mutable-hash-iterate-key+value hash pos) →
any/c any/c hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c
procedure
(unsafe-mutable-hash-iterate-key+value hash pos bad-index-v)
→
any/c any/c hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c bad-index-v : any/c
procedure
(unsafe-mutable-hash-iterate-pair hash pos) → pair?
hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c
procedure
(unsafe-mutable-hash-iterate-pair hash pos bad-index-v) → pair? hash : (and/c hash? (not/c immutable?) hash-strong?) pos : any/c bad-index-v : any/c
procedure
(unsafe-immutable-hash-iterate-first hash) → (or/c #f any/c)
hash : (and/c hash? immutable?)
procedure
(unsafe-immutable-hash-iterate-next hash pos) → (or/c #f any/c) hash : (and/c hash? immutable?) pos : any/c
procedure
(unsafe-immutable-hash-iterate-key hash pos) → any/c hash : (and/c hash? immutable?) pos : any/c
procedure
(unsafe-immutable-hash-iterate-key hash pos bad-index-v) → any/c hash : (and/c hash? immutable?) pos : any/c bad-index-v : any/c
procedure
(unsafe-immutable-hash-iterate-value hash pos) → any/c hash : (and/c hash? immutable?) pos : any/c
procedure
(unsafe-immutable-hash-iterate-value hash pos bad-index-v) → any/c hash : (and/c hash? immutable?) pos : any/c bad-index-v : any/c
procedure
(unsafe-immutable-hash-iterate-key+value hash pos) →
any/c any/c hash : (and/c hash? immutable?) pos : any/c
procedure
(unsafe-immutable-hash-iterate-key+value hash pos bad-index-v)
→
any/c any/c hash : (and/c hash? immutable?) pos : any/c bad-index-v : any/c
procedure
(unsafe-immutable-hash-iterate-pair hash pos) → pair? hash : (and/c hash? immutable?) pos : any/c
procedure
(unsafe-immutable-hash-iterate-pair hash pos bad-index-v) → pair? hash : (and/c hash? immutable?) pos : any/c bad-index-v : any/c
procedure
(unsafe-weak-hash-iterate-first hash) → (or/c #f any/c)
hash : (and/c hash? hash-weak?)
procedure
(unsafe-weak-hash-iterate-next hash pos) → (or/c #f any/c)
hash : (and/c hash? hash-weak?) pos : any/c
procedure
(unsafe-weak-hash-iterate-key hash pos) → any/c
hash : (and/c hash? hash-weak?) pos : any/c
procedure
(unsafe-weak-hash-iterate-key hash pos bad-index-v) → any/c hash : (and/c hash? hash-weak?) pos : any/c bad-index-v : any/c
procedure
(unsafe-weak-hash-iterate-value hash pos) → any/c
hash : (and/c hash? hash-weak?) pos : any/c
procedure
(unsafe-weak-hash-iterate-value hash pos bad-index-v) → any/c hash : (and/c hash? hash-weak?) pos : any/c bad-index-v : any/c
procedure
(unsafe-weak-hash-iterate-key+value hash pos) →
any/c any/c hash : (and/c hash? hash-weak?) pos : any/c
procedure
(unsafe-weak-hash-iterate-key+value hash pos bad-index-v) →
any/c any/c hash : (and/c hash? hash-weak?) pos : any/c bad-index-v : any/c
procedure
(unsafe-weak-hash-iterate-pair hash pos) → pair?
hash : (and/c hash? hash-weak?) pos : any/c
procedure
(unsafe-weak-hash-iterate-pair hash pos bad-index-v) → pair? hash : (and/c hash? hash-weak?) pos : any/c bad-index-v : any/c
procedure
(unsafe-ephemeron-hash-iterate-first hash) → (or/c #f any/c)
hash : (and/c hash? hash-ephemeron?)
procedure
(unsafe-ephemeron-hash-iterate-next hash pos) → (or/c #f any/c) hash : (and/c hash? hash-ephemeron?) pos : any/c
procedure
(unsafe-ephemeron-hash-iterate-key hash pos) → any/c hash : (and/c hash? hash-ephemeron?) pos : any/c
procedure
(unsafe-ephemeron-hash-iterate-key hash pos bad-index-v) → any/c hash : (and/c hash? hash-ephemeron?) pos : any/c bad-index-v : any/c
procedure
(unsafe-ephemeron-hash-iterate-value hash pos) → any/c hash : (and/c hash? hash-ephemeron?) pos : any/c
procedure
(unsafe-ephemeron-hash-iterate-value hash pos bad-index-v) → any/c hash : (and/c hash? hash-ephemeron?) pos : any/c bad-index-v : any/c
procedure
(unsafe-ephemeron-hash-iterate-key+value hash pos) →
any/c any/c hash : (and/c hash? hash-ephemeron?) pos : any/c
procedure
(unsafe-ephemeron-hash-iterate-key+value hash pos bad-index-v)
→
any/c any/c hash : (and/c hash? hash-ephemeron?) pos : any/c bad-index-v : any/c
procedure
(unsafe-ephemeron-hash-iterate-pair hash pos) → pair? hash : (and/c hash? hash-ephemeron?) pos : any/c
procedure
(unsafe-ephemeron-hash-iterate-pair hash pos bad-index-v) → pair? hash : (and/c hash? hash-ephemeron?) pos : any/c bad-index-v : any/c
每个不安全的 ...-first 和 ...-next 过程可能返回哈希结构视图的内部表示而非数字索引,从而实现更快的迭代。这些 ...-first 和 ...-next 函数的结果应作为 pos 传递给相应的不安全访问器函数。
如果提供给可变 hash 访问器函数的 pos 之前是 有效哈希索引,但不再是 hash 的 有效哈希索引,且未提供 bad-index-v,则 exn:fail:contract exception is raised。对于从未是 hash 的 有效哈希索引的 pos,未指定行为。注意,bad-index-v 参数在技术上对 unsafe-immutable-hash-iterate- 函数无用,因为对于不可变 hash,索引不会变为无效。
Added in version 6.4.0.6 of package base.
Changed in version 7.0.0.10: 添加了可选的 bad-index-v 参数。
Changed in version 8.0.0.10: 添加了 ephemeron 变体。
procedure
(unsafe-make-srcloc source line column position span) → srcloc? source : any/c line : (or/c exact-positive-integer? #f) column : (or/c exact-nonnegative-integer? #f) position : (or/c exact-positive-integer? #f) span : (or/c exact-nonnegative-integer? #f)
Added in version 7.2.0.10 of package base.
17.4 Unsafe Extflonum Operations
procedure
(unsafe-extfl+ a b) → extflonum?
a : extflonum? b : extflonum?
procedure
(unsafe-extfl- a b) → extflonum?
a : extflonum? b : extflonum?
procedure
(unsafe-extfl* a b) → extflonum?
a : extflonum? b : extflonum?
procedure
(unsafe-extfl/ a b) → extflonum?
a : extflonum? b : extflonum?
procedure
(unsafe-extflabs a) → extflonum?
a : extflonum?
procedure
(unsafe-extfl= a b) → boolean?
a : extflonum? b : extflonum?
procedure
(unsafe-extfl< a b) → boolean?
a : extflonum? b : extflonum?
procedure
(unsafe-extfl> a b) → boolean?
a : extflonum? b : extflonum?
procedure
(unsafe-extfl<= a b) → boolean?
a : extflonum? b : extflonum?
procedure
(unsafe-extfl>= a b) → boolean?
a : extflonum? b : extflonum?
procedure
(unsafe-extflmin a b) → extflonum?
a : extflonum? b : extflonum?
procedure
(unsafe-extflmax a b) → extflonum?
a : extflonum? b : extflonum?
procedure
(unsafe-extflround a) → extflonum?
a : extflonum?
procedure
(unsafe-extflfloor a) → extflonum?
a : extflonum?
procedure
a : extflonum?
procedure
a : extflonum?
procedure
(unsafe-extflsin a) → extflonum?
a : extflonum?
procedure
(unsafe-extflcos a) → extflonum?
a : extflonum?
procedure
(unsafe-extfltan a) → extflonum?
a : extflonum?
procedure
(unsafe-extflasin a) → extflonum?
a : extflonum?
procedure
(unsafe-extflacos a) → extflonum?
a : extflonum?
procedure
(unsafe-extflatan a) → extflonum?
a : extflonum?
procedure
(unsafe-extfllog a) → extflonum?
a : extflonum?
procedure
(unsafe-extflexp a) → extflonum?
a : extflonum?
procedure
(unsafe-extflsqrt a) → extflonum?
a : extflonum?
procedure
(unsafe-extflexpt a b) → extflonum?
a : extflonum? b : extflonum?
procedure
(unsafe-fx->extfl a) → extflonum?
a : fixnum?
procedure
(unsafe-extfl->fx a) → fixnum?
a : extflonum?
Changed in version 7.7.0.8 of package base: 将 unsafe-fl->fx 改为截断。
procedure
v : extflvector?
procedure
(unsafe-extflvector-ref v k) → extflonum?
v : extflvector? k : fixnum?
procedure
(unsafe-extflvector-set! v k x) → void?
v : extflvector? k : fixnum? x : extflonum?
17.5 Unsafe Impersonators and Chaperones
procedure
(unsafe-impersonate-procedure proc replacement-proc prop prop-val ... ...) → (and/c procedure? impersonator?) proc : procedure? replacement-proc : procedure? prop : impersonator-property? prop-val : any
如果 proc 本身是从 impersonate-procedure* 或 chaperone-procedure* 派生的拟人化对象,注意 replacement-proc 将无法正确调用它。具体来说,由 unsafe-impersonate-procedure 生成的拟人化对象不会传递给提供给 impersonate-procedure* 或 chaperone-procedure* 以生成 proc 的包装过程。
最后,与 impersonate-procedure 不同,unsafe-impersonate-procedure 不会将 impersonator-prop:application-mark 作为 prop 特殊处理。
unsafe-impersonate-procedure 的不安全性仅限于上述与 impersonate-procedure 的区别。unsafe-impersonate-procedure 的参数合约在提供参数时进行检查。
(define log1-args '()) (define log1-results '()) (define wrap-f1 (λ (f) (impersonate-procedure f (λ (arg) (set! log1-args (cons arg log1-args)) (values (λ (res) (set! log1-results (cons res log1-results)) res) arg))))) (define log2-args '()) (define log2-results '()) (define wrap-f2 (λ (f) (unsafe-impersonate-procedure f (λ (arg) (set! log2-args (cons arg log2-args)) (let ([res (f arg)]) (set! log2-results (cons res log2-results)) res)))))
Added in version 6.4.0.4 of package base.
procedure
(unsafe-chaperone-procedure proc wrapper-proc prop prop-val ... ...) → (and/c procedure? chaperone?) proc : procedure? wrapper-proc : procedure? prop : impersonator-property? prop-val : any
Added in version 6.4.0.4 of package base.
procedure
(unsafe-impersonate-vector vec replacement-vec prop prop-val ... ...) → (and/c vector? impersonator?) vec : vector? replacement-vec : (and/c vector? (not/c impersonator?)) prop : impersonator-property? prop-val : any/c
unsafe-impersonate-vector 的结果是 vec 的拟人化对象。
Added in version 6.9.0.2 of package base.
procedure
(unsafe-chaperone-vector vec replacement-vec prop prop-val ... ...) → (and/c vector? chaperone?) vec : vector? replacement-vec : (and/c vector? (not/c impersonator?)) prop : impersonator-property? prop-val : any/c
Added in version 6.9.0.2 of package base.
17.6 Unsafe Assertions
procedure
编译器可以利用其自由,选择便捷或高效的行为来代替对 unsafe-assert-unreachable 的调用。例如,表达式
(lambda (x) (if (pair? x) (car x) (unsafe-assert-unreachable)))
可能被编译为等价于以下代码
(lambda (x) (unsafe-car x))
因为选择让 (unsafe-assert-unreachable) 的行为与 (unsafe-car x) 相同,使得 if 的两个分支相同,从而可以消除 pair? 测试。
Added in version 8.0.0.11 of package base.
17.7 Unsafe Structure Type Properties
| (require racket/unsafe/struct-type-property) | package: base |
procedure
(unsafe-make-struct-type-property/guard-calls-no-arguments name [ guard supers can-impersonate? accessor-name contract-str realm])
→
struct-type-property? (any/c . -> . boolean?) procedure? name : symbol? guard : (or/c procedure? #f 'can-impersonate) = #f
supers :
(listof (cons/c struct-type-property? (any/c . -> . any/c))) = null can-impersonate? : any/c = #f accessor-name : (or/c symbol? #f) = #f contract-str : (or/c string? symbol? #f) = #f realm : symbol? = 'racket
断言给定过程不会被属性的 guard 调用,可以减少检查并改进对使用该属性的结构类型操作的优化。具体来说,当由 unsafe-make-struct-type-property/guard-calls-no-arguments 创建的属性用于结构类型声明时,并且当为该属性提供的值包含引用回结构类型声明绑定的过程(这是方法类属性的常见模式)时,编译器可以更容易地得出结论:在属性值中引用的已定义名称不会被过早引用。
Added in version 8.18.0.18 of package base.
17.8 Unsafe Undefined
| (require racket/unsafe/undefined) | package: base |
常量 unsafe-undefined 在内部被用作占位值。例如,它被 letrec 用作尚未赋值的 variable 的值。然而,与 racket/undefined 导出的 undefined 值不同,unsafe-undefined 值不应泄露为某个安全表达式的结果,也不应作为可选参数传给 procedure(因为可能被视作"未提供值")。 可能产生 unsafe-undefined 的表达式结果可以由 check-not-unsafe-undefined 保护,以便在产生 undefined 值之前引发异常。
unsafe-undefined 值始终与自身是 eq? 的。
Added in version 6.0.1.2 of package base.
Changed in version 6.90.0.29: 带有可选参数的 Procedure 有时会在内部使用
unsafe-undefined 来表示"未提供参数"。
value
参见上面了解 unsafe-undefined 使用的重要约束条件。
procedure
(check-not-unsafe-undefined v sym) → any/c
v : any/c sym : symbol?
procedure
(check-not-unsafe-undefined/assign v sym) → any/c
v : any/c sym : symbol?
procedure
v : any/c
当某个字段访问可能产生 unsafe-undefined 或某个字段赋值可能替换 unsafe-undefined 时,会引发 exn:fail:contract 异常。
当 (continuation-mark-set-first #f prop:chaperone-unsafe-undefined) 返回 unsafe-undefined 时,chaperone 的字段赋值检查被禁用。因此,字段初始化赋值——旨在替换字段 unsafe-undefined 值的赋值——应包裹在 (with-continuation-mark prop:chaperone-unsafe-undefined unsafe-undefined ....) 中。
属性值应为一个用作字段名称的 symbol 列表,但顺序应与结构字段顺序相反。当某个字段访问或赋值会产生或替换 unsafe-undefined 时,如果字段名称由结构属性的值提供,则引发 exn:fail:contract:variable 异常,否则引发 exn:fail:contract 异常。