replace lazy-thunk with delay / force

main
Matthew Butterick 6 years ago
parent 23429648c5
commit cb858bc636

@ -56,6 +56,4 @@
(cond
[(void? size) 0]
[(and (integer? size) (not (negative? size))) size]
[else (raise-argument-error 'size "nonnegative integer" size)]))
(struct lazy-thunk (proc) #:transparent)
[else (raise-argument-error 'size "nonnegative integer" size)]))

@ -1,6 +1,7 @@
#lang debug racket/base
(require "helper.rkt"
racket/dict
racket/promise
sugar/unstable/dict)
(provide (all-defined-out))
@ -42,7 +43,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Pointer.coffee
(pos port orig-pos)
val]))
(if (pointer-lazy? xp)
(lazy-thunk decode-value)
(delay (decode-value))
(decode-value))]
[else ptr])])))

@ -1,5 +1,10 @@
#lang debug racket/base
(require (prefix-in d: racket/dict) racket/list "helper.rkt" "number.rkt" sugar/unstable/dict)
(require (prefix-in d: racket/dict)
racket/promise
racket/list
"helper.rkt"
"number.rkt"
sugar/unstable/dict)
(provide (all-defined-out))
#|
@ -19,7 +24,7 @@ https://github.com/mbutterick/restructure/blob/master/src/Struct.coffee
[(define (dict-set! d k v) (d:dict-set! (choose-dict d k) k v))
(define (dict-ref d k [thunk #f])
(define res (d:dict-ref (choose-dict d k) k thunk))
(if (lazy-thunk? res) ((lazy-thunk-proc res)) res))
(force res))
(define (dict-remove! d k) (d:dict-remove! (choose-dict d k) k))
;; public keys only
(define (dict-keys d) (d:dict-keys (struct-dict-res-_kv d)))

@ -5,6 +5,7 @@
"../pointer.rkt"
"../number.rkt"
"../struct.rkt"
racket/promise
sugar/unstable/dict)
#|
@ -59,7 +60,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"decode should support decoding pointers lazily"
(parameterize ([current-input-port (open-input-bytes (bytes 1 53))])
(define res (decode (+xstruct (dictify 'ptr (+xpointer uint8 uint8 (mhasheq 'lazy #t))))))
(check-true (lazy-thunk? (dict-ref (struct-dict-res-_kv res) 'ptr)))
(check-true (promise? (dict-ref (struct-dict-res-_kv res) 'ptr)))
(check-equal? (dict-ref res 'ptr) 53)))
(test-case

@ -15,6 +15,7 @@ https://github.com/mbutterick/restructure/blob/master/src/VersionedStruct.coffee
(dict-set! res 'version
(cond
[(integer? (xversioned-struct-type xvs)) (xversioned-struct-type xvs)]
#;[forced-version] ; for testing purposes: pass an explicit version
[(or (symbol? (xversioned-struct-type xvs)) (procedure? (xversioned-struct-type xvs)))
(unless parent

Loading…
Cancel
Save