Provide the index? predicate.

original commit: 17afa91c095d9df8f91820dcb8268df34f9f0165
This commit is contained in:
Vincent St-Amour 2011-03-07 17:20:44 -05:00
parent c8a4abd264
commit b2d591e70b
4 changed files with 8 additions and 4 deletions

View File

@ -3,7 +3,8 @@
(begin
(require
racket/list
(for-template racket/flonum racket/fixnum racket/math racket/unsafe/ops racket/base)
(for-template racket/flonum racket/fixnum racket/math racket/unsafe/ops racket/base
(only-in "../types/numeric-predicates.rkt" index?))
(only-in (types abbrev numeric-tower) [-Number N] [-Boolean B] [-Symbol Sym] [-Real R] [-PosInt -Pos]))
;; TODO having definitions only at the top is really inconvenient.
@ -598,6 +599,7 @@
[exact? (asym-pred N B (-FS -top (-not-filter -Rat 0)))]
[inexact? (asym-pred N B (-FS -top (-not-filter (Un -InexactReal -FloatComplex) 0)))]
[fixnum? (make-pred-ty -Fixnum)]
[index? (make-pred-ty -Index)]
[positive? (cl->* (-> -Byte B : (-FS (-filter -PosByte 0) (-filter -Zero 0)))
(-> -Index B : (-FS (-filter -PosIndex 0) (-filter -Zero 0)))
(-> -Fixnum B : (-FS (-filter -PosFixnum 0) (-filter -NonPosFixnum 0)))

View File

@ -48,7 +48,9 @@ This file defines two sorts of primitives. All of them are provided into any mod
"../utils/tc-utils.rkt"
"../env/type-name-env.rkt"
"type-contract.rkt"
"for-clauses.rkt"))
"for-clauses.rkt")
"../types/numeric-predicates.rkt")
(provide index?) ; useful for assert, and racket doesn't have it
(define-for-syntax (ignore stx) (syntax-property stx 'typechecker:ignore #t))

View File

@ -9,6 +9,6 @@
;; we assume indexes are 2 bits shorter than fixnums
;; We're generating a reference to fixnum? rather than calling it, so
;; we're safe from fixnum size issues on different platforms.
(define (index? x) (and (fixnum? x) (fixnum? (* x 4))))
(define (index? x) (and (fixnum? x) (>= x 0) (fixnum? (* x 4))))
(define exact-rational? (conjoin rational? exact?))

View File

@ -42,7 +42,7 @@
(define (portable-index? n)
(and (exact-integer? n)
(< n (expt 2 28))
(>= n (- (expt 2 28)))))
(>= n 0)))
;; Singletons
(define -Zero (-val 0)) ; exact