-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.ss
40 lines (34 loc) · 1.27 KB
/
util.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#lang scheme
(require (only-in srfi/26 cut)
(only-in srfi/60 bit-field))
;; Return a list consisting of all elements from clist with indexes from is.
(define (list-refs clist . is)
(map (cut list-ref clist <>) is))
;; Return a bit generator using bits from number.
(define (make-bit-stream number)
(let ((position 0))
(lambda (count)
(let ((old-position position))
(set! position (+ count position))
(bit-field number old-position position)))))
(define (degrees->radians degrees)
(* pi (/ (remainder degrees 360) 180)))
;; Covert file extension into an image kind appropriate to pass into save-file
;; method of a bitmap% instance.
(define (file-extension->kind extension (default 'png))
(case extension
[("png") 'png]
[("jpg" "jpeg") 'jpg]
[("xbm") 'xbm]
[("xpm") 'xpm]
[("bmp") 'bmp]
[else default]))
;; Contract that checks if procedure is of arity one.
(define arity-one-procedure?
(flat-contract (cut procedure-arity-includes? <> 1)))
(provide/contract
[list-refs ((list?) () #:rest (listof integer?) . ->* . list?)]
[make-bit-stream (integer? . -> . (and/c procedure? arity-one-procedure?))]
[degrees->radians (number? . -> . number?)]
[file-extension->kind (string? . -> . symbol?)]
[arity-one-procedure? contract?])