Skip to content

Commit cc23001

Browse files
committed
add listof-zero?
1 parent c603254 commit cc23001

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

cmdopt.rkt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
(require racket/symbol)
77

88
(require "digitama/cmdopt.rkt")
9-
10-
(require "number.rkt")
9+
(require "digitama/predicate.rkt")
1110

1211
(require (for-syntax racket/base))
1312
(require (for-syntax racket/syntax))

digitama/predicate.rkt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#lang typed/racket/base
2+
3+
(provide (all-defined-out))
4+
5+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6+
(define nonnegative-fixnum? : (-> Any Boolean : Nonnegative-Fixnum) (λ [n] (and (fixnum? n) (>= n 0))))
7+
(define nonnegative-flonum? : (-> Any Boolean : #:+ Nonnegative-Flonum) (λ [f] (and (flonum? f) (>= f 0.0)))) ; unable to deal with +nan.0
8+
9+
(define positive-byte? : (-> Any Boolean : Positive-Byte) (λ [b] (and (byte? b) (> b 0))))
10+
(define positive-index? : (-> Any Boolean : Positive-Index) (λ [i] (and (index? i) (> i 0))))
11+
(define positive-fixnum? : (-> Any Boolean : Positive-Fixnum) (λ [n] (and (fixnum? n) (> n 0))))
12+
(define positive-flonum? : (-> Any Boolean : #:+ Positive-Flonum) (λ [f] (and (flonum? f) (> f 0.0)))) ; unable to deal with +nan.0
13+
14+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15+
(define real-zero? : (-> Any Boolean)
16+
(lambda [v]
17+
(and (real? v)
18+
(zero? v))))

number.rkt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
(provide (all-defined-out))
44
(provide (rename-out [string+>integer string->natural]))
5+
(provide (all-from-out "digitama/predicate.rkt"))
56
(provide msb-bytes->float lsb-bytes->float
67
msb-bytes->double lsb-bytes->double)
78

89
(require "digitama/unsafe/number.rkt")
10+
(require "digitama/predicate.rkt")
911
(require "digitama/number.rkt")
1012

11-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12-
(define nonnegative-fixnum? : (-> Any Boolean : Nonnegative-Fixnum) (λ [n] (and (fixnum? n) (>= n 0))))
13-
(define nonnegative-flonum? : (-> Any Boolean : #:+ Nonnegative-Flonum) (λ [f] (and (flonum? f) (>= f 0.0)))) ; unable to deal with +nan.0
14-
15-
(define positive-byte? : (-> Any Boolean : Positive-Byte) (λ [b] (and (byte? b) (> b 0))))
16-
(define positive-index? : (-> Any Boolean : Positive-Index) (λ [i] (and (index? i) (> i 0))))
17-
(define positive-fixnum? : (-> Any Boolean : Positive-Fixnum) (λ [n] (and (fixnum? n) (> n 0))))
18-
(define positive-flonum? : (-> Any Boolean : #:+ Positive-Flonum) (λ [f] (and (flonum? f) (> f 0.0)))) ; unable to deal with +nan.0
19-
2013
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2114
(define string->byte : (->* (String) (Integer) (Option Byte))
2215
(lambda [str.n [radix 10]]

predicate.rkt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@
22

33
(provide (all-defined-out))
44

5+
(require "digitama/predicate.rkt")
6+
57
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6-
(define is-listof? : (All (T) (-> Any (-> Any Boolean : T) Boolean : #:+ (Listof T) #:- (! (Listof T))))
8+
(define listof? : (All (T) (case-> [Any (-> Any Boolean : T) -> Boolean : #:+ (Listof T) #:- (! (Listof T))]
9+
[Any (-> Any Boolean) -> Boolean]))
710
(lambda [v ?]
811
(and (list? v)
912
(andmap ? v))))
1013

11-
(define is-listof+? : (All (T) (-> Any (-> Any Boolean : T) Boolean : #:+ (Pairof T (Listof T)) #:- (! (Pairof T (Listof T)))))
14+
(define listof+? : (All (T) (case-> [Any (-> Any Boolean : T) -> Boolean : #:+ (Pairof T (Listof T)) #:- (! (Pairof T (Listof T)))]
15+
[Any (-> Any Boolean) -> Boolean]))
1216
(lambda [v ?]
1317
(and (list? v)
1418
(pair? v)
1519
(andmap ? v))))
1620

21+
(define make-listof? : (All (T) (case-> [(-> Any Boolean : T) -> (-> Any Boolean : #:+ (Listof T) #:- (! (Listof T)))]
22+
[(-> Any Boolean) -> (-> Any Boolean)]))
23+
(lambda [?]
24+
(λ [v] (listof? v ?))))
25+
26+
(define make-listof+? : (All (T) (case-> [(-> Any Boolean : T) -> (-> Any Boolean : #:+ (Pairof T (Listof T)) #:- (! (Pairof T (Listof T))))]
27+
[(-> Any Boolean) -> (-> Any Boolean)]))
28+
(lambda [?]
29+
(λ [v] (listof+? v ?))))
30+
1731
(define disjoin? : (All (a b c) (case-> [Any (-> Any Boolean : a) (-> Any Boolean : b) -> Boolean : #:+ (U a b) #:- (! (U a b))]
1832
[Any (-> Any Boolean : a) (-> Any Boolean : b) (-> Any Boolean : c) -> Boolean : #:+ (U a b c) #:- (! (U a b c))]))
1933
(case-lambda
2034
[(v p1? p2?) (or (p1? v) (p2? v))]
2135
[(v p1? p2? p3?) (or (p1? v) (p2? v) (p3? v))]))
2236

37+
(define listof-zero? : (-> Any Boolean) (make-listof? real-zero?))
38+
(define listof+zero? : (-> Any Boolean) (make-listof+? real-zero?))
39+
2340
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2441
(define bs-regexp? : (-> Any Boolean : (U Regexp Byte-Regexp))
2542
(lambda [v]

tamer/zip/lz77.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
(require digimon/cmdopt)
1010
(require digimon/dtrace)
1111
(require digimon/format)
12-
(require digimon/number)
1312
(require digimon/debug)
1413
(require digimon/echo)
1514

15+
(require digimon/digitama/predicate)
1616
(require digimon/digitama/bintext/lz77)
1717
(require digimon/digitama/bintext/archive)
1818
(require digimon/digitama/bintext/zipconfig)

0 commit comments

Comments
 (0)