-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
7.1.3 嵌套合约的测试 | ||
|
||
在许多情况下,在模块边界上附加合约是有意义的。然而,能够以比模块更细致的方式使用合约通常是便利的。define/contract表允许这种使用: | ||
|
||
#lang racket | ||
|
||
(define/contract amount | ||
(and/c number? positive?) | ||
150) | ||
|
||
(+ amount 10) | ||
|
||
在这个例子中,define/contract表在amount定义和它周围的上下文之间建立了一个合约边界。换言之,这里的双方是包含它的定义和模块。 | ||
|
||
创造这些嵌套的合约边界的表的使用有时是微妙的,因为他们可能会有意想不到的影响性能或指责似乎不直观的一方。这些微妙之处在《define/contract和->的使用》(Using define/contract and ->)和《合同的边界和define/contract》(Contract boundaries and define/contract | ||
)中得到了解释。 |