Skip to content

Commit

Permalink
Create 07.1.3 嵌套合约的测试
Browse files Browse the repository at this point in the history
  • Loading branch information
OnRoadZy committed Dec 2, 2017
1 parent dc81891 commit 1f13bcb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 07.1.3 嵌套合约的测试
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
)中得到了解释。

0 comments on commit 1f13bcb

Please sign in to comment.