|
|
|
@ -1,9 +1,13 @@
|
|
|
|
|
#lang racket/base
|
|
|
|
|
(require (for-syntax racket/base))
|
|
|
|
|
(require racket/contract)
|
|
|
|
|
|
|
|
|
|
(provide (contract-out
|
|
|
|
|
[bytecount->string (integer? . -> . string?)])
|
|
|
|
|
when/splice)
|
|
|
|
|
|
|
|
|
|
;; convert a bytecount into a string
|
|
|
|
|
(define/contract (bytecount->string bytecount)
|
|
|
|
|
(integer? . -> . string?)
|
|
|
|
|
(define (bytecount->string bytecount)
|
|
|
|
|
(define (format-with-threshold threshold suffix)
|
|
|
|
|
;; upconvert by factor of 100 to get two digits after decimal
|
|
|
|
|
(format "~a ~a" (exact->inexact (/ (round ((* bytecount 100) . / . threshold)) 100)) suffix))
|
|
|
|
@ -24,4 +28,7 @@
|
|
|
|
|
;; for use inside quasiquote
|
|
|
|
|
;; instead of ,(when ...) use ,@(when/splice ...)
|
|
|
|
|
;; to avoid voids
|
|
|
|
|
(define-syntax-rule (when/splice test body) (if test (list body) '()))
|
|
|
|
|
(define-syntax (when/splice stx)
|
|
|
|
|
(syntax-case stx ()
|
|
|
|
|
[(_ test body)
|
|
|
|
|
#'(if test (list body) '())]))
|