delete racket/function

main
Matthew Butterick 6 years ago
parent d0647d4532
commit 64f762f9d7

@ -1,12 +1,8 @@
#lang racket/base
(require racket/class
racket/list
racket/function
sugar/unstable/class
sugar/unstable/dict
sugar/unstable/js
racket/dict
"struct.rkt"
"private/generic.rkt"
"private/helper.rkt"
"number.rkt"

@ -4,8 +4,6 @@
"sizes.rkt"
racket/match)
racket/class
racket/list
racket/function
sugar/unstable/class
"private/helper.rkt"
"sizes.rkt")
@ -46,7 +44,8 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(define/augment (size . args) _size)
(define-values (bound-min bound-max)
;; if a signed integer has n bits, it can contain a number between - (expt 2 (sub1 n)) and (sub1 (expt 2 (sub1 n)).
;; if a signed integer has n bits, it can contain a number
;; between - (expt 2 (sub1 n)) and (sub1 (expt 2 (sub1 n)).
(let* ([signed-max (sub1 (arithmetic-shift 1 (sub1 bits)))]
[signed-min (sub1 (- signed-max))]
[delta (if _signed? 0 signed-min)])
@ -54,7 +53,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(define/augment (decode port [parent #f])
(define bstr (read-bytes _size port))
(define bs ((if (eq? endian system-endian) identity reverse) (bytes->list bstr)))
(define bs ((if (eq? endian system-endian) values reverse) (bytes->list bstr)))
(define unsigned-int (for/sum ([(b i) (in-indexed bs)])
(arithmetic-shift b (* 8 i))))
unsigned-int)
@ -68,10 +67,10 @@ https://github.com/mbutterick/restructure/blob/master/src/Number.coffee
(define/augment (encode port val [parent #f])
(unless (<= bound-min val bound-max)
(raise-argument-error 'Integer:encode (format "value within range of ~a ~a-byte int (~a to ~a)" (if _signed? "signed" "unsigned") _size bound-min bound-max) val))
(define-values (bs _) (for/fold ([bs empty] [n val])
(define-values (bs _) (for/fold ([bs null] [n val])
([i (in-range _size)])
(values (cons (bitwise-and n #xff) bs) (arithmetic-shift n -8))))
(apply bytes ((if (eq? endian 'be) identity reverse) bs))))
(apply bytes ((if (eq? endian 'be) values reverse) bs))))
(define-values (NumberT NumberT? +NumberT) (values Integer Integer? +Integer))
(define-values (Number Number? +Number) (values Integer Integer? +Integer))

@ -1,12 +1,12 @@
#lang racket/base
(require racket/class
racket/function
sugar/unstable/class
sugar/unstable/case
sugar/unstable/js
"private/generic.rkt"
"private/helper.rkt")
(require "number.rkt" "utils.rkt")
"private/helper.rkt"
"number.rkt"
"utils.rkt")
(provide (all-defined-out))
#|
@ -20,7 +20,7 @@ https://github.com/mbutterick/restructure/blob/master/src/String.coffee
[(ucs2) (error 'bleh)]
[(utf8) bytes->string/utf-8]
[(ascii) bytes->string/latin-1]
[else identity]))
[else values]))
(proc (read-bytes len port)))
(define (write-encoded-string port string [encoding 'ascii])

@ -7,8 +7,7 @@
"private/helper.rkt"
"private/generic.rkt"
racket/dict
racket/private/generic-methods
racket/function)
racket/private/generic-methods)
(provide (all-defined-out) ref* ref*-set! (all-from-out racket/dict))
(require (prefix-in d: racket/dict))
@ -79,7 +78,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
(unless (dict? res) (raise-result-error 'Struct:pre-encode "dict" res))
res))
(unless ((disjoin assocs? Struct?) fields) ; should be Versioned Struct but whatever
(unless (or (assocs? fields) (Struct? fields)) ; should be Versioned Struct but whatever
(raise-argument-error 'Struct "assocs or Versioned Struct" fields))
(define/augride (decode stream [parent #f] [len 0])

@ -1,7 +1,6 @@
#lang racket/base
(require racket/class
racket/list
racket/function
sugar/unstable/class
sugar/unstable/dict
sugar/unstable/js
@ -19,7 +18,8 @@ https://github.com/mbuttrackerick/restructure/blob/master/src/VersionedStruct.co
(define-subclass Struct (VersionedStruct type [versions (dictify)])
(unless ((disjoin integer? procedure? xenomorph-base%? symbol?) type)
(unless (for/or ([proc (list integer? procedure? xenomorph-base%? symbol?)])
(proc type))
(raise-argument-error 'VersionedStruct "integer, function, symbol, or Restructure object" type))
(unless (and (dict? versions) (andmap (λ (val) (or (dict? val) (Struct? val))) (map cdr versions)))
(raise-argument-error 'VersionedStruct "dict of dicts or Structs" versions))

Loading…
Cancel
Save