레거시 계약
레거시 계약 (Legacy Contracts)
계약(contract) 시스템의 초기 인터페이스를 그대로 유지하면서도 내부적으로는 새 계약 엔진을 활용할 수 있는 도구들이 있어요. 이 문서에서는 make-proj-contract, raise-contract-error, contract-proc 같은 레거시 계약 도구를 설명합니다.
출처: Racket Reference
본문
procedure
(make-proj-contract name proj first-order) → contract?
name : any/c
proj : (or/c (-> any/c any/c (list/c any/c any/c) contact? (-> any/c any/c))
(-> any/c any/c (list/c any/c any/c) contact? boolean? (-> any/c any/c)))
first-order : (-> any/c boolean?)
옛 인터페이스를 사용해서 계약을 만듭니다.
오류를 제외하면, 이것은 다음 코드와 동일합니다:
(make-contract
#:name name
#:first-order first-order
#:projection
(cond
[(procedure-arity-includes? proj 5)
(lambda (blame)
(proj (blame-positive blame)
(blame-negative blame)
(list (blame-source blame) (blame-value blame))
(blame-contract blame)
(not (blame-swapped? blame))))]
[(procedure-arity-includes? proj 4)
(lambda (blame)
(proj (blame-positive blame)
(blame-negative blame)
(list (blame-source blame) (blame-value blame))
(blame-contract blame)))]))
procedure
(raise-contract-error val src pos name fmt arg ...) → any/c
val : any/c
src : any/c
pos : any/c
name : any/c
fmt : string?
arg : any/c
val, src, pos, name 인자들로 blame 구조체를 만든 다음 raise-blame-error를 호출합니다. fmt 문자열과 그 뒤의 인자들은 format에 전달되며, 오류 메시지의 문자열로 사용됩니다.
procedure
(contract-proc c) → (->* (symbol? symbol? (or/c syntax? (list/c any/c any/c)))
(boolean?) (-> any/c any))
c : contract?
계약으로부터 옛 스타일의 프로젝션(projection)을 만듭니다.
결과 함수는 blame 구조체에 들어 있는 정보를 받아서, 계약을 검사하는 프로젝션 함수를 반환합니다.
더 알아보기
- 계약 (Contracts) — 계약 시스템의 개요
- 계약 유틸리티 (Contract Utilities) —
make-contract, 프로젝션 - 블레임 (Blame) —
raise-blame-error,blame-positive등