blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
171
content_id
stringlengths
40
40
detected_licenses
listlengths
0
8
license_type
stringclasses
2 values
repo_name
stringlengths
6
82
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
13 values
visit_date
timestamp[ns]
revision_date
timestamp[ns]
committer_date
timestamp[ns]
github_id
int64
1.59k
594M
star_events_count
int64
0
77.1k
fork_events_count
int64
0
33.7k
gha_license_id
stringclasses
12 values
gha_event_created_at
timestamp[ns]
gha_created_at
timestamp[ns]
gha_language
stringclasses
46 values
src_encoding
stringclasses
14 values
language
stringclasses
2 values
is_vendor
bool
2 classes
is_generated
bool
1 class
length_bytes
int64
4
7.87M
extension
stringclasses
101 values
filename
stringlengths
2
149
content
stringlengths
4
7.87M
has_macro_def
bool
2 classes
9f36a24bc64550eba24e573a542494355ca6f15b
b21f59bbd4faf31159321e8d26eb170f9aa410c0
/2.1.2-abstraction-barriers/midpoint-segment.scm
6f9a771fe36faf0020adf27a3da8abf827e93065
[]
no_license
furkhat/sicp-practice
4774048022718c165e0ec35602bb192241d9f97a
301fea9ee4d6cea895cec4b618c664b48c2106f0
refs/heads/master
2021-06-08T06:01:01.760120
2016-12-11T08:11:34
2016-12-11T08:11:34
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
511
scm
midpoint-segment.scm
(load "segment.scm") (define (midpoint-segment s) (let ((start-s (start-segment s)) (end-s (end-segment s))) (define (mid a b) (/ (+ a b) 2)) (make-point (mid (x-point start-s) (x-point end-s)) (mid (y-point start-s) (y-point end-s))))) ;test (display "\nmid of:") (print-point (make-point -3 2)) (print-point (make-point 5 -6)) (display "\nis:") (print-point (midpoint-segment (make-segment (make-point -3 2) (make-point 5 -6))))
false
cdb3a5ee2388cf3b4cdda2d222f451d1d7077fa0
4f30ba37cfe5ec9f5defe52a29e879cf92f183ee
/src/smake-lexer.scm
514803f030e7b48e665a376d4186da06b98c109c
[ "MIT" ]
permissive
rtrusso/scp
e31ecae62adb372b0886909c8108d109407bcd62
d647639ecb8e5a87c0a31a7c9d4b6a26208fbc53
refs/heads/master
2021-07-20T00:46:52.889648
2021-06-14T00:31:07
2021-06-14T00:31:07
167,993,024
8
1
MIT
2021-06-14T00:31:07
2019-01-28T16:17:18
Scheme
UTF-8
Scheme
false
false
48,782
scm
smake-lexer.scm
(need regex/dfa) (need regex/genlex) (define smake-lexer-dfa (build-fast-dfa (quote 116) (quote #(#t #t #t #t #t #t #t #t #t #t #t #f #f #f #f #f #f #t #t #t #t #t #f #f #f #t #t #f #f #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #t #f #t #t #f #t #t #t #t #f #t #t)) (quote #(#(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 1 1 1 1 1 1 1 1 1 1 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 2 58 58 58 58 58 58 58 58 6 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 4 58 58 58 58 58 58 58 58 9 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 1 1 1 1 1 1 1 1 1 1 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 2 58 58 58 58 58 58 58 58 6 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 4 58 58 58 58 58 58 58 58 9 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 11 11 20 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 16 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 11 11 20 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 16 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 11 11 20 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 16 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 11 11 20 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 16 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f 13 #f 13 #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 13 #f #f #f 13 #f 13 #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 11 11 20 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 16 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 26 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 23 #f #f #f #f #f #f #f #f 23 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 23 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 23 #f #f #f 23 #f 23 #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 26 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 27 27 27 27 27 27 27 #f 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 24 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 40 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 41 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 42 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 44 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 45 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 46 87 43 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f #f 58 #f 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 100 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 101 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 58 #f #f #f #f 58 #f #f 58 58 58 87 87 87 87 87 87 87 87 87 87 #f #f #f #f #f 58 #f 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f #f 87 #f 87 87 87 87 87 102 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 #f #f #f 58 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f 104 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f 106 107 #f #f 106 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 #f 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f 106 107 #f #f 106 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 #f 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 106 #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f 110 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 110 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f 110 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 110 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f 113 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f) #() #()) #(#(#f #f #f #f #f #f #f #f #f 115 112 #f #f 114 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 111 #f 22 109 39 36 #f 28 38 37 58 #f 32 58 35 58 10 10 10 10 10 10 10 10 10 10 34 #f 31 33 30 58 29 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #f 105 #f #f 0 #f 0 0 0 0 47 0 0 0 103 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #f #f #f 58 #f) #() #()))) (quote #(identifier number number number number number number number number number number #f #f #f #f #f #f string-literal string-literal string-literal string-literal string-literal #f #f #f char-literal char-literal #f #f at greater-than less-than comma equals colon dot percent rparen lparen dollar endif identifier identifier identifier else identifier identifier identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier freeform-identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier ifeq identifier identifier identifier suppress-newline backslash #f comment comment #f whitespace whitespace newline newline #f tab freeform-identifier)))) (define smake-lexically-analyze (let ((main-dfa smake-lexer-dfa)) (lambda (input-port) (run-generated-lexer main-dfa (quote (*whitespace* *comment*)) input-port))))
false
fc0aa58eb1da70b7dbe97b6204c38cd0bbe0b259
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/runtime/remoting/remoting-services.sls
7b62fb0e92dc96448fe83f00b661611776c5b5d9
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
5,209
sls
remoting-services.sls
(library (system runtime remoting remoting-services) (export is? remoting-services? execute-message is-one-way? connect get-real-proxy is-object-out-of-context? get-server-type-for-uri is-method-overloaded? set-object-uri-for-marshal get-object-data unmarshal get-method-base-from-method-message get-obj-ref-for-proxy get-session-id-for-method-message is-transparent-proxy? get-envoy-chain-for-proxy get-lifetime-service log-remoting-stage marshal disconnect? get-object-uri is-object-out-of-app-domain?) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Runtime.Remoting.RemotingServices a)) (define (remoting-services? a) (clr-is System.Runtime.Remoting.RemotingServices a)) (define-method-port execute-message System.Runtime.Remoting.RemotingServices ExecuteMessage (static: System.Runtime.Remoting.Messaging.IMethodReturnMessage System.MarshalByRefObject System.Runtime.Remoting.Messaging.IMethodCallMessage)) (define-method-port is-one-way? System.Runtime.Remoting.RemotingServices IsOneWay (static: System.Boolean System.Reflection.MethodBase)) (define-method-port connect System.Runtime.Remoting.RemotingServices Connect (static: System.Object System.Type System.String System.Object) (static: System.Object System.Type System.String)) (define-method-port get-real-proxy System.Runtime.Remoting.RemotingServices GetRealProxy (static: System.Runtime.Remoting.Proxies.RealProxy System.Object)) (define-method-port is-object-out-of-context? System.Runtime.Remoting.RemotingServices IsObjectOutOfContext (static: System.Boolean System.Object)) (define-method-port get-server-type-for-uri System.Runtime.Remoting.RemotingServices GetServerTypeForUri (static: System.Type System.String)) (define-method-port is-method-overloaded? System.Runtime.Remoting.RemotingServices IsMethodOverloaded (static: System.Boolean System.Runtime.Remoting.Messaging.IMethodMessage)) (define-method-port set-object-uri-for-marshal System.Runtime.Remoting.RemotingServices SetObjectUriForMarshal (static: System.Void System.MarshalByRefObject System.String)) (define-method-port get-object-data System.Runtime.Remoting.RemotingServices GetObjectData (static: System.Void System.Object System.Runtime.Serialization.SerializationInfo System.Runtime.Serialization.StreamingContext)) (define-method-port unmarshal System.Runtime.Remoting.RemotingServices Unmarshal (static: System.Object System.Runtime.Remoting.ObjRef System.Boolean) (static: System.Object System.Runtime.Remoting.ObjRef)) (define-method-port get-method-base-from-method-message System.Runtime.Remoting.RemotingServices GetMethodBaseFromMethodMessage (static: System.Reflection.MethodBase System.Runtime.Remoting.Messaging.IMethodMessage)) (define-method-port get-obj-ref-for-proxy System.Runtime.Remoting.RemotingServices GetObjRefForProxy (static: System.Runtime.Remoting.ObjRef System.MarshalByRefObject)) (define-method-port get-session-id-for-method-message System.Runtime.Remoting.RemotingServices GetSessionIdForMethodMessage (static: System.String System.Runtime.Remoting.Messaging.IMethodMessage)) (define-method-port is-transparent-proxy? System.Runtime.Remoting.RemotingServices IsTransparentProxy (static: System.Boolean System.Object)) (define-method-port get-envoy-chain-for-proxy System.Runtime.Remoting.RemotingServices GetEnvoyChainForProxy (static: System.Runtime.Remoting.Messaging.IMessageSink System.MarshalByRefObject)) (define-method-port get-lifetime-service System.Runtime.Remoting.RemotingServices GetLifetimeService (static: System.Object System.MarshalByRefObject)) (define-method-port log-remoting-stage System.Runtime.Remoting.RemotingServices LogRemotingStage (static: System.Void System.Int32)) (define-method-port marshal System.Runtime.Remoting.RemotingServices Marshal (static: System.Runtime.Remoting.ObjRef System.MarshalByRefObject System.String System.Type) (static: System.Runtime.Remoting.ObjRef System.MarshalByRefObject System.String) (static: System.Runtime.Remoting.ObjRef System.MarshalByRefObject)) (define-method-port disconnect? System.Runtime.Remoting.RemotingServices Disconnect (static: System.Boolean System.MarshalByRefObject)) (define-method-port get-object-uri System.Runtime.Remoting.RemotingServices GetObjectUri (static: System.String System.MarshalByRefObject)) (define-method-port is-object-out-of-app-domain? System.Runtime.Remoting.RemotingServices IsObjectOutOfAppDomain (static: System.Boolean System.Object)))
false
6d9cbd66d6d1c281c27ca621cbcde43f00ffd26b
defeada37d39bca09ef76f66f38683754c0a6aa0
/System.Configuration/system/configuration/callback-validator-attribute.sls
11cb8693dacb0c73f72451a638121be4a16d7a08
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,336
sls
callback-validator-attribute.sls
(library (system configuration callback-validator-attribute) (export new is? callback-validator-attribute? callback-method-name-get callback-method-name-set! callback-method-name-update! type-get type-set! type-update! validator-instance) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.Configuration.CallbackValidatorAttribute a ...))))) (define (is? a) (clr-is System.Configuration.CallbackValidatorAttribute a)) (define (callback-validator-attribute? a) (clr-is System.Configuration.CallbackValidatorAttribute a)) (define-field-port callback-method-name-get callback-method-name-set! callback-method-name-update! (property:) System.Configuration.CallbackValidatorAttribute CallbackMethodName System.String) (define-field-port type-get type-set! type-update! (property:) System.Configuration.CallbackValidatorAttribute Type System.Type) (define-field-port validator-instance #f #f (property:) System.Configuration.CallbackValidatorAttribute ValidatorInstance System.Configuration.ConfigurationValidatorBase))
true
7511a0386c18f0a4c5d54184274a3c0ed458290e
140a499a12332fa8b77fb738463ef58de56f6cb9
/worlds/core/verbcode/9/trymove-0.scm
ba28d2590a537d680c1ff74386189f6d010a5b50
[ "MIT" ]
permissive
sid-code/nmoo
2a5546621ee8c247d4f2610f9aa04d115aa41c5b
cf504f28ab473fd70f2c60cda4d109c33b600727
refs/heads/master
2023-08-19T09:16:37.488546
2023-08-15T16:57:39
2023-08-15T16:57:39
31,146,820
10
0
null
null
null
null
UTF-8
Scheme
false
false
319
scm
trymove-0.scm
(let ((who (get args 0)) (dest self.destination) (door self.door) (door-attempt (if door (door:try-enter who) 1))) (if (valid dest) (if door-attempt (do (move who dest) (dest:look)) nil) (who:tell "Exit didn't work because room was invalid.")))
false
524e953af9d6e68589fd731ea87cf0613efc1e54
e1fc47ba76cfc1881a5d096dc3d59ffe10d07be6
/ch5/5.04.test.scm
b1518caa9b6c731ba82daa31299fb82511bead1a
[]
no_license
lythesia/sicp-sol
e30918e1ebd799e479bae7e2a9bd4b4ed32ac075
169394cf3c3996d1865242a2a2773682f6f00a14
refs/heads/master
2021-01-18T14:31:34.469130
2019-10-08T03:34:36
2019-10-08T03:34:36
27,224,763
2
0
null
null
null
null
UTF-8
Scheme
false
false
143
scm
5.04.test.scm
;; 5.04.scm < this (define (fib n) (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2))) ) ) (display (fib 10)) ; higher is slow.. (exit)
false
1122fe78177ffe17b46747104a9fdee73d6ddb18
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/guile/uniqify.scm
5e3acfa2189fdb9d2ea0ab86bf5fa7cdd158c694
[]
no_license
offby1/doodles
be811b1004b262f69365d645a9ae837d87d7f707
316c4a0dedb8e4fde2da351a8de98a5725367901
refs/heads/master
2023-02-21T05:07:52.295903
2022-05-15T18:08:58
2022-05-15T18:08:58
512,608
2
1
null
2023-02-14T22:19:40
2010-02-11T04:24:52
Scheme
UTF-8
Scheme
false
false
1,638
scm
uniqify.scm
;; Given a list of strings, return another list of strings such that ;; -- ;; each string in the returned list appears exactly once. That is, no ;; string in the returned list is `equal?' to any other string in that ;; list. ;; each string in the input list appears once in the returned list. ;; each string in the returned list appears at least once in the input ;; list. ;; A simple way to do this would be to sort the input list, and then ;; `uniqify' it like this: ;; (define (uniqify seq equal?) ;; (cond ;; ((not (pair? seq)) ;; seq) ;; ((null? (cdr seq)) ;; seq) ;; ((equal? (car seq) ;; (cadr seq)) ;; (uniqify (cdr seq) equal?)) ;; (#t ;; (cons (car seq) ;; (uniqify (cdr seq) equal?))))) ;; However, I suspect that for very large inputs, this will be very ;; slow (sorting would be slow, and so would uniqifying). ("Premature ;; optimization is the root of all evil" -- Donald Knuth) ;; So instead, we go through the list, and add each item to a hash ;; table. Then we run through the hash table and extract the keys. (define (uniqify strings) (define stuff-into-hash! #f) (define hash-keys #f) (let () (define hash-table (make-vector 103 0)) (set! stuff-into-hash! (lambda ( strings) (for-each (lambda (str) (hash-set! hash-table str 1)) strings))) (set! hash-keys (lambda () (map caar (filter pair? (vector->list hash-table)))))) (stuff-into-hash! strings) (hash-keys))
false
2abaf710ef39c48e61cb737a1485752b1b5417ee
e75694971a8d65a860e49d099aba868e1b7ec664
/b7.scm
a6163c9494b64e93015eaeb4b07384f4dce8545f
[]
no_license
telnet23/sicp
d29088e1bdef7ede3cf5805559e0edb3b0ef54fe
a85fa7f17c7485163c9484ed5709d6ec64e87aaa
refs/heads/master
2023-02-20T09:20:38.216645
2019-04-30T20:15:12
2019-04-30T20:15:12
331,790,140
0
0
null
null
null
null
UTF-8
Scheme
false
false
6,235
scm
b7.scm
(define (symbol<? a b) (string<? (symbol->string a) (symbol->string b))) (define (make-tree value left right) (list value left right)) (define (value tree) (car tree)) (define (left tree) (cadr tree)) (define (right tree) (caddr tree)) (define empty-tree? null?) (define example (make-tree '+ (make-tree '* (make-tree '- (make-tree 0 '() '()) (make-tree 2 '() '())) (make-tree 3 '() '())) (make-tree '* (make-tree '- (make-tree 4 '() '()) (make-tree 5 '() '())) (make-tree'1/ '() (make-tree 6 '() '()))))) "problem 1." (define (apt-value t) (cond ((eq? (value t) '1/) (/ 1 (apt-value (right t)))) ((symbol? (value t)) ((cond ((eq? (value t) '+) +) ((eq? (value t) '-) -) ((eq? (value t) '*) *)) (apt-value (left t)) (apt-value (right t)))) (else (value t)))) "problem 2. (a)" (define (extract-preorder t) (if (null? t) t (append (list (value t)) (extract-preorder (left t)) (extract-preorder (right t))))) "problem 2. (b)" (define (extract-postorder t) (if (null? t) t (append (extract-postorder (left t)) (extract-postorder (right t)) (list (value t))))) "problem 2. (c)" (define (extract-inorder t) (if (null? t) t (append (extract-inorder (left t)) (list (value t)) (extract-inorder (right t))))) "problem 2. (d)" (define (extract-infix-unique t) (if (null? t) t (let ((l (extract-infix-unique (left t))) (r (extract-infix-unique (right t)))) (cond ((null? (right t)) (value t)) ; if right is null, then left is also null ((null? (left t)) (append (list (value t)) (list r))) (else (append (list l) (list (value t)) (list r))))))) "problem 3. (a)" (define (bst-element? item bs-tree same? less-than?) (display "looking for ") (display item) (display " in ") (display bs-tree) (newline) (cond ((null? bs-tree) #f) ((same? item (value bs-tree)) #t) ((less-than? item (value bs-tree)) (bst-element? item (left bs-tree) same? less-than?)) (else (bst-element? item (right bs-tree) same? less-than?)))) "problem 3. (b)" (define (bst-insert item bs-tree same? less-than?) (display "trying to insert ")(display item)(display " into ")(display bs-tree)(newline) (cond ((null? bs-tree) (make-tree item '() '())) ((same? item (value bs-tree)) bs-tree) ((less-than? item (value bs-tree)) (make-tree (value bs-tree) (bst-insert item (left bs-tree) same? less-than?) (right bs-tree))) (else (make-tree (value bs-tree) (left bs-tree) (bst-insert item (right bs-tree) same? less-than?))))) "problem 3. (c)" (define (bst-smallest bs-tree) (cond ((null? bs-tree) "error") ((null? (left bs-tree)) (value bs-tree)) (else (bst-smallest (left bs-tree))))) "problem 3. (d)" (define (bst-largest bs-tree) (cond ((null? bs-tree) "error") ((null? (right bs-tree)) (value bs-tree)) (else (bst-largest (right bs-tree))))) "problem 3. (e)" (define (bst-equal? bst1 bst2 same?) (or (and (null? bst1) (null? bst2)) (and (not (null? bst1)) (not (null? bst2)) (same? (value bst1) (value bst2)) (bst-equal? (left bst1) (left bst2) same?) (bst-equal? (right bst1) (right bst2) same?)))) "problem 4. (a)" (define (bst-subset? bst1 bst2 same? less-than?) (or (null? bst1) (and (bst-element? (value bst1) bst2 same? less-than?) (bst-subset? (left bst1) bst2 same? less-than?) (bst-subset? (left bst1) bst2 same? less-than?)))) "problem 4. (b)" (define (bst-set-difference bst1 bst2 same? less-than?) (if (null? bst1) bst1 (let ((l (bst-set-difference (left bst1) bst2 same? less-than?)) (r (bst-set-difference (right bst1) bst2 same? less-than?))) (if (bst-element? (value bst1) bst2 same? less-than?) (if (null? l) r (make-tree (bst-smallest l) (bst-delete-min l) r)) (make-tree (value bst1) l r))))) "problem 4. (c)" (define (bst-set-equal? bst1 bst2 same? less-than?) (and (bst-subset? bst1 bst2 same? less-than?) (bst-subset? bst2 bst1 same? less-than?))) "problem 5. (a)" (define (bst-delete-min bst) (cond ((null? bst) bst) ((null? (left bst)) (right bst)) (else (make-tree (value bst) (bst-delete-min (left bst)) (right bst))))) "problem 5. (b)" (define (bst-delete-max bst) (cond ((null? bst) bst) ((null? (right bst)) (left bst)) (else (make-tree (value bst) (left bst) (bst-delete-max (right bst)))))) "problem 5. (c)" (define (bst-delete val bst same? less-than?) (cond ((null? bst) bst) ((same? val (value bst)) (cond ((and (null? (left bst)) (null? (right bst))) '()) ((null? (left bst)) (right bst)) ((null? (right bst)) (left bst)) (else (make-tree (bst-largest (left bst)) (bst-delete-max (left bst)) (right bst))))) ((less-than? val (value bst)) (make-tree (value bst) (bst-delete val (left bst) same? less-than?) (right bst))) (else (make-tree (value bst) (left bst) (bst-delete val (right bst) same? less-than?)))))
false
e49b166e7bcf4f373ded68913f9384143c81f02d
9adf00fadd55632cd84ee8f4268a65505337b21e
/src/maquette/context.scm
1478dbadbc7b2bd6a82b112c567b98dca2a0bc7e
[]
no_license
ktakashi/sagittarius-maquette
c44e20629ceec1750502784cb662b0d1153cc7e0
2cdd0233584d67a689c56723964b2366e2942b96
refs/heads/master
2020-04-06T13:52:02.999446
2016-10-26T14:19:01
2016-10-26T14:19:01
51,841,198
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,969
scm
context.scm
;;; -*- mode:scheme; coding:utf-8; -*- ;;; ;;; maquette/cotnext.scm - Context for Maquette ;;; ;;; Copyright (c) 2016 Takashi Kato <[email protected]> ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; 1. Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; 2. Redistributions in binary form must reproduce the above copyright ;;; notice, this list of conditions and the following disclaimer in the ;;; documentation and/or other materials provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; (library (maquette context) (export make-maquette-context maquette-context-release! maquette-context? maquette-max-connection-count call-with-maquette-connection with-maquette-transaction maquette-context-in-transaction? ;; low level maquette-get-connection maquette-return-connection) (import (rnrs) (clos user) (srfi :39) (sagittarius object) (maquette connection)) ;; Maquette context ;; A context manages a connection pool. All high level APIs shall take ;; a context to operate database. Users may import low level libraries ;; to do some low level operations such as generating SQL or creating ;; an extra abstraction layer (which should be provided by high level ;; APIs though). ;; ;; Why context? (future note for me) ;; maquette-get-connection and maquette-return-connection do exactly ;; the same as connection pool operations. Then why do we need context ;; layer? ;; Because we may want to do more on this layer other than retrieving ;; conenctios. Showing connection pool directly to users makes less ;; extensibility. It's not only for not but also for future. (not sure ;; what would be the future yet.) (define-class <maquette-context> () ((pool :init-keyword :pool) ;; connection pool (in-transaction? :init-value #f :reader maquette-context-in-transaction?) ;; TODO more? )) ;; Combination of with-maquette-transaction and ;; call-with-maquette-connection uses 2 or more connections in one ;; transaction and causes an error on DBI. To avoid it we need to make ;; sure that using the same connection in the same transaction. ;; ;; FIXME ugly (define *current-connection* (make-parameter #f)) (define (maquette-context? o) (is-a? o <maquette-context>)) (define (maquette-context-release! ctx) (maquette-connection-pool-release! (~ ctx 'pool))) (define (maquette-max-connection-count ctx) (maquette-connection-pool-max-connection-count (~ ctx 'pool))) (define (make-maquette-context dsn :key (max-connection 10) :allow-other-keys opts) (unless (> max-connection 0) (assertion-violation 'make-maquette-context ":max-connection must be non zero positive integer" max-connection)) (let ((pool (apply make-maquette-connection-pool max-connection dsn opts))) (make <maquette-context> :pool pool))) (define (call-with-maquette-connection ctx proc :key (timeout #f) (timeout-value #f)) (let ((c (*current-connection*))) (if c (proc c) (call-with-available-connection (~ ctx 'pool) (lambda (conn) (parameterize ((*current-connection* conn)) (proc conn))) timeout timeout-value)))) (define-syntax with-maquette-transaction (syntax-rules () ((_ ctx expr ...) (let ((c ctx)) (dynamic-wind (lambda () (set! (~ c 'in-transaction?) #t)) (lambda () (call-with-maquette-connection c (lambda (conn) (with-maquette-connection-transaction conn (let ((r (begin expr ...))) ;; commit if there's no problem (maquette-connection-commit! conn) r))))) (lambda () (set! (~ c 'in-transaction?) #f))))))) ;; Low level API ;; Maybe we shouldn't show this at all? (define (maquette-get-connection ctx . opt) (apply maquette-connection-pool-get-connection (~ ctx 'pool) opt)) (define (maquette-return-connection ctx conn) (maquette-connection-pool-return-connection (~ ctx 'pool) conn)) )
true
d170609c72367ff2d9961f86a5e02ee53bf6dcd6
ca3425fbd3bef3cd7adeb7b1f61f00afd097927f
/planet/bit-io.scm
24554eeb8595bcb547f72fb5d0ff84c3a19a1aca
[]
no_license
soegaard/little-helper
b330ec4382b958cd83b65e93c27581f5dc941c97
26249c688e5adf1e2535c405c6289030eff561b4
refs/heads/master
2021-01-16T18:06:35.491073
2011-08-11T23:00:56
2011-08-11T23:00:56
2,187,791
10
0
null
null
null
null
UTF-8
Scheme
false
false
22,130
scm
bit-io.scm
;;; bit-io.scm -- Jens Axel Søgaard -- april 2006 ; This file started as a PLT port of Oleg's bit-reader ; <http://okmij.org/ftp/Scheme/binary-io.html#bit-reader>, ; then a bit-writer was added, and finally bit-ports were ; added. (module bit-io mzscheme (provide with-input-from-bit-file with-output-to-bit-file open-input-bit-file open-output-bit-file close-input-bit-port close-output-bit-port read-bits write-bits current-output-bit-port current-input-bit-port flush-bits bit-file-position call-with-input-bit-file call-with-output-bit-file ; LOW LEVEL ;make-bit-reader ;make-bit-writer ;current-bit-reader ;current-bit-writer ;current-bit-flusher ) ; A BIT-PORT consists of an underlying (byte) port and ; the current (bit)position. (define-struct bit-port (port pos)) ; An INPUT-BIT-PORT is a bit-port with a concrete byte-reader ; which from which the corresponding bit-reader read is constructed. (define-struct (input-bit-port bit-port) (byte-reader read)) ; An OUTPUT-BIT-PORT is a bit-port with a concrete byte-writer ; from which the corresponding bit-writer write is constructed. ; Bits aren't written to the underlying byte port until a whole ; byte is received - a flush operations is thus sometimes needed ; at the end of a file. (define-struct (output-bit-port bit-port) (byte-writer write flush)) ; open-input-bit-file : path [symbol ... ] -> input-bit-port ; analog to open-input-file (define (open-input-bit-file file . options) (let ([byte-port (apply open-input-file file options)]) (make-input-bit-port byte-port 0 (λ () (read-byte byte-port)) (make-bit-reader (λ () (read-byte byte-port)))))) ; open-output-bit-file : path [symbol ...] -> output-bit-port ; analog to open-output-file (define (open-output-bit-file file . options) (let ([byte-port (apply open-output-file file options)]) (let-values ([(bit-writer bit-flusher) (make-bit-writer (λ (b) (write-byte b byte-port)))]) (make-output-bit-port byte-port 0 (λ (b) (write-byte b byte-port)) bit-writer bit-flusher)))) ; current bit-ports (define current-input-bit-port (make-parameter 'none-yet)) (define current-output-bit-port (make-parameter 'none-yet)) ; close-input-bit-port : input-bit-port -> (define (close-input-bit-port bit-port) (close-input-port (bit-port-port bit-port))) ; close-output-bit-port : output-bit-port -> (define (close-output-bit-port bit-port) ((output-bit-port-flush bit-port)) (close-output-port (bit-port-port bit-port))) ; with-input-from-bit-file : path (-> alpha) [symbol ...] -> alpha ; analog to with-input-from-file (define (with-input-from-bit-file file thunk . options) (let ([in (apply open-input-bit-file file options)]) (begin0 (parameterize ([current-input-bit-port in]) (thunk)) (close-input-bit-port in)))) ; with-output-to-bit-file : path (-> alpha) [symbol ...] -> alpha ; analog to with-to-file (define (with-output-to-bit-file file thunk . options) (let ([out (apply open-output-bit-file file options)]) (begin0 (parameterize ([current-output-bit-port out]) (thunk)) (close-output-bit-port out)))) (define (call-with-input-bit-file file proc . options) (let ([in (apply open-input-bit-file file options)]) (begin0 (proc in)) (close-input-bit-port in))) (define (call-with-output-bit-file file proc . options) (let ([out (apply open-output-bit-file file options)]) (begin0 (proc out) (close-output-bit-port out)))) ; write-bits : natural natural [output-bit-port] -> ; write n lower bits from bs to the output-bit-port, ; if no output-bit-port is given use current-output-bit-port (define write-bits (case-lambda [(n bs) (write-bits n bs (current-output-bit-port))] [(n bs bit-port) (begin (set-bit-port-pos! bit-port (+ (bit-port-pos bit-port) n)) ((output-bit-port-write bit-port) n bs))])) ; read-bits : natural [input-bit-port] -> natural ; read n bits from the input-bit-port, ; if no input-bit-port is given, use current-input-bit-port (define read-bits (case-lambda [(n) (read-bits n (current-input-bit-port))] [(n bit-port) (begin (set-bit-port-pos! bit-port (+ (bit-port-pos bit-port) n)) ((input-bit-port-read bit-port) n))])) ; flush-bits : [output-bit-port] -> ; flush remaining bits in the cache by append zeros until a ; whole byte can be written (define flush-bits (case-lambda [() (flush-bits (current-output-bit-port))] [(out-bit-port) ((output-bit-port-flush out-bit-port))])) ; bit-file-position : bit-port -> natural ; return the bit-position of the bit-port, ; the bit-position of an input-bit-port is the number of bits read so far, ; for an output-bit-port it is the number of bits written so far ; bit-file-position : bit-port natural -> natural ; set the bit-position of the bit-port (define bit-file-position ; todo: this only sets the position on an input port (case-lambda [(bit-port) (bit-port-pos bit-port)] [(bit-port n) (begin (unless (input-bit-port? bit-port) (error (string-append "(bit-file-position bit-port n) is not implemented " "for output bit ports."))) (file-position (bit-port-port bit-port) (quotient n 8)) (read-bits (remainder n 8) bit-port))])) ;;; ;;; LOW LEVEL INTERFACE ;;; ; The following bit reader comes from ; <http://okmij.org/ftp/Scheme/binary-io.html#bit-reader> ; Binary parsing ;---------------------------------------- ; Apologia ; ; Binary parsing and unparsing are transformations between primitive or ; composite Scheme values and their external binary representations. ; ; Examples include reading and writing JPEG, TIFF, MP3, ELF file ; formats, communicating with DNS, Kerberos, LDAP, SLP internet ; services, participating in Sun RPC and CORBA/IIOP distributed systems, ; storing and retrieving (arrays of) floating-point numbers in a ; portable and efficient way. This project will propose a set of low- and ; intermediate- level procedures that make binary parsing possible. ; Scheme is a good language to do research in text compression. Text ; compression involves a great deal of building and traversing ; dictionaries, trees and similar data structures, where Scheme ; excels. Performance doesn't matter in research, but the size of ; compressed files does (to figure out the bpc for the common ; benchmarks). Variable-bit i/o is a necessity. It is implemented ; in the present file. ; ASN.1 corresponds to a higher-level parsing (LR parser ; vs. lexer). Information in LDAP responses and X.509 certificates is ; structural and recursive, and so lends itself to be processed in ; Scheme. Variable bit i/o is necessary, and so is a binary lexer for ; a LR parser. Parsing of ASN.1 is a highly profitable enterprise ;---------------------------------------- ; The outline of the project ; ; Primitives and streams ; ; - read-byte ; - read-u8vector (cf. read-string) ; - with-input-from-u8vector, with-input-from-encoded-u8vector 'base64,... ; building binary i/o streams from a sequence of bytes. Streams over ; u8vector, u16vector, etc. provide a serial access to memory. See SRFI-4 ; ; - read-bit, read-bits via overlayed streams given read-byte ; implemented in the present file. ; ; - mmap-u8vector, munmap-u8vector ; ; Conversions ; - u8vector->integer u8vector endianness, ; u8vector->sinteger u8vector endianness ; These conversion procedures turn a sequence of bytes to an unsigned or ; signed integer, minding the byte order. The u8vector in question can ; have size 1,2,4,8, 3 etc. bytes. These two functions therefore can be ; used to read shorts, longs, extra longs, etc. numbers. ; - u8vector-reverse and other useful u8vector operations ; ; - modf, frexp, ldexp ; The above primitives can be emulated in R5RS, yet they are quite handy ; (for portable FP manipulation) and can be executed very efficiently by ; an FPU. ; ; Higher-level parsing and combinators ; These are combinators that can compose primitives above for more ; complex (possibly iterative) actions. ; ; - skip-bits, next-u8token,... ; - IIOP, RPC/XDR, RMI ; - binary lexer for existing LR/LL-parsers ; ; The composition of primitives and combinators will represent binary ; parsing language in a _full_ notation. This is similar to XPath ; expressions in full notation. Later we need to find out the ; most-frequently used patterns of the binary parsing language and ; design an abbreviated notation. The latter will need a special ; "interpreter". The abbreviated notation may turn out to look like ; Olin's regular expressions. ;;======================================================================== ;; Configuration section ;; ; Performance is very important for binary parsing. We have to get all ; help from a particular Scheme system we can get. If a Scheme function ; can support the following primitives faster, we should take ; advantage of that fact. ;; Configuration for PLT (define-syntax << (syntax-rules () [(_ x n) (arithmetic-shift x n)])) (define-syntax >> (syntax-rules () [(_ x n) (arithmetic-shift x (- n))])) (define-syntax <<1 (syntax-rules () [(_ x) (arithmetic-shift x 1)])) (define-syntax >>1 (syntax-rules () [(_ x) (arithmetic-shift x -1)])) (define-syntax bit-set? (syntax-rules () [(_ x mask) (not (zero? (bitwise-and x mask)))])) ;; End configuration for PLT ; combine bytes in the MSB order. A byte may be #f (define (combine-two b1 b2) ; The result is for sure a fixnum (and b1 b2 (bitwise-ior (<< b1 8) b2))) (define (combine-three b1 b2 b3) ; The result is for sure a fixnum (and b1 b2 b3 (bitwise-ior (<< (bitwise-ior (<< b1 8) b2) 8) b3))) ; Here the result may be a BIGNUM (define (combine-bytes . bytes) (cond ((null? bytes) 0) ((not (car bytes)) #f) (else (let loop ((bytes (cdr bytes)) (result (car bytes))) (cond ((null? bytes) result) ((not (car bytes)) #f) (else (loop (cdr bytes) (+ (car bytes) (* 256 result))))))))) ;======================================================================== ; Reading a byte ; Read-byte is a fundamental primitive; it needs to be ; added to the standard. Most of the other functions are library ; procedures. The following is an approximation, which clearly doesn't ; hold if the port is a Unicode (especially UTF-8) character stream. ; The mzscheme read-byte is used. ; Return a byte as an exact integer [0,255], or the EOF object #;(define (read-byte port) (let ((c (read-char port))) (if (eof-object? c) c (char->integer c)))) ; The same as above, but returns #f on EOF. (define (read-byte-f port) (let ([b (read-byte port)]) (and (not (eof-object? b)) b))) ;======================================================================== ; Bit stream ; -- Function: make-bit-reader BYTE-READER ; Given a BYTE-READER (a thunk), construct and return a function ; bit-reader N ; ; that reads N bits from a byte-stream represented by the BYTE-READER. ; The BYTE-READER is a function that takes no arguments and returns ; the current byte as an exact integer [0-255]. The byte reader ; should return #f on EOF. ; The bit reader returns N bits as an exact unsigned integer, ; 0 -... (no limit). N must be a positive integer, otherwise the bit reader ; returns #f. There is no upper limit on N -- other than the size of the ; input stream itself and the amount of (virtual) memory an OS is willing ; to give to your process. If you want to read 1M of _bits_, go ahead. ; ; It is assumed that the bit order is the most-significant bit first. ; ; Note the bit reader keeps the following condition true at all times: ; (= current-inport-pos (ceiling (/ no-bits-read 8))) ; That is, no byte is read until the very moment we really need (some of) ; its bits. The bit reader does _not_ "byte read ahead". ; Therefore, it can be used to handle a concatenation of different ; bit/byte streams *STRICTLY* sequentially, _without_ 'backing up a char', ; 'unreading-char' etc. tricks. ; For example, make-bit-reader has been used to read GRIB files of ; meteorological data, which made of several bitstreams with headers and ; tags. ; Thus careful attention to byte-buffering and optimization are the ; features of this bit reader. ; ; Usage example: ; (define bit-reader (make-bit-reader (lambda () #b11000101))) ; (bit-reader 3) ==> 6 ; (bit-reader 4) ==> 2 ; The test driver below is another example. ; ; Notes on the algorithm. ; The function recognizes and handles the following special cases: ; - the buffer is empty and 8, 16, 24 bits are to be read ; - reading all bits which are currently in the byte-buffer ; (and then maybe more) ; - reading only one bit ; Since the bit reader is going to be called many times, optimization is ; critical. We need all the help from the compiler/interpreter ; we can get. (define (make-bit-reader byte-reader) (let ((buffer 0) (mask 0) ; mask = 128 means that the buffer is full and ; the msb bit is the current (yet unread) bit (bits-in-buffer 0)) ; read the byte into the buffer and set up the counters. ; return #f on eof (define (set-buffer) (set! buffer (byte-reader)) (and buffer (begin (set! bits-in-buffer 8) (set! mask 128) #t))) ; Read fewer bits than there are in the buffer (define (read-few-bits n) (let ((value (bitwise-and buffer ; all bits in buffer (sub1 (<<1 mask))))) (set! bits-in-buffer (- bits-in-buffer n)) (set! mask (>> mask n)) (>> value bits-in-buffer))) ; remove extra bits ; read n bits given an empty buffer, and append them to value, n>=8 (define (add-more-bits value n) (let loop ((value value) (n n)) (cond ((zero? n) value) ((< n 8) (let ((rest (read-n-bits n))) (and rest (+ (* value (<< 1 n)) rest)))) (else (let ((b (byte-reader))) (and b (loop (+ (* value 256) b) (- n 8)))))))) ; The main module (define (read-n-bits n) ; Check the most common cases first (cond ((not (positive? n)) #f) ((zero? bits-in-buffer) ; the bit-buffer is empty (case n ((8) (byte-reader)) ((16) (let ((b (byte-reader))) (combine-two b (byte-reader)))) ((24) (let* ((b1 (byte-reader)) (b2 (byte-reader))) (combine-three b1 b2 (byte-reader)))) (else (cond ((< n 8) (and (set-buffer) (read-few-bits n))) ((< n 16) (let ((b (byte-reader))) (and (set-buffer) (bitwise-ior (<< b (- n 8)) (read-few-bits (- n 8)))))) (else (let ((b (byte-reader))) (and b (add-more-bits b (- n 8))))))))) ((= n 1) ; read one bit (let ((value (if (bit-set? buffer mask) 1 0))) (set! mask (>>1 mask)) (set! bits-in-buffer (sub1 bits-in-buffer)) value)) ((>= n bits-in-buffer) ; will empty the buffer (let ((n-rem (- n bits-in-buffer)) (value (bitwise-and buffer ; for mask=64, it'll be &63 (sub1 (<<1 mask))))) (set! bits-in-buffer 0) (cond ((zero? n-rem) value) ((<= n-rem 16) (let ((rest (read-n-bits n-rem))) (and rest (bitwise-ior (<< value n-rem) rest)))) (else (add-more-bits value n-rem))))) (else (read-few-bits n)))) read-n-bits) ) ;;; ;;; BIT WRITER ;;; ; -- Function: make-bit-writer BYTE-WRITER ; Given a BYTE-WRITER (function of one argument), construct and return a function ; bit-writer N B ; ; that writes N bits represented by the integer B to a byte-stream represented ; by the BYTE-WRITER. ; The BYTE-WRITER is a function that takes one argument and writes ; the given byte as an exact integer [0-255]. ; It is assumed that the bit order is the most-significant bit first. ; ; Note the bit writer will output bytes as soon as possible. That is ; the maximum number of waiting bits are 7. Call bit-writer with a ; non-number as argument to flush the remainin bits. (define (make-bit-writer byte-writer) (let ((buffer 0) (bits-in-buffer 0)) (define (empty-buffer!) (set! buffer 0) (set! bits-in-buffer 0)) (define (low-bits n b) (bitwise-and b (vector-ref #(0 1 3 7 15 31 63 127 255) n))) (define (extend-buffer! n b) (set! buffer (bitwise-ior (<< buffer n) b)) (set! bits-in-buffer (+ bits-in-buffer n))) (define (set-buffer! n b) (set! buffer b) (set! bits-in-buffer n)) (define (integer-length n) (unless (and (integer? n) (not (negative? n))) (error "a non-negative integer was expected, got: " n)) (if (<= n 1) 1 (+ 1 (integer-length (arithmetic-shift n -1))))) (define (flush-buffer) (unless (zero? bits-in-buffer) (byte-writer (<< buffer (- 8 bits-in-buffer))))) (define (write-n-bits n b) (when (and (number? n) (not (zero? n)) (> (integer-length b) n)) (error "doh!" (list n b))) ; (set! b (low-bits n b)) (cond ((not (positive? n)) #f) ((zero? bits-in-buffer) ; the bit-buffer is empty (case n ((8) (byte-writer b)) ((16) (byte-writer (>> (bitwise-and #b1111111100000000 b) 8)) (byte-writer (bitwise-and #b11111111 b))) (else (let ([r (remainder n 8)]) (cond ((zero? r) (for-each byte-writer (let loop ([n n] [b b] [l '()]) (if (= n 0) l (loop (- n 8) (>> b 8) (cons (bitwise-and #b11111111 b) l)))))) ((< n 8) (set-buffer! n b)) ((< n 16) (byte-writer (>> b (- n 8))) (set-buffer! (- n 8) (bitwise-and b (>> #b11111111 (- 16 n))))) (else (let ([bits-to-buffer (remainder n 8)]) ; output all whole bytes, and buffer the rest (write-n-bits (- n bits-to-buffer) (>> b bits-to-buffer)) (set-buffer! bits-to-buffer (bitwise-and b (vector-ref #(0 1 3 7 15 31 63 127 255) r)))))))))) ((< n (- 8 bits-in-buffer)) ; everything goes to the buffer (extend-buffer! n b)) (else (let ([m (- 8 bits-in-buffer)]) ;(display (list buffer bits-in-buffer n) (current-error-port)) ; (flush-output (current-error-port)) ; the buffer and the initial bits make a byte (byte-writer (bitwise-ior (<< buffer m) (>> b (- n m)))) (empty-buffer!) ; write the rest (write-n-bits (- n m) (bitwise-xor b (<< (>> b (- n m)) (- n m)))))))) (values write-n-bits flush-buffer))) ;;; TEST #; (define (test) (define (naturals n) (do ([i 0 (+ i 1)] [l '() (cons i l)]) [(= i n) l])) ; write the numbers 999 ... 1 to "tmp" and read them again (with-output-to-file "tmp" (lambda () (let-values ([(write flush) (make-bit-writer write-byte)]) (for-each (lambda (n) (write n n)) (naturals 100)) (flush))) 'replace) (with-input-from-file "tmp" (lambda () (let ([r (make-bit-reader read-byte)]) (for-each (lambda (n) (display (r n)) (display " ")) (naturals 100)))))) ;;; ;;; PARAMETERS ;;; (define current-bit-reader (make-parameter (make-bit-reader read-byte))) (define-values (current-bit-writer current-bit-flusher) (let-values ([(writer flusher) (make-bit-writer write-byte)]) (values (make-parameter writer) (make-parameter flusher)))) )
true
3aeff2f82eaf8eaa55c004a5fcf4b3baaa0445e2
fba55a7038615b7967256306ee800f2a055df92f
/vvalkyrie/2.2/ex-2-32.scm
24e3f70b2db9587332adfdcb19f4249c73d3271a
[]
no_license
lisp-korea/sicp2014
7e8ccc17fc85b64a1c66154b440acd133544c0dc
9e60f70cb84ad2ad5987a71aebe1069db288b680
refs/heads/master
2016-09-07T19:09:28.818346
2015-10-17T01:41:13
2015-10-17T01:41:13
26,661,049
2
3
null
null
null
null
UTF-8
Scheme
false
false
713
scm
ex-2-32.scm
; ex 2.32 (define (subsets s) (if (null? s) (list '()) ;; xxx (let ((rest (subsets (cdr s)))) (append rest (map (lambda (x) (cons (car s) x)) ;; <??> rest))))) (subsets '(1 2 3)) ;;=> (() (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3)) ;; (list nil) 을 '() 로 바꾼 부분이 bug 였다. ;; (list '())이 정확한 표현이다. ;; s = (3) 일 때 rest = (()) -> (() (3)) ;; s = (2 3) 일 때 rest = (() (3)) ;; -> consing 하면 ((2) ((2 3))) ;; -> rest에 append 하면 (() (3) (2) (2 3)) ;; s = (1 2 3) 일 때 rest = (() (3) (2) (2 3)) ;; -> consing 하면 ((1) (1 3) (1 2) (1 2 3)) ;; -> rest에 append 하면 최종 결과가 나옴
false
bb9db76a379fd249334132a6df04b11ee3da3684
be06d133af3757958ac6ca43321d0327e3e3d477
/99problems/26.scm
652ae61dce878953a4e4940aa6ad9b366eac5c68
[]
no_license
aoyama-val/scheme_practice
39ad90495c4122d27a5c67d032e4ab1501ef9c15
f133d9326699b80d56995cb4889ec2ee961ef564
refs/heads/master
2020-03-13T12:14:45.778707
2018-04-26T07:12:06
2018-04-26T07:12:06
131,115,150
0
0
null
null
null
null
UTF-8
Scheme
false
false
401
scm
26.scm
(define (member-tree x tree) (let loop ((lis tree)) (cond ((not (pair? lis)) (equal? x lis)) ((null? lis) #f) ((member-tree x (car lis)) #t) (else (loop (cdr lis)))))) (print (member-tree 'd '(a (b (c (d . e) f) g) h))) ; #t (print (member-tree 'e '#?=(a #?=(b #?=(c #?=(d . e) f) g) h))) ; #t (print (member-tree 'x '#?=(a #?=(b #?=(c #?=(d . e) f) g) h))) ; #f
false
52d0deb713893b58f3dc8e7c703d6622dcca545a
c3523080a63c7e131d8b6e0994f82a3b9ed901ce
/hertfordstreet/schemes/taggedsymbolicdiff.scm
9279554e5807070b159a727ed268b3bd817290b2
[]
no_license
johnlawrenceaspden/hobby-code
2c77ffdc796e9fe863ae66e84d1e14851bf33d37
d411d21aa19fa889add9f32454915d9b68a61c03
refs/heads/master
2023-08-25T08:41:18.130545
2023-08-06T12:27:29
2023-08-06T12:27:29
377,510
6
4
null
2023-02-22T00:57:49
2009-11-18T19:57:01
Clojure
UTF-8
Scheme
false
false
2,195
scm
taggedsymbolicdiff.scm
(load "putget.scm") (require (lib "trace.ss")) (define (atom? exp) (not (pair? exp))) (define (deriv exp var) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) (else ((get (operator exp) 'deriv) (operands exp) var)))) (define (operator exp) (car exp)) (define (operands exp) (cdr exp)) (define (variable? exp) (and (atom? exp) (not (number? exp)))) (define (same-variable? exp var) (and (atom? exp) (eq? exp var))) (define (make-sum a b) (list '+ a b)) (define (make-product a b) (list '* a b)) (define (make-difference a b) (list '- a b)) (define (make-quotient a b) (list '/ a b)) (define (make-logarithm a) (list 'log a)) (define (make-exponentiation a b) (list 'expt a b)) ;------------sums--------------------- (define (deriv-sum args var) (make-sum (deriv (car args) var) (deriv (cadr args) var))) (put '+ 'deriv deriv-sum) ;---------------products--------------- (define (deriv-product args var) (make-sum (make-product (deriv (car args) var) (cadr args)) (make-product (car args) (deriv (cadr args) var)))) (put '* 'deriv deriv-product) ;--------------differences------------- (define (deriv-diff args var) (make-difference (deriv (car args) var) (deriv (cadr args) var))) (put '- 'deriv deriv-diff) ;--------------quotients--------------- (define (deriv-quotient args var) (make-quotient (make-difference (make-product (deriv (car args) var) (cadr args)) (make-product (car args) (deriv (cadr args) var)) ) (make-product (cadr args) (cadr args)))) (put '/ 'deriv deriv-quotient) ;---------------logarithms--------------- (define (deriv-logarithm args var) (make-product (make-quotient 1 (car args)) (deriv (car args) var))) (put 'log 'deriv deriv-logarithm) ;---------exponents (expt a b)----------- (define (deriv-exponentiation args var) (let ((a (car args)) (b (cadr args))) (make-sum (make-product (make-product (make-exponentiation a b) (make-logarithm a)) (deriv b var)) (make-product (make-product b (make-exponentiation a (make-difference b 1))) (deriv a var))))) (put 'expt 'deriv deriv-exponentiation) (trace deriv) (deriv '(expt x x) 'x)
false
c3a9b337495c5674777d92d3152d52c7a280bdc2
382770f6aec95f307497cc958d4a5f24439988e6
/projecteuler/037/037.scm
0cfe34b80b2282961a158917343f4ced59cb85b1
[ "Unlicense" ]
permissive
include-yy/awesome-scheme
602a16bed2a1c94acbd4ade90729aecb04a8b656
ebdf3786e54c5654166f841ba0248b3bc72a7c80
refs/heads/master
2023-07-12T19:04:48.879227
2021-08-24T04:31:46
2021-08-24T04:31:46
227,835,211
1
0
null
null
null
null
UTF-8
Scheme
false
false
1,824
scm
037.scm
(define range 10000000) (define sievebound (quotient (- range 1) 2)) (define crosslimit (quotient (- (exact (floor (sqrt range))) 1) 2)) (define prime (make-bytevector sievebound 1)) (define prime-ref (lambda (pme i) (bytevector-u8-ref pme (- i 1)))) (define prime-set! (lambda (pme i arg) (bytevector-u8-set! pme (- i 1) arg))) (let filt ([i 1]) (cond ((> i sievebound)) ((= (prime-ref prime i) 1) (let f ([j (* 2 i (+ i 1))]) (cond ((> j sievebound) (filt (+ i 1))) (else (prime-set! prime j 0) (f (+ j (+ (* i 2) 1))))))) (else (filt (+ i 1))))) (define prime-r? (lambda (n) (cond ((<= n 0) #f) ((= n 1) #f) ((= n 2) #t) ((= (remainder n 2) 0) #f) ((= (prime-ref prime (/ (- n 1) 2)) 1) #t) (else #f)))) (define r-t-l (lambda (n) (quotient n 10))) (define l-t-r (lambda (n) (let ([stl (number->string n)]) (string-set! stl 0 #\0) (string->number stl)))) (define base (list 2 3 5 7)) (define left-tr-lst (let f ([i 1] [ls base] [curr base]) (cond ((>= i 7) ls) (else (let g ([lst curr] [cur '()]) (cond ((null? lst) (f (+ i 1) (append cur ls) cur)) (else (let h ([j 1] [atom (car lst)] [get '()]) (let ([prim (+ (* j (expt 10 i)) atom)]) (cond ((> j 9) (g (cdr lst) (append get cur))) ((prime-r? prim) (h (+ j 1) atom (cons prim get))) (else (h (+ j 1) atom get)))))))))))) (define right-yes? (lambda (n) (cond ((= n 0) #t) ((prime-r? n) (right-yes? (r-t-l n))) (else #f)))) (- (apply + (let pro ([ls left-tr-lst] [res '()]) (cond ((null? ls) res) ((right-yes? (car ls)) (pro (cdr ls) (cons (car ls) res))) (else (pro (cdr ls) res)))) ) (apply + base)) ;;748317
false
d449c56e182465c6856de0a4fe030960914adcb6
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/racket/web/flickr/six-degrees.ss
10e5e66fcb74334fff8908923748e2771fed0d35
[]
no_license
offby1/doodles
be811b1004b262f69365d645a9ae837d87d7f707
316c4a0dedb8e4fde2da351a8de98a5725367901
refs/heads/master
2023-02-21T05:07:52.295903
2022-05-15T18:08:58
2022-05-15T18:08:58
512,608
2
1
null
2023-02-14T22:19:40
2010-02-11T04:24:52
Scheme
UTF-8
Scheme
false
false
4,138
ss
six-degrees.ss
#! /bin/sh #| Hey Emacs, this is -*-scheme-*- code! #$Id$ exec mzscheme -M errortrace -qu "$0" ${1+"$@"} |# (module six-degrees mzscheme (require (lib "trace.ss") (only (lib "url.ss" "net") make-url make-path/param get-pure-port string->url url->string) (only (lib "1.ss" "srfi") take) (only (lib "13.ss" "srfi") string-join) (only (planet "sxml.ss" ("lizorkin" "sxml.plt")) sxpath) (only (planet "htmlprag.ss" ("neil" "htmlprag.plt" )) html->shtml) (only (lib "pretty.ss") pretty-display pretty-print) (only (planet "bfs.ss" ("offby1" "offby1.plt") ) bfs bfs-distance) "flickr.ss") (define *initial-username* ;"George V. Reilly" ;easy "ohnoimdead" ;hard ) (define *initial-nsid* (car ((sxpath '(user @ nsid *text*)) (flickr.people.findByUsername 'username *initial-username* )))) (define *cache-file-name* "cache") (define *cached-contacts* (make-hash-table 'equal)) (when (file-exists? *cache-file-name*) (with-input-from-file *cache-file-name* (lambda () (let loop () (let ((datum (read))) (when (not (eof-object? datum)) (hash-table-put! *cached-contacts* (car datum) (cdr datum)) (loop)))))) (printf "Read ~a contacts from ~a~%" (hash-table-count *cached-contacts*) *cache-file-name*) (flush-output)) (define (get-for-real user_id) (let* ((url (string->url (format "http://www.flickr.com/people/~a" user_id))) (profile-page (html->shtml (get-pure-port url))) (strongs ((sxpath '(// strong *text*)) profile-page)) (contacts ((sxpath '(// (contact (@ username)))) (flickr.contacts.getPublicList 'user_id user_id))) (usernames ((sxpath '(@ username *text*)) contacts))) (printf "Finding contacts of ~a, distance ~a from ~a~%" user_id (bfs-distance) *initial-username*) (flush-output) ((sxpath '(@ nsid *text*)) contacts))) (call/ec (lambda (return) (parameterize-break #t (with-handlers ([exn:break? (lambda (x) (return))]) (let ((trail (bfs *initial-nsid* "20825469@N00" ; yours truly string=? ;; an idea: rather than tracking down contacts, we ;; could instead track down favorite photos, and ;; extract the authors from those. (lambda (user_id) (let ((probe (hash-table-get *cached-contacts* user_id #f))) (when probe (fprintf (current-error-port) "Woo hoo! Found ~a in cache~%" user_id) (flush-output (current-error-port))) (when (not probe) (set! probe (get-for-real user_id)) (parameterize-break #f (let ((op (open-output-file *cache-file-name* 'append))) (write (cons user_id probe) op) (newline op) (close-output-port op) ))) probe)) 3))) (if trail (printf "~a~%" (string-join (map (lambda (nsid) (car ((sxpath '(person username *text*)) (flickr.people.getInfo 'user_id nsid)))) trail) " => ")) (printf "Bummer -- no path~%")) ))))) (newline) (pretty-print (get-timings)) )
false
21babe2de3f4c2dc3f5ae6c3eec1d27fc6ab7fb5
51d30de9d65cc3d5079f050de33d574584183039
/utility/uuid.scm
b67d51f88f073b9ca93f387ffdfc316a47198e51
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
langmartin/ykk
30feb00265d603ef765b5c664d2f759be34b7b89
dd6e441dddd5b6363ee9adbbdd0f346c1522ffcf
refs/heads/master
2016-09-05T20:01:19.353224
2009-12-10T16:25:55
2009-12-10T16:25:55
408,478
0
1
null
null
null
null
UTF-8
Scheme
false
false
6,147
scm
uuid.scm
;; UUID generation ;; See: http://www.ietf.org/rfc/rfc4122.txt ;; ;; Version 4 UUID, see section 4.4 (define (%mask size) (bitwise-not (arithmetic-shift -1 size))) (define (extract-bit-field size position n) (bitwise-and (%mask size) (arithmetic-shift n (- position)))) (define-syntax define-numeric-list-ops (syntax-rules () ((_ width cons car cdr) (begin (define (cons n sum) (+ n (arithmetic-shift sum width))) (define (car sum) (extract-bit-field width 0 sum)) (define (cdr sum) (arithmetic-shift sum (- width))))))) (define-numeric-list-ops 8 u8cons u8car u8cdr) (define-numeric-list-ops 4 u4cons u4car u4cdr) ;; (begin ;; (define (u8list . args) ;; (fold-right u8cons 0 args)) ;; (define (u8cddr sum) ;; (u8cdr (u8cdr sum))) ;; (define (u8caddr sum) ;; (u8car (u8cddr sum))) ;; (u8caddr (u8list 1 2 3 4 5))) ;; (begin ;; (define (u4list . args) ;; (fold-right u4cons 0 args)) ;; (define (u4cddr sum) ;; (u4cdr (u4cdr sum))) ;; (define (u4caddr sum) ;; (u4car (u4cddr sum))) ;; (u4caddr (u4list 1 2 3 4 5))) (assert (u8car (u8cdr (u8cons 2 (u8cons 3 0)))) => 3) (define (u8unfold gen len) (let lp ((n len)) (if (zero? n) 0 (u8cons (gen n) (lp (- n 1)))))) (define (make-numeric-fold-right car cdr) (lambda (cons nil sum) (let lp ((nil nil) (sum sum)) (if (zero? sum) nil (lp (cons (car sum) nil) (cdr sum)))))) (define (make-numeric-fold car cdr) (lambda (cons nil sum) (let lp ((sum sum)) (if (zero? sum) nil (cons (car sum) (lp (cdr sum))))))) (define u8fold (make-numeric-fold u8car u8cdr)) (define u8fold-right (make-numeric-fold-right u8car u8cdr)) (define u4fold (make-numeric-fold u4car u4cdr)) (define u4fold-right (make-numeric-fold-right u4car u4cdr)) (assert (u8fold-right cons '() (u8unfold (lambda (n) (+ n 3)) 16)) => '(4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)) (define (uuidgen) (u8unfold (lambda (n) (let ((rand (random-integer 256))) (case n ((6) (bitwise-ior #b10000000 (bitwise-xor #b10111111 rand))) ((8) (bitwise-ior #b01000000 (bitwise-xor #b01001111 rand))) (else rand)))) 16)) (define (make-display-rules format) (fold-right (lambda (c lst) (if (char=? c #\-) (cons c (cdr lst)) (cons #f lst))) '() (string->list format))) (define hex '#(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\A #\B #\C #\D #\E #\F)) (define format (make-display-rules "0000-00-00-00-000000")) (define vref vector-ref) (define (num->hex n) (u4fold (lambda (n acc) (display (vref hex n))) #f n)) (define (uuid-number-display uuid) (u8fold (lambda (byte dashes) (if (car dashes) (display (car dashes))) (num->hex byte) (cdr dashes)) format uuid)) (define (uuid-number->string uuid) (let-string-output-port (uuid-number-display uuid))) (define (string-uuid->number string) (with-string-input-port (string-append "#x" (string-delete #\- string)) read)) ;; (let ((uuid (uuidgen-v1->hex-string))) ;; (assert uuid => (uuid-number->string (uuid-string->number uuid)))) (define (uuid-string? s) (uuid-number? (string-uuid->number s))) (define (uuid-number? n) (and ;; (= #b01 (extract-bit-field 2 (+ 1 (* 8 8)) n)) (= #b01 (extract-bit-field 2 (- (- 128 (* 8 8)) 2) n)) (= #b0100 (extract-bit-field 4 (- (- 128 (* 8 6)) 4) n)))) ;; (uuid->hex-string (uuidgen)) ;; (extract-bit-field ;; 4 ;; ;; (- (- 128 (* 8 8)) 2) ;; (- (- 128 (* 8 6)) 4) ;; (uuidgen) ;; ;; (string-uuid->number ;; ;; (uuidgen-v1->hex-string) ;; ;; ;; "6AAF975E-5D43-4E4A-9CEF-32C8408C9C2A" ;; ;; ) ;; ) (define (uuidgen-v1->hex-string) (let ((n1 (random-integer 65536)) (n2 (random-integer 65536)) (n3 (random-integer 65536)) (n4 (random-integer 65536)) (n5 (random-integer 65536)) (n6 (random-integer 65536)) (n7 (random-integer 65536)) (n8 (random-integer 65536))) (string ;; time_lo (vector-ref hex (extract-bit-field 4 12 n1)) (vector-ref hex (extract-bit-field 4 8 n1)) (vector-ref hex (extract-bit-field 4 4 n1)) (vector-ref hex (extract-bit-field 4 0 n1)) (vector-ref hex (extract-bit-field 4 12 n2)) (vector-ref hex (extract-bit-field 4 8 n2)) (vector-ref hex (extract-bit-field 4 4 n2)) (vector-ref hex (extract-bit-field 4 0 n2)) #\- ;; time_mid (vector-ref hex (extract-bit-field 4 12 n3)) (vector-ref hex (extract-bit-field 4 8 n3)) (vector-ref hex (extract-bit-field 4 4 n3)) (vector-ref hex (extract-bit-field 4 0 n3)) #\- ;; time_hi_and_version (vector-ref hex #b0100) (vector-ref hex (extract-bit-field 4 8 n4)) (vector-ref hex (extract-bit-field 4 4 n4)) (vector-ref hex (extract-bit-field 4 0 n4)) #\- ;; clock_seq_hi_and_reserved (vector-ref hex (bitwise-ior (extract-bit-field 2 12 n5) #b1000)) (vector-ref hex (extract-bit-field 4 8 n5)) ;; clock_seq_low (vector-ref hex (extract-bit-field 4 4 n5)) (vector-ref hex (extract-bit-field 4 0 n5)) #\- ;; node (vector-ref hex (extract-bit-field 4 12 n6)) (vector-ref hex (extract-bit-field 4 8 n6)) (vector-ref hex (extract-bit-field 4 4 n6)) (vector-ref hex (extract-bit-field 4 0 n6)) (vector-ref hex (extract-bit-field 4 12 n7)) (vector-ref hex (extract-bit-field 4 8 n7)) (vector-ref hex (extract-bit-field 4 4 n7)) (vector-ref hex (extract-bit-field 4 0 n7)) (vector-ref hex (extract-bit-field 4 12 n8)) (vector-ref hex (extract-bit-field 4 8 n8)) (vector-ref hex (extract-bit-field 4 4 n8)) (vector-ref hex (extract-bit-field 4 0 n8)))))
true
fba8d01d02867c5e56449708c15ac2f85ae970f3
6d8516960c6fd93e063d23d5d3edad82dd75cb16
/ch01/ex1.1.scm
e045ce357a87cc0ed428c28a433b1a73e9afe633
[]
no_license
d11wtq/L.i.S.P
e600a7fd527079d8ab0df7296345b3f9be990ace
6e826ddba7f2e725d767e76b464f0baa32405e39
refs/heads/master
2021-01-19T11:02:17.834736
2014-03-31T11:12:36
2014-03-31T11:12:36
18,139,047
0
1
null
null
null
null
UTF-8
Scheme
false
false
288
scm
ex1.1.scm
;;;; ;;; Lisp in Small Pieces, Chapter 1, ex 1.1. ;;;; (load "../ch01.scm") (define old-invoke invoke) (define (invoke f args) (let ((result (old-invoke f args))) (display (format "Invoked ~a => ~a~%" (cons f args) result)) result))
false
aa02853b3f884b109f598f835bd1e2dd0277c165
b14c18fa7a4067706bd19df10f846fce5a24c169
/Chapter2/2.39.scm
8379443146b9b71286c5d19d95c86557fb0d42e8
[]
no_license
silvesthu/LearningSICP
eceed6267c349ff143506b28cf27c8be07e28ee9
b5738f7a22c9e7967a1c8f0b1b9a180210051397
refs/heads/master
2021-01-17T00:30:29.035210
2016-11-29T17:57:16
2016-11-29T17:57:16
19,287,764
3
0
null
null
null
null
UTF-8
Scheme
false
false
813
scm
2.39.scm
#lang scheme (define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) (accumulate op initial (cdr sequence))) ) ) (define (fold-left op initial sequence) (define (iter result rest) (if (null? rest) result (iter (op result (car rest)) (cdr rest) ) ) ) (iter initial sequence) ) (define fold-right accumulate) ; -------------------------------------- (define (reverse sequence) (fold-right (lambda (x y) (display "x=")(display x)(display " y=")(display y) (newline) (append y (list x)) ; took a while to recall there is a "append"... ; although it just work as a "push_back" ) null sequence ) ) (reverse '(1 2 3)) (define (reverse-l sequence) (fold-left (lambda (x y) (cons y x)) null sequence) ) (reverse-l '(1 2 3))
false
40eb35060e91c4f6c19a739e2209d12b1905a703
6c6cf6e4b77640825c2457e54052a56d5de6f4d2
/ch3/3_55-partial-sums.scm
4ae110f076effa64bb4a2fdadd4e5c2b6c92fb17
[]
no_license
leonacwa/sicp
a469c7bc96e0c47e4658dccd7c5309350090a746
d880b482d8027b7111678eff8d1c848e156d5374
refs/heads/master
2018-12-28T07:20:30.118868
2015-02-07T16:40:10
2015-02-07T16:40:10
11,738,761
0
0
null
null
null
null
UTF-8
Scheme
false
false
142
scm
3_55-partial-sums.scm
;ex 3.55 partial-sums (define (partial-sums s) (define ps (cons-stream (stream-car s) (stream-map + ps (stream-cdr s)))) ps)
false
8fe2488f3b6f4b19d09d89c1aeab564d3a4f895b
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/mono/audio/audio-data.sls
175c68a6850d5264f301ad07fc9f25e666dbefcd
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,114
sls
audio-data.sls
(library (mono audio audio-data) (export is? audio-data? play setup channels rate format is-stopped?-get is-stopped?-set! is-stopped?-update!) (import (ironscheme-clr-port)) (define (is? a) (clr-is Mono.Audio.AudioData a)) (define (audio-data? a) (clr-is Mono.Audio.AudioData a)) (define-method-port play Mono.Audio.AudioData Play (System.Void Mono.Audio.AudioDevice)) (define-method-port setup Mono.Audio.AudioData Setup (System.Void Mono.Audio.AudioDevice)) (define-field-port channels #f #f (property:) Mono.Audio.AudioData Channels System.Int32) (define-field-port rate #f #f (property:) Mono.Audio.AudioData Rate System.Int32) (define-field-port format #f #f (property:) Mono.Audio.AudioData Format Mono.Audio.AudioFormat) (define-field-port is-stopped?-get is-stopped?-set! is-stopped?-update! (property:) Mono.Audio.AudioData IsStopped System.Boolean))
false
a0e29d5fba4fc5a7719914c372439efe5312851e
5cff1b36355d64cd109f8e4168f68283daddb404
/universe.scm
42d090c4ac72b0ce33306e748043f2b461ab44ca
[]
no_license
natj212/Racing-Game
2b77d89a91ba7c52ea3159ff8c724d2f3d153535
d2a8f348e13526c90b4fad5760b265e5f95d2667
refs/heads/master
2022-11-28T11:47:49.913466
2020-08-10T21:53:41
2020-08-10T21:53:41
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
6,673
scm
universe.scm
(use srfi-69) (use srfi-113) (use srfi-128) (use (prefix sdl2 sdl2:) (prefix sdl2-ttf ttf:)) (define hash-ref (lambda (table . keys) (cond [(> (length keys) 1) (apply hash-ref (cons (hash-table-ref table (car keys)) (cdr keys))) ] [else (hash-table-ref table (car keys))]))) (define hash-update (lambda (table . rest) (let ([tb (hash-table-copy table)]) (cond [(> 2 (length rest)) (raise "Not enough arguments")] [(>= 2 (length rest)) (hash-table-update! tb (car rest) (cadr rest))] [else (hash-table-update! (apply hash-ref (cons tb (reverse (cddr (reverse rest))))) (cadr (reverse rest)) (car (reverse rest)))]) tb ))) (define hash-set (lambda (table val . rest) (apply hash-update (append (list table) rest (list (lambda (x) val)))))) (define-syntax make-hash (syntax-rules () ((_ (key val) ... ) (alist->hash-table (list (cons (quote key) val) ...))))) (define draw-fill-rect (lambda (sdl x y w h) (sdl2:render-fill-rect! (cdr sdl) (sdl2:make-rect x y w h)))) (define set-color (lambda (sdl col) (sdl2:render-draw-color-set! (cdr sdl) (apply sdl2:make-color col) ))) (define draw-line (lambda (sdl x1 y1 x2 y2) (sdl2:render-draw-line! (cdr sdl) x1 y1 x2 y2))) (define distance2 (lambda (x1 y1 x2 y2) (+ (expt (- x2 x1) 2) (expt (- y2 y1) 2)))) (define render-texture (lambda (sdl texture x y #!optional color width height) (let ([width (if width width (sdl2:texture-w texture))] [height (if height height (sdl2:texture-h texture))]) (if color (set! (sdl2:texture-color-mod texture) color)) (sdl2:render-copy! (cdr sdl) texture #f (sdl2:make-rect (- x (quotient width 2)) (- y (quotient height 2)) width height))))) (define open-font (lambda (path size) (ttf:open-font path size))) (define make-text (lambda (font text sdl) (sdl2:create-texture-from-surface (cdr sdl) (ttf:render-utf8-solid font text (sdl2:make-color 255 255 255))))) (define make-color (lambda (r g b #!optional a) (if a (sdl2:make-color r g b a) (sdl2:make-color r g b)))) (define make-circle (lambda (radius sdl #!optional color surface comparator) (let ([surf (if surface surface (sdl2:make-surface (* 2 radius) (+ (* 2 radius) 1) 32))] [color (if color color (sdl2:make-color 255 255 255))] [comparator (if comparator comparator >)]) (sdl2:lock-surface! surf) (do ((i 0 (+ 1 i))) ((> i (* 4 radius radius))) (let ([x (modulo i (* 2 radius))] [y (quotient i (* 2 radius))]) (cond [(comparator (* radius radius) (distance2 radius radius x y)) (sdl2:surface-set! surf x y color)]))) (sdl2:unlock-surface! surf) (sdl2:create-texture-from-surface (cdr sdl) surf)))) (define-syntax big-bang (syntax-rules (init-world on-draw stop-when on-key) ((_ (init-world init-proc sizes ...) body body* ...) (begin (define (make-events keyboard mouse) (make-hash (keyboard keyboard) (mouse mouse))) (define (make-set) (set (make-equal-comparator))) (define (get-events events quit) (let ([event (sdl2:poll-event!)]) (cond [event (cond [(sdl2:quit-event? event) (quit)] [(sdl2:keyboard-event? event) (hash-table-set! events 'keyboard (if (sdl2:keyboard-event-state event) (set-adjoin (hash-ref events 'keyboard) (sdl2:keyboard-event-scancode event)) (set-delete (hash-ref events 'keyboard) (sdl2:keyboard-event-scancode event))))] [(sdl2:mouse-button-event? event) (hash-table-set! events 'mouse (cons (list 'button (sdl2:mouse-button-event-state event) (sdl2:mouse-button-event-button event)) (cons (list 'movement (cons (sdl2:mouse-button-event-x event) (sdl2:mouse-button-event-y event))) (hash-ref events 'mouse))))] [(sdl2:mouse-motion-event? event) (hash-table-set! events 'mouse (cons (list 'movement (cons (sdl2:mouse-motion-event-x event) (sdl2:mouse-motion-event-y event))) (hash-ref events 'mouse)))]) (get-events events quit)] [else events]))) (define (make-state world sdl return events) (make-hash (world world) (sdl sdl) (return return) (events events))) (define do-events (lambda (world events proc) (cond [(null? events) world] [else (proc (do-events world (cdr events) proc) (car events))]))) (sdl2:set-main-ready!) (sdl2:init!) (ttf:init!) ;Sets vsync (sdl2:set-hint! 'render-vsync "1") (current-exception-handler (let ((original-handler (current-exception-handler))) (lambda (exception) (sdl2:quit!) (original-handler exception)))) (let* ([options (list sizes ...)] [window-size (if (not (null? options)) options '(1280 720))] [sdl (call-with-values (lambda () (sdl2:create-window-and-renderer! (first window-size) (second window-size) '())) cons)] [events (make-events (make-set) '())]) (letrec ([run (lambda (world time) ;Locks framerate at 60 (let ([offset (- (quotient 1000 60) (- (sdl2:get-ticks) time))]) (sdl2:delay! (if (> offset 0) offset 0))) (let ([last-time (sdl2:get-ticks)]) (call/cc (lambda (return) (set! events (get-events events (lambda () (return world)))) (let* ([state (make-state world sdl return events)]) (run (big-bang state body body* ...) last-time ))))))]) (run (init-proc sdl) 0 )) (sdl2:destroy-window! (car sdl))))) ((_ state (on-draw proc) body ...) (begin (sdl2:render-clear! (cdr (hash-ref state 'sdl))) (let ([result (proc (big-bang state body ...) (hash-ref state 'sdl))]) (sdl2:render-present! (cdr (hash-ref state 'sdl))) result))) ((_ state (stop-when proc) body ...) (let ([return (hash-ref state 'return)]) (cond [(proc (big-bang state body ...)) (return (hash-ref state 'world))]) (big-bang state body ...))) ((_ state (on-key proc) body ...) (do-events (big-bang state body ...) (set->list (hash-ref state 'events 'keyboard)) proc)) ((_ state (on-mouse proc) body ...) (let ([result (do-events (big-bang state body ...) (hash-ref state 'events 'mouse) proc)]) (hash-table-set! (hash-ref state 'events) 'mouse '()) result)) ((_ state) (hash-ref state 'world))))
true
96473e76c560937e2c726602c331c2c4fc256621
307481dbdfd91619aa5fd854c0a19cd592408f1b
/node_modules/biwascheme/,/library/counter/other.sld
75ba8222bd0bda786744afa3a6bdcf29c14483d3
[ "MIT", "CC-BY-3.0" ]
permissive
yukarigohan/firstrepository
38ff2db62bb8baa85b21daf65b12765e10691d46
2bcdb91cbb6f01033e2e0a987a9dfee9d3a98ac7
refs/heads/master
2020-04-20T10:59:02.600980
2019-02-02T07:08:41
2019-02-02T07:08:41
168,803,970
0
0
null
null
null
null
UTF-8
Scheme
false
false
75
sld
other.sld
(define-library (other) (import (counter)) (begin (counter-inc!)))
false
e17d9890edd379271cd017f0f80f6ec2c04ea77f
140a499a12332fa8b77fb738463ef58de56f6cb9
/worlds/core/verbcode/119/base64-encode-2.scm
6a913310ab710b8cd6ba493df29a90af889a322b
[ "MIT" ]
permissive
sid-code/nmoo
2a5546621ee8c247d4f2610f9aa04d115aa41c5b
cf504f28ab473fd70f2c60cda4d109c33b600727
refs/heads/master
2023-08-19T09:16:37.488546
2023-08-15T16:57:39
2023-08-15T16:57:39
31,146,820
10
0
null
null
null
null
UTF-8
Scheme
false
false
1,883
scm
base64-encode-2.scm
(define base64-encode-triplet (lambda (c1 c2 c3) (if (nil? c1) (err E_ARGS "base64-encode-triplet's first argument must be not nil") (let ((e1 (/ c1 4)) (e2-partial (* (% c1 4) 16))) (if (nil? c2) (list e1 e2-partial -1 -1) (let ((e2 (+ e2-partial (/ c2 16))) (e3-partial (* (% c2 16) 4))) (if (nil? c3) (list e1 e2 e3-partial -1) (let ((e3 (+ e3-partial (/ c3 64))) (e4 (% c3 64))) (list e1 e2 e3 e4))))))))) (define base64-lookup (lambda (value) (cond ((= value -1) "=") ; padding ((< value 26) (chr (+ value (ord "A")))) ((< value 52) (chr (+ (- value 26) (ord "a")))) ((< value 62) (chr (+ (- value 52) (ord "0")))) ((= value 62) "+") ((= value 63) "/") ((err E_ARGS (cat "base 64 value out of range: " value)))))) (define base64-encode (lambda (str) (let ((size (len str)) (num-blocks (/ size 3)) (no-padding? (= 0 (% size 3))) (blocks (range 0 (if no-padding? (- num-blocks 1) num-blocks)))) (if (= 0 size) "" (call cat (map (lambda (block) (let ((idx (* block 3)) ; guaranteed not to be out of bounds (c1 (ord (substr str idx idx))) (c2 (if (> idx (- size 2)) nil (ord (substr str (+ idx 1) (+ idx 1))))) (c3 (if (> idx (- size 3)) nil (ord (substr str (+ idx 2) (+ idx 2)))))) (call cat (map base64-lookup (base64-encode-triplet c1 c2 c3))))) blocks)))))) (if (not (= 1 (len args))) (err E_ARGS (cat verb " takes one string argument")) (let ((str (get args 0))) (base64-encode str)))
false
7adc9ef75fbd7c9fc3feaab943fd15ecaf09987a
66face060b57fab316ae7fbfc23af33a683ee9b2
/chicken/pr015.scm
b757b78c6f7204260c412cc47f27d755acfc0772
[]
no_license
d3zd3z/euler
af56ec84c0cd59f682489dd3b47f713d206ef377
af7365ea58ed317b5c818d8ca7d9df73b961ae18
refs/heads/main
2021-07-09T05:24:05.173898
2021-04-24T23:35:14
2021-04-24T23:35:14
238,053
3
0
null
null
null
null
UTF-8
Scheme
false
false
765
scm
pr015.scm
;;; Problem 15 ;;; ;;; 19 April 2002 ;;; ;;; Starting in the top left corner of a 2x2 grid, there are 6 routes (without ;;; backtracking) to the bottom right corner. ;;; ;;; [p_015] ;;; ;;; How many routes are there through a 20x20 grid? ;;; ;;; 137846528820 ;(require-extension numbers) (define (base n) (make-vector (add1 n) 1)) (define (bump line) (define size (- (vector-length line) 1)) (do ((i 0 (+ i 1))) ((= i size)) (let ((i2 (+ i 1))) (vector-set! line i2 (+ (vector-ref line i2) (vector-ref line i)))))) (define (euler-15) (define size 20) (define item (base size)) (do ((i 0 (add1 i))) ((= i size)) (bump item)) (vector-ref item size)) (display (euler-15)) (newline)
false
6f86b65b2681b4d34c25aba45056098c822f2475
53cb8287b8b44063adcfbd02f9736b109e54f001
/parser/parser-errors.scm
ae4d09703030fb709a65a75af0c6be793c74fdd9
[]
no_license
fiddlerwoaroof/yale-haskell-reboot
72aa8fcd2ab7346a4990795621b258651c6d6c39
339b7d85e940db0b8cb81759e44abbb254c54aad
refs/heads/master
2021-06-22T10:32:25.076594
2020-10-30T00:00:31
2020-10-30T00:00:31
92,361,235
3
0
null
null
null
null
UTF-8
Scheme
false
false
2,330
scm
parser-errors.scm
;;; This contains parser error handlers. They, in turn, call the ;;; system error handlers. (define (lexer-error id . msgs) (parser-error/common id 'recoverable msgs '#t) `#\?) (define (parser-error id . msgs) (parser-error/common id 'phase msgs '#f) (if (null? *layout-stack*) (abort-compilation) (recover-to-next-decl *token-stream*))) (define (parser-error/recoverable id . args) (parser-error/common id 'recoverable args '#f)) (define (parser-error/common id type msgs in-lexer?) (let ((place (if in-lexer? (list "Error occured at in file ~A at line ~A, column ~A." *current-file* *current-line* *current-col*) (list "Error occured at in file ~A at line ~A, token ~A." *current-file* *current-line* (cond ((null? *token-args*) *token*) ((null? (cdr *token-args*)) (car *token-args*)) (else *token-args*)))))) ; could be better (haskell-error id type (list place msgs)))) (define (recover-to-next-decl tokens) (cond ((null? tokens) (abort-compilation)) ((eq? (car (car tokens)) 'line) (search-layout-stack *layout-stack* tokens (caddr (car tokens)))) (else (recover-to-next-decl (cdr tokens))))) (define (search-layout-stack layouts tokens column) (cond ((null? layouts) (abort-compilation)) ((> column (layout-col (car layouts))) (recover-to-next-decl (cdr tokens))) ((= column (layout-col (car layouts))) (setf *current-col* column) (setf *current-line* (cadr (car tokens))) (setf *token-stream* (cdr tokens)) (advance-token) ; loads up *token* ;; *** layout-recovery-fn is not defined anywhere! (funcall (layout-recovery-fn (car layouts)))) (else (setf *layout-stack* (cdr *layout-stack*)) (search-layout-stack (cdr layouts) tokens column)))) ;;; Here are some very commonly used signalling functions. ;;; Other (more specific) signalling functions are defined near ;;; the places where they are called. ;;; This is used when a particular token isn't found. (define (signal-missing-token what where) (parser-error 'missing-token "Missing ~a in ~a." what where)) ;;; This is used to signal more complicated parse failures involving ;;; failure to match a nonterminal. (define (signal-invalid-syntax where) (parser-error 'invalid-syntax "Invalid syntax appears where ~a is expected." where))
false
667e95a781c6492420b2d0fddf72a23f9d585d90
927764fbf52b0411142b198b618bee7188308297
/tests/parser.scm
907c106e13fe73170af26f93b96664d771f60ed1
[ "MIT" ]
permissive
jcubic/lips
49b60b2f9c4e0dc5882d3a69ddf16081f602b074
cab80df6a208f44f7c91d3da450de117d2f68760
refs/heads/master
2023-08-29T12:43:56.372494
2023-05-27T09:55:00
2023-05-27T09:55:00
122,653,051
320
40
NOASSERTION
2023-04-13T21:30:26
2018-02-23T17:39:04
JavaScript
UTF-8
Scheme
false
false
6,003
scm
parser.scm
(set-special! "<>" 'html lips.specials.SPLICE) (define-macro (html . args) (let ((str (--> (list->array (map symbol->string args)) (join "+")))) `(string-append "<" ,str "/>"))) (define parser/t1 <>(foo bar)) (unset-special! "<>") (set-special! "--" 'dash lips.specials.LITERAL) (define-macro (dash x) `'(,(car x) . ,(cadr x))) (define parser/t2 --(foo bar baz)) (unset-special! "--") (define parser/t3 (read "(--)")) (set-special! ":" 'keyword lips.specials.LITERAL) (define-macro (keyword n) `(string->symbol (string-append ":" (symbol->string ',n)))) (define parser/t4 :foo) (set-special! ":" 'keyword lips.specials.SPLICE) (define-macro (keyword . n) `(string->symbol (string-append ":" (symbol->string ',n)))) (define parser/t5 :foo) (unset-special! ":") (set-special! "::" 'cube) (define (cube x) (if (number? x) (* x x x) `(let ((.x ,x)) (* .x .x .x)))) (define parser/t6 (let ((x 3)) ::x)) (define parser/t7 (read "(let ((x 3)) ::x))")) (unset-special! "::") (test "parser: syntax extension" (lambda (t) (t.is parser/t1 "<foo+bar/>") (t.is parser/t2 '(foo . bar)) (t.is parser/t3 '(--)) (t.is parser/t4 ':foo) (t.is parser/t5 ':foo) (t.is parser/t6 27) (t.is parser/t7 '(let ((x 3)) (let ((.x x)) (* .x .x .x)))))) (test "parser: escape hex literals" (lambda (t) (t.is (to.throw (read "\"\\x9\"")) #t) (t.is "\uFFFF" "￿") (t.is "\x9;\x9;" "\t\t") (t.is (repr '|foo bar|) "foo bar") (t.is '|\x9;\x9;| '|\t\t|))) (test "parser: character literals" (lambda (t) (let ((a #\A) (b #\xFF)) (t.is (and (string=? (type a) "character") (string=? (type b) "character")) true) (t.is #\Space #\space) (t.is #\SPACE #\SPace) (t.is (a.valueOf) "A") (t.is (b.valueOf) "\xFF;")))) (test "parser: quotes with literals" (lambda (t) (t.is ''#f '(quote #f)) (t.is ''#x10 '(quote #x10)) (t.is ''#o10 '(quote #o10)) (t.is ''#b10 '(quote #b10)) ;; binary (t.is ''#i#b10 '(quote #i#b10)) (t.is ''#b#i10 '(quote #b#i10)) (t.is ''#e#b10 '(quote #e#b10)) (t.is ''#b#e10 '(quote #b#e10)) ;; hex (t.is ''#i#x10A '(quote #i#x10A)) (t.is ''#x#i10A '(quote #x#i10A)) (t.is ''#e#x10A '(quote #e#x10A)) (t.is ''#x#e10A '(quote #x#e10A)) ;; octal (t.is ''#i#o10 '(quote #i#o10)) (t.is ''#o#i10 '(quote #o#i10)) (t.is ''#e#o10 '(quote #e#o10)) (t.is ''#o#e10 '(quote #o#e10)))) (test "parser: it should ignore comments" (lambda (t) (t.is (list #;(foo bar (quux)) 10 20) (list 10 20)) (t.is (list #;foo 10 20) (list 10 20)) (t.is (list 10 #;10+10i 20) (list 10 20)) (t.is (list 10 ;foo bar 20) (list 10 20)))) (test "parser: it should return literal space" (lambda (t) (let ((str (make-string 10 #\ ))) (t.is (string-length str) 10) (t.is (not (null? (--> str (match #/^\s{10}$/)))) #t)))) (test "parser: vector quoting" (lambda (t) (t.is `#(1 2 3) #(1 2 3)) (t.is `#(1 2 foo) #(1 2 foo)) (t.is '#(1 2 foo) #(1 2 foo)))) (test "parser: vector constants" (lambda (t) (define (v) #(1 2 3)) (t.is (eq? (v) (v)) true) (define (v) `#(1 2 3)) (t.is (eq? (v) (v)) true))) (test "parser: escaping in strings" (lambda (t) ;; testing #48 - when writing code with string in Scheme ;; we need to double escape to get slash (define code (lips.parse "(--> \"<title>hello-world<\\/title>\" (match #/<title>([^<]+)<\\/title>/) 1)")) (t.is (eval (. code 0)) "hello-world"))) (test "parse: datum labels" (lambda (t) (let ((x (list #0=(cons 1 2) #0#))) (set-car! (car x) 2) (t.is x '((2 . 2) (1 . 2)))) (let ((x (list '#0=(1 2 3) '#0#))) (t.is (eq? (car x) (cadr x)) true)) (let ((x (list #1='(1 2 3) #1#))) (t.is (eq? (car x) (cadr x)) true)) (let ((x '(#2=(1 2 3) #2#))) (t.is (eq? (car x) (cadr x)) true)) (let ((x '#3=(1 2 . #3#))) (t.is (eq? x (cddr x)) true)))) (test "tokenizer: should create tokens for simple list" (lambda (t) (t.is (lips.tokenize "(foo bar baz)") #("(" "foo" "bar" "baz" ")")))) (test "tokenizer: should create tokens for numbers string and regexes" (lambda (t) (t.is (lips.tokenize "(foo #/( \\/)/g \"bar baz\" 10 1.1 10e2 10+10i +inf.0+inf.0i +nan.0+nan.0i 1/2+1/2i)") #("(" "foo" "#/( \\/)/g" "\"bar baz\"" "10" "1.1" "10e2" "10+10i" "+inf.0+inf.0i" "+nan.0+nan.0i" "1/2+1/2i" ")")))) (test "tokenizer: should create token for alist" (lambda (t) (t.is (lips.tokenize "((foo . 10) (bar . 20) (baz . 30))") #("(" "(" "foo" "." "10" ")" "(" "bar" "." "20" ")" "(" "baz" "." "30" ")" ")")))) (test "tokenizer: should ignore comments" (lambda (t) (let ((code "(foo bar baz); (baz quux)")) (t.is (lips.tokenize code) #("(" "foo" "bar" "baz" ")"))))) (test "tokenizer: should handle semicolon in regexes and strings" (lambda (t) (let ((code "(\";()\" #/;;;/g baz); (baz quux)")) (t.is (lips.tokenize code) #("(" "\";()\"" "#/;;;/g" "baz" ")"))))) (test "tokenizer: with meta data" (lambda (t) (let* ((fs (require "fs")) (code (--> (fs.promises.readFile "./tests/stubs/macro.txt") (toString)))) (t.snapshot (lips.tokenize code true)))))
false
00981541ac17a9683f0e44aefabc608d563d6ada
d8fd100f7fedcf165381c5bfeac3b8b04baf5980
/lib/sdl2/lib/sdl2-internals/accessors/color.scm
35d79d8ad2d1af97be4dc1b57db2aaa9f7c5d4b7
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
shelt/flib
9c7b8228692ac6973c593a4bcd2d89ad96c1879c
5e2212d0c907297c0859758bc97a0a50f320172e
refs/heads/master
2021-01-10T04:18:23.371234
2016-01-23T05:24:45
2016-01-23T05:24:45
50,224,827
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,114
scm
color.scm
;; ;; chicken-sdl2: CHICKEN Scheme bindings to Simple DirectMedia Layer 2 ;; ;; Copyright © 2013, 2015 John Croisant. ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; - Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; - Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in ;; the documentation and/or other materials provided with the ;; distribution. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ;; COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, ;; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED ;; OF THE POSSIBILITY OF SUCH DAMAGE. (export color-r color-r-set! color-g color-g-set! color-b color-b-set! color-a color-a-set! make-color make-color* color-set! color->list color=? copy-color copy-color* colour-r colour-r-set! colour-g colour-g-set! colour-b colour-b-set! colour-a colour-a-set! make-colour make-colour* colour-set! colour->list colour=? copy-colour copy-colour*) (define-struct-field-accessors SDL_Color* color? ("r" type: Uint8 getter: color-r setter: color-r-set! guard: (Uint8-guard "sdl2:color field r")) ("g" type: Uint8 getter: color-g setter: color-g-set! guard: (Uint8-guard "sdl2:color field g")) ("b" type: Uint8 getter: color-b setter: color-b-set! guard: (Uint8-guard "sdl2:color field b")) ("a" type: Uint8 getter: color-a setter: color-a-set! guard: (Uint8-guard "sdl2:color field a"))) (define (make-color #!optional (r 0) (g 0) (b 0) (a 255)) (color-set! (alloc-color) r g b a)) (define (make-color* #!optional (r 0) (g 0) (b 0) (a 255)) (color-set! (alloc-color*) r g b a)) (define (color-set! color #!optional r g b a) (when r (color-r-set! color r)) (when g (color-g-set! color g)) (when b (color-b-set! color b)) (when a (color-a-set! color a)) color) (define (color->list color) (list (color-r color) (color-g color) (color-b color) (color-a color))) (define (color=? color1 color2) (define foreign-equals (foreign-lambda* bool ((SDL_Color* c1) (SDL_Color* c2)) "C_return(((c1->r == c2->r) && (c1->g == c2->g) && (c1->b == c2->b) && (c1->a == c2->a)) ? 1 : 0);")) (foreign-equals color1 color2)) (define %copy-color! (foreign-lambda* void ((SDL_Color* src) (SDL_Color* dest)) "*dest = *src;")) (define (copy-color color) (let ((dest (alloc-color))) (%copy-color! color dest) dest)) (define (copy-color* color) (let ((dest (alloc-color*))) (%copy-color! color dest) dest)) (define colour-r color-r) (define colour-g color-g) (define colour-b color-b) (define colour-a color-a) (define colour-r-set! color-r-set!) (define colour-g-set! color-g-set!) (define colour-b-set! color-b-set!) (define colour-a-set! color-a-set!) (define make-colour make-color) (define make-colour* make-color*) (define colour-set! color-set!) (define colour->list color->list) (define colour=? color=?) (define copy-colour copy-color) (define copy-colour* copy-color*)
false
1b991f8190616c916e101fa91136994aa0ab2630
ac2a3544b88444eabf12b68a9bce08941cd62581
/tests/unit-tests/02-flonum/#.scm
8e733c6ff0e95cfd5c281aa8cbfdc5a3973fec84
[ "Apache-2.0", "LGPL-2.1-only" ]
permissive
tomelam/gambit
2fd664cf6ea68859d4549fdda62d31a25b2d6c6f
d60fdeb136b2ed89b75da5bfa8011aa334b29020
refs/heads/master
2020-11-27T06:39:26.718179
2019-12-15T16:56:31
2019-12-15T16:56:31
229,341,552
1
0
Apache-2.0
2019-12-20T21:52:26
2019-12-20T21:52:26
null
UTF-8
Scheme
false
false
1,191
scm
#.scm
(include "../#.scm") (define-macro (macro-inexact-+pi) 3.141592653589793) (define-macro (macro-inexact--pi) -3.141592653589793) (define-macro (macro-inexact-+pi/2) 1.5707963267948966) (define-macro (macro-inexact--pi/2) -1.5707963267948966) (define-macro (macro-inexact-+pi/4) .7853981633974483) (define-macro (macro-inexact--pi/4) -.7853981633974483) (define-macro (macro-inexact-+3pi/4) 2.356194490192345) (define-macro (macro-inexact--3pi/4) -2.356194490192345) (define (isnan? x) (not (= x x))) ;;; We're going to compare two functional results, so we need a new ;;; epsilon (set! epsilon 1e-12) ;;; naive definitions of hyperbolic functions from ;;; Will Clinger's SRFI-144 implementation. (define (flsinh-144 x) (##fl/ (##fl- (##flexp x) (##flexp (##fl- x))) 2.0)) (define (flcosh-144 x) (##fl/ (##fl+ (##flexp x) (##flexp (##fl- x))) 2.0)) (define (fltanh-144 x) (##fl/ (flsinh-144 x) (flcosh-144 x))) (define (flasinh-144 x) (##fllog (##fl+ x (##flsqrt (##fl+ (##fl* x x) 1.0))))) (define (flacosh-144 x) (##fllog (##fl+ x (##flsqrt (##fl- (##fl* x x) 1.0))))) (define (flatanh-144 x) (##fl* 0.5 (##fllog (##fl/ (##fl+ 1.0 x) (##fl- 1.0 x)))))
false
189e7fe991d3087cb60f7964f2f42cdf0d9bbf38
7611e3c8bbb3c00b7dae44e008b7afb246be413a
/private/automaton-macro.ss
c6febcc7e69c1cc5a35e8447f4ba08b667a1688b
[]
no_license
dyoo/racket-ahocorasick
1d2637075df666154b486f7f8a1413f840a2d44f
3ba7966aa2de055aed84b15ac8eaec4253a709d2
refs/heads/master
2020-05-17T23:56:40.430836
2012-04-19T17:08:16
2012-04-19T17:08:16
3,212,690
3
0
null
null
null
null
UTF-8
Scheme
false
false
6,466
ss
automaton-macro.ss
#lang racket/base ;; Adaptation of Shriram Krishnamurthi's "Automata via Macros" ;; to work with Aho-Corasick finite state automata. ;; ;; ;; Adaptations: the descriptions of each state now contains: ;; ;; (outputs ...) ;; added ;; (<label> -> state) ;; same as the paper ;; (fail -> state) ;; added ;; (else -> state) ;; added ;; ;; Note that outputs, fail, and else, ->, : are treated as ;; keywords in the context of the automaton macro. (I've explicitely ;; done symbolic equality of those keywords to avoid lexical capture; ;; not sure if this is kosher since I'm still learning the macro system, ;; so this may change.) ;; ;; The automaton signature has also uglified... er... changed, ;; to take in a few more parameters: ;; ;; automaton: stream ;; (outputs ->)[output-callback] ;; (stream -> boolean)[empty?] ;; (stream -> element)[first] ;; (stream -> stream)[rest] -> ;; ;; so that this should be usable with any sequence type that provides empty?, first and rest. (provide automaton automaton-from-strings automaton-sexp-from-strings string-search) (require (for-syntax "ahocorasick.ss")) (require (for-syntax "automaton.ss")) (require (for-syntax racket/base)) (require (for-syntax syntax/stx)) (require (prefix-in list: racket/list)) ;; string-search: automaton string -> ;; (listof (string[output] number[start-pos] number[end-pos])) (define (string-search automaton s) (let* ((results '()) (n 0) (rest (lambda (lst) (set! n (+ n 1)) (list:rest lst)))) (automaton (string->list s) (lambda (outs) (for-each (lambda (o) (set! results (cons (list o (- n (string-length o)) n) results))) outs)) list:empty? list:first rest) (reverse results))) (define-syntax (automaton-sexp-from-strings stx) (syntax-case stx () [(automaton-sexp-from-strings strings ...) (let* ((strings (syntax->datum (syntax/loc stx (strings ...)))) (tree (make-from-strings strings))) (with-syntax ((sexp (stx-cdr (datum->syntax stx (ahocorasick->sexp tree))))) (syntax/loc stx (quote (automaton . sexp)))))])) (define-syntax (automaton-from-strings stx) (syntax-case stx () [(automaton-from-strings strings ...) (let* ((strings (syntax->datum (syntax/loc stx (strings ...)))) (tree (make-from-strings strings))) (with-syntax ((sexp (stx-cdr (datum->syntax stx (ahocorasick->sexp tree))))) (syntax/loc stx (automaton . sexp))))])) ;; symbolic-identifier=?: stx stx -> boolean ;; returns true if x and y are symbolically the same. (define-for-syntax (symbolic-identifier=? x y) (and (eq? (syntax-e x) (syntax-e y)))) (define-syntax (automaton stx) (syntax-case* stx (:) symbolic-identifier=? [(automaton init-state (state : response ...) ...) (syntax/loc stx (letrec ([state (process-outputs response ...)] ...) init-state))])) ;; FIXME: figure out how to incorporate units with this, so we don't have to thread so much state! (define-syntax (process-outputs stx) (syntax-case* stx (outputs) symbolic-identifier=? [(process-outputs (outputs (outs ...)) other-transitions ...) (syntax/loc stx (case-lambda [(stream output-callback empty? first rest from-fail?) (when (not from-fail?) (output-callback (list outs ...))) (process-transitions stream output-callback empty? first rest other-transitions ...)] [(stream output-callback empty? first rest) (process-transitions stream output-callback empty? first rest other-transitions ...)]))] [(process-outputs other-transitions ...) (syntax/loc stx (case-lambda [(stream output-callback empty? first rest from-fail?) (process-transitions stream output-callback empty? first rest other-transitions ...)] [(stream output-callback empty? first rest) (process-transitions stream output-callback empty? first rest other-transitions ...)]))])) (define-syntax (process-transitions stx) (syntax-case* stx (->) symbolic-identifier=? [(process-transitions stream output-callback empty? first rest (character -> state) ...) (syntax (if (empty? stream) #f (let ((peeked (first stream))) (process-transition-as-if-chain peeked stream output-callback empty? first rest (character ...) (state ...)))))])) ;; FIXME: clean this up. Way too ugly for words. (define-syntax (process-transition-as-if-chain stx) (syntax-case stx () [(process-transition-as-if-chain peeked stream output-callback empty? first rest (label) (state)) (cond ;; else case: consume, regardless of the current first stream element. [(symbolic-identifier=? (syntax label) (syntax else)) (syntax/loc stx (state (rest stream) output-callback empty? first rest #f))] ;; fail case: don't consume the stream, but follow the transition. [(symbolic-identifier=? (syntax label) (syntax fail)) (syntax/loc stx (state stream output-callback empty? first rest #t))])] ;; regular case: do the comparison, and either go along the goto or fail transitions ;; appropriately. [(process-transition-as-if-chain peeked stream output-callback empty? first rest (label rest-labels ...) (state rest-states ...)) (syntax/loc stx (if (equal? label peeked) (state (rest stream) output-callback empty? first rest #f) (process-transition-as-if-chain peeked stream output-callback empty? first rest (rest-labels ...) (rest-states ...))))]))
true
070d1aa073eedb77f0a867b62f43d79cfe25b99f
3629e5c33ebbc3acbaa660fb324c26357098147c
/examples/glbook/example7-2.scm
c9732e53411a05258cbe38fe6ec4d0fc49e9a37e
[ "LicenseRef-scancode-x11-sg", "MIT" ]
permissive
shirok/Gauche-gl
f31a62ce4c2d91795f972b668861a77626b02cb5
a569e3009314f81bc513827064e05869220c6a9d
refs/heads/master
2023-06-07T15:56:17.514969
2023-06-01T06:56:48
2023-06-01T06:56:48
9,487,174
4
5
MIT
2018-09-24T21:39:18
2013-04-17T02:13:32
C
UTF-8
Scheme
false
false
1,326
scm
example7-2.scm
;; Example 7-2 Using a Display list (use gl) (use gl.glut) (define *list-name* 0) (define (init) (set! *list-name* (gl-gen-lists 1)) (gl-new-list *list-name* GL_COMPILE) (gl-color 1.0 0.0 0.0) (gl-begin GL_TRIANGLES) (gl-vertex 0.0 0.0) (gl-vertex 1.0 0.0) (gl-vertex 0.0 1.0) (gl-end) (gl-translate 1.5 0.0 0.0) (gl-end-list) (gl-shade-model GL_FLAT) ) (define (draw-line) (gl-begin GL_LINES) (gl-vertex 0.0 0.5) (gl-vertex 15.0 0.5) (gl-end)) (define (disp) (gl-load-identity) (gl-clear GL_COLOR_BUFFER_BIT) (gl-color 0.0 1.0 0.0) (dotimes (i 10) (gl-call-list *list-name*)) (draw-line) (gl-flush) ) (define (reshape w h) (gl-viewport 0 0 w h) (gl-matrix-mode GL_PROJECTION) (gl-load-identity) (if (<= w h) (glu-ortho-2d 0.0 1.0 (* -0.5 (/ h w)) (* 1.5 (/ h w))) (glu-ortho-2d 0.0 (* 2.0 (/ w h)) -0.5 1.5)) (gl-matrix-mode GL_MODELVIEW) (gl-load-identity) ) (define (keyboard key x y) (cond ((= key 27) ;ESC (exit 0))) ) (define (main args) (glut-init args) (glut-init-display-mode (logior GLUT_SINGLE GLUT_RGB)) (glut-init-window-size 650 50) (glut-create-window (car args)) (init) (glut-reshape-func reshape) (glut-keyboard-func keyboard) (glut-display-func disp) (glut-main-loop) 0)
false
eba5aa0e892272fb5f0f32c35f3715e8ce3b3bde
eef5f68873f7d5658c7c500846ce7752a6f45f69
/spheres/net/mime.sld
6157f95e5a1d1b8c6aa54138dece576b0a6cd9fc
[ "MIT" ]
permissive
alvatar/spheres
c0601a157ddce270c06b7b58473b20b7417a08d9
568836f234a469ef70c69f4a2d9b56d41c3fc5bd
refs/heads/master
2021-06-01T15:59:32.277602
2021-03-18T21:21:43
2021-03-18T21:21:43
25,094,121
13
3
null
null
null
null
UTF-8
Scheme
false
false
1,742
sld
mime.sld
;;!!! Decode and encode data using the MIME format. ;; .author Marc Feeley, 2006-2007 ;; .author Alvaro Castro-Castilla, 2015 ;; .license lgpl/v2.1 ;; Copyright (c) 2006-2007 by Marc Feeley, All Rights Reserved. ;; ;; ;; See the following RFCs: ;; ;; RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One: ;; Format of Internet Message Bodies ;; ;; RFC 2046 - Multipurpose Internet Mail Extensions (MIME) Part Two: ;; Media Types ;; ;; RFC 2047 - MIME (Multipurpose Internet Mail Extensions) Part Three: ;; Message Header Extensions for Non-ASCII Text ;; ;; RFC 2048 - Multipurpose Internet Mail Extensions (MIME) Part Four: ;; Registration Procedures ;; ;; RFC 2049 - Multipurpose Internet Mail Extensions (MIME) Part Five: ;; Conformance Criteria and Examples ;; ;; RFC 2822 - Internet Message Format (define-library (spheres/net mime) (export mime-generate-boundary ; We use this one in Content-ID generation in other modules so important to export. mime-format-header ; This list of exports is to be revised, some may not make sense to export. TODO mime-parse-header mime-encode-x-www-form-urlencoded mime-decode-x-www-form-urlencoded mime-decode-text mime-encode-text mime-encode-application mime-decode-application mime-encode-multipart mime-decode-multipart-with-boundary mime-encode mime-decode mime-string->content-type mime-eol-str content-type-header-value-to-string mime-text-default-content-type) (import (spheres/algorithm u8vector) (spheres/string u8vector) (spheres/dataenc base64)) (include "mime.scm"))
false
45bc2b429966807ea94a783dfe45f2f389bf41b0
d7a69a0e464473bf2699b8370682080c18c6ff93
/test/srfi.scm
7f232b43e6b40c6f2f62ee22d262e89b6ad90ab1
[ "MIT" ]
permissive
leftmike/foment
08ecd44cd5327f00d0fc32d197e0903dd3d2f123
6089c3c9e762875f619ef382d27943819bbe002b
refs/heads/master
2022-09-19T00:53:49.568819
2022-09-07T04:46:36
2022-09-07T04:46:36
52,575,413
72
9
MIT
2022-08-28T15:33:02
2016-02-26T03:21:58
C++
UTF-8
Scheme
false
false
175,669
scm
srfi.scm
;;; ;;; SRFIs ;;; ;; ;; ---- SRFI 112: Environment Inquiry ---- ;; (import (srfi 112)) (check-equal #t (or (string? (implementation-name)) (eq? (implementation-name) #f))) (check-error (assertion-violation implementation-name) (implementation-name 1)) (check-equal #t (or (string? (implementation-version)) (eq? (implementation-version) #f))) (check-error (assertion-violation implementation-version) (implementation-version 1)) (check-equal #t (or (string? (cpu-architecture)) (eq? (cpu-architecture) #f))) (check-error (assertion-violation cpu-architecture) (cpu-architecture 1)) (check-equal #t (or (string? (machine-name)) (eq? (machine-name) #f))) (check-error (assertion-violation machine-name) (machine-name 1)) (check-equal #t (or (string? (os-name)) (eq? (os-name) #f))) (check-error (assertion-violation os-name) (os-name 1)) (check-equal #t (or (string? (os-version)) (eq? (os-version) #f))) (check-error (assertion-violation os-version) (os-version 1)) ;; ;; ---- SRFI 111: Boxes ---- ;; (import (scheme box)) (check-equal 10 (unbox (box 10))) (check-equal #t (equal? (box 20) (box 20))) (check-equal #f (eq? (box 30) (box 30))) (check-error (assertion-violation box) (box)) (check-error (assertion-violation box) (box 1 2)) (check-equal #t (box? (box 10))) (check-equal #f (box? 10)) (check-equal #f (box? #(10))) (check-equal #f (box? (cons 1 2))) (check-error (assertion-violation box?) (box?)) (check-error (assertion-violation box?) (box? 1 2)) (check-equal 10 (unbox (box 10))) (check-error (assertion-violation unbox) (unbox)) (check-error (assertion-violation unbox) (unbox (box 1) 2)) (check-error (assertion-violation unbox) (unbox (cons 1 2))) (define b (box 10)) (check-equal 10 (unbox b)) (set-box! b 20) (check-equal 20 (unbox b)) (check-equal #t (equal? b (box 20))) (check-equal #f (eq? b (box 20))) (check-error (assertion-violation set-box!) (set-box! b)) (check-error (assertion-violation set-box!) (set-box! b 2 3)) (check-error (assertion-violation set-box!) (set-box! (cons 1 2) 2)) ;; ;; ---- SRFI 60: Integers As Bits ---- ;; (import (srfi 60)) (check-equal "1000" (number->string (bitwise-and #b1100 #b1010) 2)) (check-equal -1 (bitwise-and)) (check-equal 12345 (bitwise-and 12345)) (check-equal 4145 (bitwise-and 12345 54321)) (check-equal 4145 (bitwise-and 54321 12345)) (check-equal 49 (bitwise-and 12345 54321 10101010101)) (check-equal 16 (bitwise-and 12345 12345678901234567890123456789012345678901234567890)) (check-equal 39235487929048208904815248 (bitwise-and 12345678901234567890123456789012345678901234567890 987654321987654321987654321)) (check-error (assertion-violation bitwise-and) (bitwise-and 1234 56.78)) (check-error (assertion-violation bitwise-and) (bitwise-and 1234 56/78)) (check-error (assertion-violation bitwise-and) (bitwise-and 12.34 5678)) (check-error (assertion-violation bitwise-and) (bitwise-and 12/34 5678)) (check-equal 0 (bitwise-ior)) (check-equal 12345 (bitwise-ior 12345)) (check-equal 62521( bitwise-ior 12345 54321)) (check-equal 62521( bitwise-ior 54321 12345)) (check-equal 1014205 (bitwise-ior 12345 1010101)) (check-equal 1014205 (bitwise-ior 1010101 12345)) (check-equal 123456789123456789123456789123456789123456789123465021 (bitwise-ior 12345 123456789123456789123456789123456789123456789123456789)) (check-equal 123456789123456789123456789123456789123456789123465021 (bitwise-ior 123456789123456789123456789123456789123456789123456789 12345)) (check-equal 1234123412341276660008185256654991575253956765272574 (bitwise-ior 1234123412341234123412341234123412341234123412341234 5678567856785678567856785678567856785678)) (check-error (assertion-violation bitwise-ior) (bitwise-ior 1234 56.78)) (check-error (assertion-violation bitwise-ior) (bitwise-ior 1234 56/78)) (check-error (assertion-violation bitwise-ior) (bitwise-ior 12.34 5678)) (check-error (assertion-violation bitwise-ior) (bitwise-ior 12/34 5678)) (check-equal 0 (bitwise-xor)) (check-equal 12345 (bitwise-xor 12345)) (check-equal 58376 (bitwise-xor 12345 54321)) (check-equal 58376 (bitwise-xor 54321 12345)) (check-equal 10 (bitwise-xor #b10001 #b11011)) (check-equal 678967896789678967896789678967896789678967896789678967884524 (bitwise-xor 12345 678967896789678967896789678967896789678967896789678967896789)) (check-equal 7088580165427581030224296127424816853124929578319024555 (bitwise-xor 1234512345123451234512345123451234512345123451234512345 6789067890678906789067890678906789067890678906789067890)) (check-error (assertion-violation bitwise-xor) (bitwise-xor 1234 56.78)) (check-error (assertion-violation bitwise-xor) (bitwise-xor 1234 56/78)) (check-error (assertion-violation bitwise-xor) (bitwise-xor 12.34 5678)) (check-error (assertion-violation bitwise-xor) (bitwise-xor 12/34 5678)) (check-equal -12346 (bitwise-not 12345)) (check-equal -6789067890678906789067890678906789067890678906789067890678906789067891 (bitwise-not 6789067890678906789067890678906789067890678906789067890678906789067890)) (check-error (assertion-violation bitwise-not) (bitwise-not 12.34)) (check-error (assertion-violation bitwise-not) (bitwise-not 12/34)) (check-error (assertion-violation bitwise-not) (bitwise-not)) (check-error (assertion-violation bitwise-not) (bitwise-not 12 34)) (check-equal #f (any-bits-set? #b0100 #b1011)) (check-equal #t (any-bits-set? #b0100 #b0111)) (check-equal 4 (bit-count #b10101010)) (check-equal 0 (bit-count 0)) (check-equal 1 (bit-count -2)) (check-error (assertion-violation bit-count) (bit-count)) (check-error (assertion-violation bit-count) (bit-count 12 34)) (check-error (assertion-violation bit-count) (bit-count 12.34)) (check-error (assertion-violation bit-count) (bit-count 12/34)) (check-equal 8 (integer-length #b10101010)) (check-equal 0 (integer-length 0)) (check-equal 4 (integer-length #b1111)) (check-error (assertion-violation integer-length) (integer-length)) (check-error (assertion-violation integer-length) (integer-length 12 34)) (check-error (assertion-violation integer-length) (integer-length 12.34)) (check-error (assertion-violation integer-length) (integer-length 12/34)) (check-equal -1 (first-set-bit 0)) (check-equal -1 (first-set-bit 0)) (check-equal 0 (first-set-bit -1)) (check-equal 0 (first-set-bit 1)) (check-equal 1 (first-set-bit -2)) (check-equal 1 (first-set-bit 2)) (check-equal 0 (first-set-bit -3)) (check-equal 0 (first-set-bit 3)) (check-equal 2 (first-set-bit -4)) (check-equal 2 (first-set-bit 4)) (check-equal 0 (first-set-bit -5)) (check-equal 0 (first-set-bit 5)) (check-equal 1 (first-set-bit -6)) (check-equal 1 (first-set-bit 6)) (check-equal 0 (first-set-bit -7)) (check-equal 0 (first-set-bit 7)) (check-equal 3 (first-set-bit -8)) (check-equal 3 (first-set-bit 8)) (check-equal 0 (first-set-bit -9)) (check-equal 0 (first-set-bit 9)) (check-equal 1 (first-set-bit -10)) (check-equal 1 (first-set-bit 10)) (check-equal 0 (first-set-bit -11)) (check-equal 0 (first-set-bit 11)) (check-equal 2 (first-set-bit -12)) (check-equal 2 (first-set-bit 12)) (check-equal 0 (first-set-bit -13)) (check-equal 0 (first-set-bit 13)) (check-equal 1 (first-set-bit -14)) (check-equal 1 (first-set-bit 14)) (check-equal 0 (first-set-bit -15)) (check-equal 0 (first-set-bit 15)) (check-equal 4 (first-set-bit -16)) (check-equal 4 (first-set-bit 16)) (check-equal 123 (first-set-bit (arithmetic-shift 1 123))) (check-equal 123 (first-set-bit (arithmetic-shift -1 123))) (check-error (assertion-violation first-set-bit) (first-set-bit)) (check-error (assertion-violation first-set-bit) (first-set-bit 12 34)) (check-error (assertion-violation bitwise-and) (first-set-bit 12.34)) (check-error (assertion-violation bitwise-and) (first-set-bit 12/34)) (check-equal #t (logbit? 0 #b1101)) (check-equal #f (logbit? 1 #b1101)) (check-equal #t (logbit? 2 #b1101)) (check-equal #t (logbit? 3 #b1101)) (check-equal #f (logbit? 4 #b1101)) (check-equal "1" (number->string (copy-bit 0 0 #t) 2)) (check-equal "100" (number->string (copy-bit 2 0 #t) 2)) (check-equal "1011" (number->string (copy-bit 2 #b1111 #f) 2)) (check-equal "1010" (number->string (bit-field #b1101101010 0 4) 2)) (check-equal "10110" (number->string (bit-field #b1101101010 4 9) 2)) (check-equal "1101100000" (number->string (copy-bit-field #b1101101010 0 0 4) 2)) (check-equal "1101101111" (number->string (copy-bit-field #b1101101010 -1 0 4) 2)) (check-equal "110100111110000" (number->string (copy-bit-field #b110100100010000 -1 5 9) 2)) (check-equal "1000" (number->string (arithmetic-shift #b1 3) 2)) (check-equal "101" (number->string (arithmetic-shift #b1010 -1) 2)) (check-equal "111010110111100110100010101" (number->string (arithmetic-shift 123456789 0) 2)) (check-equal "11101011011110011010001010100000" (number->string (arithmetic-shift 123456789 5) 2)) (check-equal "-11101011011110011010001010100000" (number->string (arithmetic-shift -123456789 5) 2)) (check-equal "1110101101111001101000101010000000000000" (number->string (arithmetic-shift 123456789 13) 2)) (check-equal "-1110101101111001101000101100010000000" (number->string (arithmetic-shift -987654321 7) 2)) (check-equal "1111000100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" (number->string (arithmetic-shift 123456 101) 2)) (check-equal "-1111000100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" (number->string (arithmetic-shift -123456 101) 2)) (check-equal "1000011100100111111101100011011010011010101011111000001111001010000101010000001001100111010001111010111110001100011111110001100101101100111000111111000010101101001000000000000000000000000" (number->string (arithmetic-shift 12345678901234567890123456789012345678901234567890 23) 2)) (check-equal "-10000111001001111111011000110110100110101010111110000011110010100001010100000010011001110100011110101111100011000111111100011001011011001110001111110000101011010010000000000000000000000000000" (number->string (arithmetic-shift -12345678901234567890123456789012345678901234567890 27) 2)) (check-equal "1110101101111001101000101" (number->string (arithmetic-shift 123456789 -2) 2)) (check-equal "-1110101101111001101000110" (number->string (arithmetic-shift -123456789 -2) 2)) (check-equal "1110101101" (number->string (arithmetic-shift 123456789 -17) 2)) (check-equal "0" (number->string (arithmetic-shift 123456789 -101) 2)) (check-equal "-1" (number->string (arithmetic-shift -123456789 -101) 2)) (check-equal "1001110101010111101010000010011100100101111000001111001100010000101110011111110000111101001000011011110001100001101111011010010011100100011001100111111110001100101101100111000111111000" (number->string (arithmetic-shift 123456789012345678901234567890123456789012345678901234567890 -13) 2)) (check-equal "-1001110101010111101010000010011100100101111000001111001100010000101110011111110000111101001000011011110001100001101111011010010011100100011001100111111110001100101101100111000111111001" (number->string (arithmetic-shift -123456789012345678901234567890123456789012345678901234567890 -13) 2)) (check-equal "100111010101011110101000001001110010010111100000111100110001000010111001111111000011110100100001" (number->string (arithmetic-shift 123456789012345678901234567890123456789012345678901234567890 -101) 2)) (check-equal "-100111010101011110101000001001110010010111100000111100110001000010111001111111000011110100100010" (number->string (arithmetic-shift -123456789012345678901234567890123456789012345678901234567890 -101) 2)) (check-equal "1001110101010111" (number->string (arithmetic-shift 123456789012345678901234567890123456789012345678901234567890 -181) 2)) (check-equal "-1001110101011000" (number->string (arithmetic-shift -123456789012345678901234567890123456789012345678901234567890 -181) 2)) (check-equal "0" (number->string (arithmetic-shift 123456789012345678901234567890123456789012345678901234567890 -201) 2)) (check-equal "-1" (number->string (arithmetic-shift -123456789012345678901234567890123456789012345678901234567890 -201) 2)) (check-error (assertion-violation arithmetic-shift) (arithmetic-shift)) (check-error (assertion-violation arithmetic-shift) (arithmetic-shift 12)) (check-error (assertion-violation arithmetic-shift) (arithmetic-shift 12 34.56)) (check-error (assertion-violation arithmetic-shift) (arithmetic-shift 12 34/56)) (check-error (assertion-violation arithmetic-shift) (arithmetic-shift 12.34 56)) (check-error (assertion-violation arithmetic-shift) (arithmetic-shift 12/34 56)) (check-equal "10" (number->string (rotate-bit-field #b0100 3 0 4) 2)) (check-equal "10" (number->string (rotate-bit-field #b0100 -1 0 4) 2)) (check-equal "110100010010000" (number->string (rotate-bit-field #b110100100010000 -1 5 9) 2)) (check-equal "110100000110000" (number->string (rotate-bit-field #b110100100010000 1 5 9) 2)) (check-equal "e5" (number->string (reverse-bit-field #xa7 0 8) 16)) ;; ;; ---- SRFI 1: List Library ---- ;; (import (scheme list)) (check-equal (a) (cons 'a '())) (check-equal ((a) b c d) (cons '(a) '(b c d))) (check-equal ("a" b c) (cons "a" '(b c))) (check-equal (a . 3) (cons 'a 3)) (check-equal ((a b) . c) (cons '(a b) 'c)) (check-equal (a 7 c) (list 'a (+ 3 4) 'c)) (check-equal () (list)) (check-equal (a . b) (xcons 'b 'a)) (check-equal (1 2 3 . 4) (cons* 1 2 3 4)) (check-equal 1 (cons* 1)) (check-equal (c c c c) (make-list 4 'c)) (check-equal () (make-list 0)) (check-equal 10 (length (make-list 10))) (check-equal (0 1 2 3) (list-tabulate 4 values)) (check-equal () (list-tabulate 0 values)) (define cl (circular-list 'a 'b 'c)) (check-equal #t (eq? cl (cdddr cl))) (check-equal (a b a b a b a b) (take (circular-list 'a 'b) 8)) (check-equal #f (list? (circular-list 1 2 3 4 5))) (check-equal (0 1 2 3 4 5) (iota 6)) (check-equal (0 -0.1 -0.2 -0.3 -0.4) (iota 5 0 -0.1)) (check-equal #t (proper-list? '(a b c))) (check-equal #t (proper-list? '())) (check-equal #f (proper-list? '(a b . c))) (check-equal #f (proper-list? 'a)) (check-equal #f (proper-list? (circular-list 1 2 3 4 5 6))) (check-equal #f (circular-list? '(a b c))) (check-equal #f (circular-list? '())) (check-equal #f (circular-list? '(a b . c))) (check-equal #f (circular-list? 'a)) (check-equal #t (circular-list? (circular-list 1 2 3 4 5 6))) (check-equal #t (circular-list? (cons 0 (circular-list 1 2 3 4 5 6)))) (check-equal #f (dotted-list? '(a b c))) (check-equal #f (dotted-list? '())) (check-equal #t (dotted-list? '(a b . c))) (check-equal #t (dotted-list? 'a)) (check-equal #f (dotted-list? (circular-list 1 2 3 4 5 6))) (check-equal #t (not-pair? 'a)) (check-equal #t (not-pair? #())) (check-equal #f (not-pair? (cons 1 2))) (check-equal #t (not-pair? '())) (check-equal #f (null-list? (cons 1 2))) (check-equal #t (null-list? '())) (check-equal #t (list= eq? '(1 2 3 4) '(1 2 3 4))) (check-equal #f (list= eq? '(1 2 3) '(1 2 3 4))) (check-equal #f (list= eq? '(1 2 3 4) '(1 2 3))) (check-equal #f (list= eq? '(1 2 3 4) '(1 2 3 5))) (check-equal #t (list= eq? '(1 2 3 4) '(1 2 3 4) '(1 2 3 4))) (check-equal #f (list= eq? '(1 2 3) '(1 2 3 4) '(1 2 3 4))) (check-equal #f (list= eq? '(1 2 3 4) '(1 2 3) '(1 2 3 4))) (check-equal #f (list= eq? '(1 2 3 4) '(1 2 3 4) '(1 2 3))) (check-equal #f (list= eq? '(1 2 3 4) '(1 2 3 4) '(1 2 3 5))) (check-equal #f (list= eq? '(1 2 3 4) '(1 2 4) '(1 2 3 4))) (check-equal #f (list= eq? '(1 2 6 4) '(1 2 3 4) '(1 2 3 4))) (check-equal 1 (first '(1 2 3 4 5 6 7 8 9 10))) (check-equal 2 (second '(1 2 3 4 5 6 7 8 9 10))) (check-equal 3 (third '(1 2 3 4 5 6 7 8 9 10))) (check-equal 4 (fourth '(1 2 3 4 5 6 7 8 9 10))) (check-equal 5 (fifth '(1 2 3 4 5 6 7 8 9 10))) (check-equal 6 (sixth '(1 2 3 4 5 6 7 8 9 10))) (check-equal 7 (seventh '(1 2 3 4 5 6 7 8 9 10))) (check-equal 8 (eighth '(1 2 3 4 5 6 7 8 9 10))) (check-equal 9 (ninth '(1 2 3 4 5 6 7 8 9 10))) (check-equal 10 (tenth '(1 2 3 4 5 6 7 8 9 10))) (check-equal (1 2 3) (take '(1 2 3 4 5 6) 3)) (check-equal () (take '(1 2 3 4 5 6) 0)) (check-equal (4 5 6) (drop '(1 2 3 4 5 6) 3)) (check-equal () (drop '(1 2 3 4 5 6) 6)) (check-equal (d e) (take-right '(a b c d e) 2)) (check-equal (2 3 . d) (take-right '(1 2 3 . d) 2)) (check-equal d (take-right '(1 2 3 . d) 0)) (check-equal (a b c) (drop-right '(a b c d e) 2)) (check-equal (1) (drop-right '(1 2 3 . d) 2)) (check-equal (1 2 3) (drop-right '(1 2 3 . d) 0)) (check-equal (1 3) (take! (circular-list 1 3 5) 8)) (check-equal (1 2 3) (take! '(1 2 3 4 5 6) 3)) (check-equal () (take! '(1 2 3 4 5 6) 0)) (check-equal (a b c) (drop-right! '(a b c d e) 2)) (check-equal (1) (drop-right! '(1 2 3 . d) 2)) (check-equal (1 2 3) (drop-right! '(1 2 3 . d) 0)) (check-equal ((1 2 3) (4 5 6 7 8)) (let-values (((pre suf) (split-at '(1 2 3 4 5 6 7 8) 3))) (list pre suf))) (check-equal (() (1 2 3 4 5 6 7 8)) (let-values (((pre suf) (split-at '(1 2 3 4 5 6 7 8) 0))) (list pre suf))) (check-equal ((1 2 3 4 5 6 7 8) ()) (let-values (((pre suf) (split-at '(1 2 3 4 5 6 7 8) 8))) (list pre suf))) (check-equal ((1 2 3) (4 5 6 7 8)) (let-values (((pre suf) (split-at! '(1 2 3 4 5 6 7 8) 3))) (list pre suf))) (check-equal (() (1 2 3 4 5 6 7 8)) (let-values (((pre suf) (split-at! '(1 2 3 4 5 6 7 8) 0))) (list pre suf))) (check-equal ((1 2 3 4 5 6 7 8) ()) (let-values (((pre suf) (split-at! '(1 2 3 4 5 6 7 8) 8))) (list pre suf))) (check-equal c (last '(a b c))) (check-equal (c) (last-pair '(a b c))) (check-equal (x y) (append '(x) '(y))) (check-equal (a b c d) (append '(a) '(b c d))) (check-equal (a b c d) (append '(a) '() '(b c d))) (check-equal (a b c d) (append '() '(a) '() '(b c d) '())) (check-equal (a (b) (c)) (append '(a (b)) '((c)))) (check-equal (a b c . d) (append '(a b) '(c . d))) (check-equal a (append '() 'a)) (check-equal (x y) (append '(x y))) (check-equal () (append)) (check-equal (x y) (append! '(x) '(y))) (check-equal (a b c d) (append! '(a) '(b c d))) (check-equal (a b c d) (append! '(a) '() '(b c d))) (check-equal (a b c d) (append! '() '(a) '() '(b c d) '())) (check-equal (a (b) (c)) (append! '(a (b)) '((c)))) (check-equal (a b c . d) (append! '(a b) '(c . d))) (check-equal a (append! '() 'a)) (check-equal (x y) (append! '(x y))) (check-equal () (append!)) (check-equal (x y) (concatenate '((x) (y)))) (check-equal (a b c d) (concatenate '((a) (b c d)))) (check-equal (a b c d) (concatenate '((a) () (b c d)))) (check-equal (a b c d) (concatenate '(() (a) () (b c d) ()))) (check-equal (a (b) (c)) (concatenate '((a (b)) ((c))))) (check-equal (a b c . d) (concatenate '((a b) (c . d)))) (check-equal a (concatenate '(() a))) (check-equal (x y) (concatenate '((x y)))) (check-equal () (concatenate '())) (check-equal (x y) (concatenate! '((x) (y)))) (check-equal (a b c d) (concatenate! '((a) (b c d)))) (check-equal (a b c d) (concatenate! '((a) () (b c d)))) (check-equal (a b c d) (concatenate! '(() (a) () (b c d) ()))) (check-equal (a (b) (c)) (concatenate! '((a (b)) ((c))))) (check-equal (a b c . d) (concatenate! '((a b) (c . d)))) (check-equal a (concatenate! '(() a))) (check-equal (x y) (concatenate! '((x y)))) (check-equal () (concatenate! '())) (check-equal (c b a) (reverse '(a b c))) (check-equal ((e (f)) d (b c) a) (reverse '(a (b c) d (e (f))))) (check-equal (c b a) (reverse! '(a b c))) (check-equal ((e (f)) d (b c) a) (reverse! '(a (b c) d (e (f))))) (check-equal (3 2 1 4 5) (append-reverse '(1 2 3) '(4 5))) (check-equal (3 2 1) (append-reverse '(1 2 3) '())) (check-equal (4 5) (append-reverse '() '(4 5))) (check-equal (3 2 1 4 5) (append-reverse! '(1 2 3) '(4 5))) (check-equal (3 2 1) (append-reverse! '(1 2 3) '())) (check-equal (4 5) (append-reverse! '() '(4 5))) (check-equal ((one 1 odd) (two 2 even) (three 3 odd)) (zip '(one two three) '(1 2 3) '(odd even odd even odd even odd even))) (check-equal ((1) (2) (3)) (zip '(1 2 3))) (check-equal ((3 #f) (1 #t) (4 #f) (1 #t)) (zip '(3 1 4 1) (circular-list #f #t))) (check-equal (1 2 3) (unzip1 '((1 2 3) (2 3 4) (3 4 5)))) (check-equal ((1 2 3) (one two three)) (let-values (((lst1 lst2) (unzip2 '((1 one) (2 two) (3 three))))) (list lst1 lst2))) (check-equal (1 2 3 4) (unzip1 '((1 one a #\a "a") (2 two b #\b "b") (3 three c #\c "c") (4 four d #\d "d")))) (check-equal ((1 2 3 4) (one two three four)) (let-values (((lst1 lst2) (unzip2 '((1 one a #\a "a") (2 two b #\b "b") (3 three c #\c "c") (4 four d #\d "d"))))) (list lst1 lst2))) (check-equal ((1 2 3 4) (one two three four) (a b c d)) (let-values (((lst1 lst2 lst3) (unzip3 '((1 one a #\a "a") (2 two b #\b "b") (3 three c #\c "c") (4 four d #\d "d"))))) (list lst1 lst2 lst3))) (check-equal ((1 2 3 4) (one two three four) (a b c d) (#\a #\b #\c #\d)) (let-values (((lst1 lst2 lst3 lst4) (unzip4 '((1 one a #\a "a") (2 two b #\b "b") (3 three c #\c "c") (4 four d #\d "d"))))) (list lst1 lst2 lst3 lst4))) (check-equal ((1 2 3 4) (one two three four) (a b c d) (#\a #\b #\c #\d) ("a" "b" "c" "d")) (let-values (((lst1 lst2 lst3 lst4 lst5) (unzip5 '((1 one a #\a "a") (2 two b #\b "b") (3 three c #\c "c") (4 four d #\d "d"))))) (list lst1 lst2 lst3 lst4 lst5))) (check-equal 3 (count even? '(3 1 4 1 5 9 2 5 6))) (check-equal 3 (count < '(1 2 4 8) '(2 4 6 8 10 12 14 16))) (check-equal 2 (count < '(3 1 4 1) (circular-list 1 10))) (check-equal 10 (fold + 0 '(1 2 3 4))) (check-equal (5 4 3 2 1) (fold cons '() '(1 2 3 4 5))) (check-equal 3 (fold (lambda (x count) (if (symbol? x) (+ count 1) count)) 0 '(a "a" #\a 1 2 3 (b c) d #(e f g) h))) (check-equal 10 (fold (lambda (s max-len) (max max-len (string-length s))) 0 '("abc" "def" "1234567890" "123456789" "wxyz"))) (check-equal (c 3 b 2 a 1) (fold cons* '() '(a b c) '(1 2 3 4 5))) (check-equal (10 8 6) (fold (lambda (frst snd val) (cons (+ frst snd) val)) '() '(1 2 3 4) '(5 6 7))) (check-equal (1 3 5 7) (fold-right (lambda (n lst) (if (odd? n) (cons n lst) lst)) '() '(1 2 3 4 5 6 7 8))) (check-equal (a 1 b 2 c 3) (fold-right cons* '() '(a b c) '(1 2 3 4 5))) (check-equal (6 8 10) (fold-right (lambda (frst snd val) (cons (+ frst snd) val)) '() '(1 2 3 4) '(5 6 7))) (check-equal (5 4 3 2 1) (pair-fold (lambda (pair tail) (set-cdr! pair tail) pair) '() '(1 2 3 4 5))) (check-equal 10 (pair-fold (lambda (s max-len) (max max-len (string-length (car s)))) 0 '("abc" "def" "1234567890" "123456789" "wxyz"))) (check-equal (10 8 6) (pair-fold (lambda (frst snd val) (cons (+ (car frst) (car snd)) val)) '() '(1 2 3 4) '(5 6 7))) (check-equal (1 3 5 7) (pair-fold-right (lambda (n lst) (if (odd? (car n)) (cons (car n) lst) lst)) '() '(1 2 3 4 5 6 7 8))) (check-equal (6 8 10) (pair-fold-right (lambda (frst snd val) (cons (+ (car frst) (car snd)) val)) '() '(1 2 3 4) '(5 6 7))) (check-equal 10 (reduce max 0 '(8 4 3 -5 10 9))) (check-equal (1 2 3 4 5 6 7 8 9) (reduce-right append '() '((1 2 3) (4 5) (6 7 8) (9)))) (check-equal (1 4 9 16 25 36 49 64 81 100) (unfold (lambda (x) (> x 10)) (lambda (x) (* x x)) (lambda (x) (+ x 1)) 1)) (check-equal (1 2 3 4 5) (unfold null-list? car cdr '(1 2 3 4 5))) (check-equal (1 2 3 4 5) (unfold null-list? car cdr '(1 2) (lambda (x) '(3 4 5)))) (check-equal (1 4 9 16 25 36 49 64 81 100) (unfold-right zero? (lambda (x) (* x x)) (lambda (x) (- x 1)) 10)) (check-equal (5 4 3 2 1) (unfold-right null-list? car cdr '(1 2 3 4 5))) (check-equal (3 2 1 4 5) (unfold-right null-list? car cdr '(1 2 3) '(4 5))) (check-equal (3 2 1) (unfold-right null-list? car cdr '(1 2 3) '())) (check-equal (4 5) (unfold-right null-list? car cdr '() '(4 5))) (check-equal (b e h) (map cadr '((a b) (d e) (g h)))) (check-equal (1 4 27 256 3125) (map (lambda (n) (expt n n)) '(1 2 3 4 5))) (check-equal (5 7 9) (map + '(1 2 3) '(4 5 6))) (check-equal #t (let ((ret (let ((count 0)) (map (lambda (ignored) (set! count (+ count 1)) count) '(a b))))) (or (equal? ret '(1 2)) (equal? ret '(2 1))))) (check-equal (4 1 5 1) (map + '(3 1 4 1) (circular-list 1 0))) (check-equal #(0 1 4 9 16) (let ((v (make-vector 5))) (for-each (lambda (i) (vector-set! v i (* i i))) '(0 1 2 3 4)) v)) (check-equal #(1 1 3 3 5) (let ((v (make-vector 5))) (for-each (lambda (a b) (vector-set! v a (+ a b))) '(0 1 2 3 4) (circular-list 1 0)) v)) (check-equal (1 -1 3 -3 8 -8) (append-map (lambda (x) (list x (- x))) '(1 3 8))) (check-equal (1 0 2 1 3 0 4 1 5 0) (append-map (lambda (x y) (list x y)) '(1 2 3 4 5) (circular-list 0 1))) (check-equal (1 -1 3 -3 8 -8) (append-map! (lambda (x) (list x (- x))) '(1 3 8))) (check-equal (1 0 2 1 3 0 4 1 5 0) (append-map! (lambda (x y) (list x y)) '(1 2 3 4 5) (circular-list 0 1))) (check-equal (b e h) (map! cadr '((a b) (d e) (g h)))) (check-equal (1 4 27 256 3125) (map! (lambda (n) (expt n n)) '(1 2 3 4 5))) (check-equal (5 7 9) (map! + '(1 2 3) '(4 5 6))) (check-equal #t (let ((ret (let ((count 0)) (map! (lambda (ignored) (set! count (+ count 1)) count) '(a b))))) (or (equal? ret '(1 2)) (equal? ret '(2 1))))) (check-equal (4 1 5 1) (map! + '(3 1 4 1) (circular-list 1 0))) (check-equal (b e h) (map-in-order cadr '((a b) (d e) (g h)))) (check-equal (1 4 27 256 3125) (map-in-order (lambda (n) (expt n n)) '(1 2 3 4 5))) (check-equal (5 7 9) (map-in-order + '(1 2 3) '(4 5 6))) (check-equal #t (let ((ret (let ((count 0)) (map-in-order (lambda (ignored) (set! count (+ count 1)) count) '(a b))))) (or (equal? ret '(1 2)) (equal? ret '(2 1))))) (check-equal (4 1 5 1) (map-in-order + '(3 1 4 1) (circular-list 1 0))) (check-equal #((0 1 2 3) (1 2 3) (2 3) (3)) (let ((v (make-vector 4))) (pair-for-each (lambda (lst) (vector-set! v (car lst) lst)) '(0 1 2 3)) v)) (check-equal #((0 . a) (1 . b) (2 . c) (3 . d)) (let ((v (make-vector 4))) (pair-for-each (lambda (fst snd) (vector-set! v (car fst) (cons (car fst) (car snd)))) '(0 1 2 3) '(a b c d)) v)) (check-equal (1 9 49) (filter-map (lambda (x) (and (number? x) (* x x))) '(a 1 b 3 c 7))) (check-equal (0 2 4 6) (filter-map (lambda (n b) (and b n)) '(0 1 2 3 4 5 6) (circular-list #t #f))) (check-equal (0 8 8 -4) (filter even? '(0 7 8 8 43 -4))) (check-equal () (filter even? '(1 3 5 7))) (check-equal () (filter even? '())) (check-equal ((one four five) (2 3 6)) (let-values (((nums syms) (partition symbol? '(one 2 3 four five 6)))) (list nums syms))) (check-equal (0 8 8 -4) (remove odd? '(0 7 8 8 43 -4))) (check-equal () (remove odd? '(1 3 5 7))) (check-equal () (remove odd? '())) (check-equal (7 43) (remove even? '(0 7 8 8 43 -4))) (check-equal (0 8 8 -4) (filter! even? '(0 7 8 8 43 -4))) (check-equal () (filter! even? '(1 3 5 7))) (check-equal () (filter! even? '())) (check-equal ((one four five) (2 3 6)) (let-values (((nums syms) (partition! symbol? '(one 2 3 four five 6)))) (list nums syms))) (check-equal (0 8 8 -4) (remove! odd? '(0 7 8 8 43 -4))) (check-equal () (remove! odd? '(1 3 5 7))) (check-equal () (remove! odd? '())) (check-equal (7 43) (remove! even? '(0 7 8 8 43 -4))) (check-equal 2 (find even? '(1 2 3))) (check-equal #f (find even? '(1 7 3))) (check-equal 2 (find even? '(1 2 . x))) (check-equal 6 (find even? (circular-list 1 6 3))) (check-equal 4 (find even? '(3 1 4 1 5 9))) (check-equal (2 3) (find-tail even? '(1 2 3))) (check-equal #f (find-tail even? '(1 7 3))) (check-equal (2 . x) (find-tail even? '(1 2 . x))) (check-equal (4 1 5 9) (find-tail even? '(3 1 4 1 5 9))) (check-equal (-8 -5 0 0) (find-tail even? '(3 1 37 -8 -5 0 0))) (check-equal #f (find-tail even? '(3 1 37 -5))) (check-equal (2 18) (take-while even? '(2 18 3 10 22 9))) (check-equal () (take-while odd? '(2 18 4 10 22 20))) (check-equal (2 18 4 10 22 20) (take-while even? '(2 18 4 10 22 20))) (check-equal (2 18) (take-while! even? '(2 18 3 10 22 9))) (check-equal () (take-while! odd? '(2 18 4 10 22 20))) (check-equal (2 18 4 10 22 20) (take-while! even? '(2 18 4 10 22 20))) (check-equal (3 10 22 9) (drop-while even? '(2 18 3 10 22 9))) (check-equal ((2 18) (3 10 22 9)) (let-values (((pre suf) (span even? '(2 18 3 10 22 9)))) (list pre suf))) (check-equal ((2 18 4 10 22 20) ()) (let-values (((pre suf) (span even? '(2 18 4 10 22 20)))) (list pre suf))) (check-equal (() (2 18 4 10 22 20)) (let-values (((pre suf) (span odd? '(2 18 4 10 22 20)))) (list pre suf))) (check-equal ((3 1) (4 1 5 9)) (let-values (((pre suf) (break even? '(3 1 4 1 5 9)))) (list pre suf))) (check-equal ((2 18 4 10 22 20) ()) (let-values (((pre suf) (break odd? '(2 18 4 10 22 20)))) (list pre suf))) (check-equal (() (2 18 4 10 22 20)) (let-values (((pre suf) (break even? '(2 18 4 10 22 20)))) (list pre suf))) (check-equal #t (any even? '(1 2 3))) (check-equal #f (any even? '(1 7 3))) (check-equal #t (any even? (circular-list 1 6 3))) (check-equal #t (any integer? '(a 3 b 2.7))) (check-equal #f (any integer? '(a 3.1 b 2.7))) (check-equal #t (any < '(3 1 4 1 5) '(2 7 1 8 2))) (check-equal #f (any even? '())) (check-equal #f (any < '(3 7 4 1 5) '(2 7))) (check-equal #t (every even? '(2 4 6 8))) (check-equal #f (every even? '(2 4 5 8))) (check-equal #t (every < '(1 2 3 4 5) '(2 3 4))) (check-equal #t (every even? '())) (check-equal 2 (list-index even? '(3 1 4 1 5 9))) (check-equal 1(list-index < '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2))) (check-equal #f (list-index = '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2))) (check-equal (a b c) (memq 'a '(a b c))) (check-equal (b c) (memq 'b '(a b c))) (check-equal #f (memq 'a '(b c d))) (check-equal #f (memq (list 'a) '(b (a) c))) (check-equal ((a) c) (member (list 'a) '(b (a) c))) (check-equal (101 102) (memq 101 '(100 101 102))) (check-equal (101 102) (memv 101 '(100 101 102))) (check-equal (b c d) (delete 'a '(a b c d))) (check-equal (b c d) (delete 'a '(a b a a c d a))) (check-equal (b c d) (delete 'a '(b c d))) (check-equal () (delete 'a '(a a a a))) (check-equal () (delete 'a '())) (check-equal (11 12 13) (delete 11 '(8 9 10 11 12 13) >)) (check-equal (a b c z) (delete-duplicates '(a b a c a b c z))) (check-equal ((a . 3) (b . 7) (c . 1)) (delete-duplicates '((a . 3) (b . 7) (a . 9) (c . 1)) (lambda (x y) (eq? (car x) (car y))))) (check-equal (a 1) (assq 'a '((a 1) (b 2) (c 3)))) (check-equal (b 2) (assq 'b '((a 1) (b 2) (c 3)))) (check-equal #f (assq 'd '((a 1) (b 2) (c 3)))) (check-equal #f (assq (list 'a) '(((a)) ((b)) ((c))))) (check-equal ((a)) (assoc (list 'a) '(((a)) ((b)) ((c))))) (check-equal (5 7) (assq 5 '((2 3) (5 7) (11 13)))) (check-equal (5 7) (assv 5 '((2 3) (5 7) (11 13)))) (check-equal ((a . 1)) (alist-cons 'a 1 '())) (check-equal ((a . 1) (b . 2)) (alist-cons 'a 1 '((b . 2)))) (check-equal ((a . 1) (b . 2) (c . 3)) (alist-copy '((a . 1) (b . 2) (c . 3)))) (check-equal () (alist-copy '())) (check-equal #t (lset<= eq? '(a) '(a b a) '(a b c c))) (check-equal #f (lset<= eq? '(a b a) '(a) '(a b c c))) (check-equal #t (lset<= eq?)) (check-equal #t (lset<= eq? '(a))) (check-equal #t (lset= eq? '(b e a) '(a e b) '(e e b a))) (check-equal #t (lset= eq?)) (check-equal #t (lset= eq? '(a))) (check-equal #f (lset= eq? '(b e a d) '(a e b) '(e e b a))) (check-equal #f (lset= eq? '(b e a) '(a d e b) '(e e b a))) (check-equal #f (lset= eq? '(b e a) '(a e b) '(e d e b a))) (check-equal (u o i a b c d c e) (lset-adjoin eq? '(a b c d c e) 'a 'e 'i 'o 'u)) (check-equal (u o i a b c d e) (lset-union eq? '(a b c d e) '(a e i o u))) (check-equal (x a a c) (lset-union eq? '(a a c) '(x a x))) (check-equal () (lset-union eq?)) (check-equal (a b c) (lset-union eq? '(a b c))) (check-equal (a e) (lset-intersection eq? '(a b c d e) '(a e i o u))) (check-equal (a x a) (lset-intersection eq? '(a x y a) '(x a x z))) (check-equal (a b c) (lset-intersection eq? '(a b c))) (check-equal (b c d) (lset-difference eq? '(a b c d e) '(a e i o u))) (check-equal (a b c) (lset-difference eq? '(a b c))) (check-equal (b c d i o u) (lset-xor eq? '(a b c d e) '(a e i o u))) (check-equal () (lset-xor eq?)) (check-equal (a b c d e) (lset-xor eq? '(a b c d e))) (check-equal ((b c d) (a e)) (let-values (((diff inter) (lset-diff+intersection eq? '(a b c d e) '(a e i o u)))) (list diff inter))) ;; ;; ---- SRFI 128: Comparators ---- ;; (import (foment base)) (import (scheme char)) (import (scheme comparator)) (define default-comparator (make-default-comparator)) (define boolean-comparator (make-comparator boolean? eq? (lambda (x y) (and (not x) y)) boolean-hash)) (define char-comparator (make-comparator char? char=? char<? char-hash)) (define string-ci-comparator (make-comparator string? string-ci=? string-ci<? string-ci-hash)) (define symbol-comparator (make-comparator symbol? eq? (lambda (obj1 obj2) (string<? (symbol->string obj1) (symbol->string obj2))) symbol-hash)) (define fail-comparator (make-comparator (lambda (obj) #t) eq? #f #f)) (define number-comparator (make-comparator number? = < number-hash)) (define pnb-comparator (make-pair-comparator number-comparator boolean-comparator)) (define ln-comparator (make-list-comparator number-comparator list? null? car cdr)) (define vn-comparator (make-vector-comparator number-comparator vector? vector-length vector-ref)) (define eq-comparator (make-eq-comparator)) (define eqv-comparator (make-eqv-comparator)) (define equal-comparator (make-equal-comparator)) (check-equal #t (comparator? (make-comparator (lambda (obj) #t) eq? #f #f))) (check-equal #t (comparator? (make-default-comparator))) (check-equal #f (comparator? (list 'make-comparator (lambda (obj) #t) eq? #f #f))) (check-equal #t (comparator? boolean-comparator)) (check-equal #t (comparator? symbol-comparator)) (check-equal #t (comparator-ordered? boolean-comparator)) (check-equal #f (comparator-ordered? (make-comparator (lambda (obj) #t) eq? #f #f))) (check-equal #f (comparator-ordered? fail-comparator)) (check-equal #t (comparator-hashable? boolean-comparator)) (check-equal #f (comparator-hashable? (make-comparator (lambda (obj) #t) eq? #f #f))) (check-equal #f (comparator-hashable? fail-comparator)) (check-error (assertion-violation no-ordering-predicate) ((comparator-ordering-predicate fail-comparator) 1 2)) (check-error (assertion-violation no-hash-function) ((comparator-hash-function fail-comparator) 1)) (check-equal #t (comparator-test-type pnb-comparator '(12 . #t))) (check-equal #f (comparator-test-type pnb-comparator '(#t . 12))) (check-equal #f (comparator-test-type pnb-comparator '(#t 12))) (check-equal #f (comparator-test-type pnb-comparator #t)) (check-equal #f (comparator-test-type pnb-comparator 12)) (check-equal #t (=? pnb-comparator '(12 . #t) '(12 . #t))) (check-equal #f (=? pnb-comparator '(12 . #t) '(11 . #t))) (check-equal #f (=? pnb-comparator '(12 . #t) '(12 . #f))) (check-equal #t (<? pnb-comparator '(12 . #t) '(13 . #t))) (check-equal #t (<? pnb-comparator '(12 . #f) '(12 . #t))) (check-equal #f (<? pnb-comparator '(12 . #t) '(12 . #t))) (check-equal #f (<? pnb-comparator '(13 . #t) '(12 . #t))) (check-equal #f (<? pnb-comparator '(12 . #t) '(12 . #f))) (check-equal #t (= (comparator-hash pnb-comparator '(12 . #t)) (comparator-hash pnb-comparator '(12 . #t)))) (check-equal #f (= (comparator-hash pnb-comparator '(13 . #t)) (comparator-hash pnb-comparator '(12 . #t)))) (check-equal #f (= (comparator-hash pnb-comparator '(12 . #f)) (comparator-hash pnb-comparator '(12 . #t)))) (check-equal #t (comparator-test-type ln-comparator '(12 34))) (check-equal #f (comparator-test-type ln-comparator '(12 . 34))) (check-equal #f (comparator-test-type ln-comparator '(12 34 #t))) (check-equal #f (comparator-test-type ln-comparator 123)) (check-equal #t (=? ln-comparator '(12 34) '(12 34))) (check-equal #f (=? ln-comparator '(12 34) '(12 34 56))) (check-equal #f (=? ln-comparator '(12 34) '(12 35))) (check-equal #f (=? ln-comparator '(12 34) '(13 34))) (check-equal #t (<? ln-comparator '(12 34) '(12 35))) (check-equal #f (<? ln-comparator '(12 34) '(12 34))) (check-equal #f (<? ln-comparator '(12 34 56) '(12 34))) (check-equal #t (<? ln-comparator '(12 34) '(12 34 56))) (check-equal #f (<? ln-comparator '(13 34) '(12 34))) (check-equal #f (<? ln-comparator '(12 35) '(12 34))) (check-equal #t (comparator-test-type vn-comparator #(12 34))) (check-equal #f (comparator-test-type vn-comparator '(12 34))) (check-equal #f (comparator-test-type vn-comparator #(12 34 #t))) (check-equal #f (comparator-test-type vn-comparator 123)) (check-equal #t (=? vn-comparator #(12 34) #(12 34))) (check-equal #f (=? vn-comparator #(12 34) #(12 34 56))) (check-equal #f (=? vn-comparator #(12 34) #(12 35))) (check-equal #f (=? vn-comparator #(12 34) #(13 34))) (check-equal #t (<? vn-comparator #(12 34) #(12 35))) (check-equal #f (<? vn-comparator #(12 34) #(12 34))) (check-equal #f (<? vn-comparator #(12 34 56) #(12 34))) (check-equal #t (<? vn-comparator #(12 34) #(12 34 56))) (check-equal #f (<? vn-comparator #(13 34) #(12 34))) (check-equal #f (<? vn-comparator #(12 35) #(12 34))) (check-equal #t (comparator-test-type eq-comparator #t)) (check-equal #t (comparator-test-type eq-comparator (lambda (obj) obj))) (check-equal #t (comparator-test-type eq-comparator 123)) (check-equal #t (comparator-test-type eq-comparator '(1 2 3))) (check-equal #t (comparator-test-type eq-comparator cons)) (check-equal #t (=? eq-comparator 123 123)) (check-equal #f (=? eq-comparator 123 123.456)) (check-equal #f (=? eq-comparator '(1 2 3) '(1 2 3))) (check-equal #t (let ((lst '(1 2 3))) (=? eq-comparator lst lst))) (check-equal #f (=? eq-comparator #(1 2 3) #(1 2 3))) (check-equal #t (let ((vec '#(1 2 3))) (=? eq-comparator vec vec))) (check-equal #t (eq? default-hash (comparator-hash-function eq-comparator))) (check-equal #t (comparator-test-type eqv-comparator #t)) (check-equal #t (comparator-test-type eqv-comparator (lambda (obj) obj))) (check-equal #t (comparator-test-type eqv-comparator 123)) (check-equal #t (comparator-test-type eqv-comparator '(1 2 3))) (check-equal #t (comparator-test-type eqv-comparator cons)) (check-equal #t (=? eqv-comparator 123 123)) (check-equal #f (=? eqv-comparator 123 123.456)) (check-equal #f (=? eqv-comparator '(1 2 3) '(1 2 3))) (check-equal #t (let ((lst '(1 2 3))) (=? eqv-comparator lst lst))) (check-equal #f (=? eqv-comparator #(1 2 3) #(1 2 3))) (check-equal #t (let ((vec '#(1 2 3))) (=? eqv-comparator vec vec))) (check-equal #t (eq? default-hash (comparator-hash-function eqv-comparator))) (check-equal #t (comparator-test-type equal-comparator #t)) (check-equal #t (comparator-test-type equal-comparator (lambda (obj) obj))) (check-equal #t (comparator-test-type equal-comparator 123)) (check-equal #t (comparator-test-type equal-comparator '(1 2 3))) (check-equal #t (comparator-test-type equal-comparator cons)) (check-equal #t (=? equal-comparator 123 123)) (check-equal #f (=? equal-comparator 123 123.456)) (check-equal #t (=? equal-comparator '(1 2 3) '(1 2 3))) (check-equal #t (let ((lst '(1 2 3))) (=? equal-comparator lst lst))) (check-equal #t (=? equal-comparator #(1 2 3) #(1 2 3))) (check-equal #t (let ((vec '#(1 2 3))) (=? equal-comparator vec vec))) (check-equal #t (eq? default-hash (comparator-hash-function equal-comparator))) (check-equal #t (= (boolean-hash #t) (boolean-hash #t))) (check-equal #t (= (boolean-hash #f) (boolean-hash #f))) (check-equal #f (= (boolean-hash #f) (boolean-hash #t))) (check-equal #t (= (char-hash #\a) (char-hash #\a))) (check-equal #f (= (char-hash #\a) (char-hash #\A))) (check-equal #f (= (char-hash #\a) (char-hash #\b))) (check-equal #t (= (char-ci-hash #\a) (char-ci-hash #\a))) (check-equal #t (= (char-ci-hash #\a) (char-ci-hash #\A))) (check-equal #f (= (char-ci-hash #\a) (char-ci-hash #\b))) (check-equal #t (= (string-hash "abcdef") (string-hash "abcdef"))) (check-equal #f (= (string-hash "abcdef") (string-hash "Abcdef"))) (check-equal #f (= (string-hash "abcdef") (string-hash "bcdefg"))) (check-equal #t (= (string-ci-hash "abcdef") (string-ci-hash "abcdef"))) (check-equal #t (= (string-ci-hash "abcdef") (string-ci-hash "Abcdef"))) (check-equal #f (= (string-ci-hash "abcdef") (string-ci-hash "bcdefg"))) (check-equal #t (= (symbol-hash 'abc) (symbol-hash (string->symbol "abc")))) (check-equal #f (= (symbol-hash 'abc) (symbol-hash 'abcd))) (check-equal #t (= (number-hash 123) (number-hash 123))) (check-equal #f (= (number-hash 123) (number-hash 456))) (check-equal #t (= (number-hash 123.456) (number-hash 123.456))) (check-equal #f (= (number-hash 123.456) (number-hash 456.789))) (check-equal #t (<? default-comparator '() '(1 . 2))) (check-equal #f (<? default-comparator '(1 . 2) '())) (check-equal #t (<? default-comparator #f #t)) (check-equal #f (<? default-comparator #t #f)) (check-equal #t (eq? default-hash (comparator-hash-function default-comparator))) (check-equal #t (comparator-test-type boolean-comparator #t)) (check-equal #f (comparator-test-type boolean-comparator 't)) (check-equal #f (comparator-test-type boolean-comparator '())) (check-error (assertion-violation comparator-check-type) (comparator-check-type boolean-comparator 123)) (check-equal #t (=? boolean-comparator #f #f)) (check-equal #f (=? boolean-comparator #t #f)) (check-equal -1 (comparator-if<=> boolean-comparator #f #t -1 0 1)) (check-equal 0 (comparator-if<=> boolean-comparator #f #f -1 0 1)) (check-equal 1 (comparator-if<=> boolean-comparator #t #f -1 0 1)) (check-equal #t (= (comparator-hash boolean-comparator #f) (comparator-hash boolean-comparator #f))) (check-equal #f (= (comparator-hash boolean-comparator #t) (comparator-hash boolean-comparator #f))) (check-equal #t (comparator-test-type char-comparator #\A)) (check-equal #f (comparator-test-type char-comparator 'a)) (check-equal #t (=? char-comparator #\z #\z)) (check-equal #f (=? char-comparator #\Z #\z)) (check-equal -1 (comparator-if<=> char-comparator #\a #\f -1 0 1)) (check-equal 0 (comparator-if<=> char-comparator #\Q #\Q -1 0 1)) (check-equal 1 (comparator-if<=> char-comparator #\F #\A -1 0 1)) (check-equal #t (= (comparator-hash char-comparator #\w) (comparator-hash char-comparator #\w))) (check-equal #f (= (comparator-hash char-comparator #\w) (comparator-hash char-comparator #\x))) (check-equal #t (comparator-test-type string-ci-comparator "abc")) (check-equal #f (comparator-test-type string-ci-comparator #\a)) (check-equal #t (=? string-ci-comparator "xyz" "xyz")) (check-equal #t (=? string-ci-comparator "XYZ" "xyz")) (check-equal #f (=? string-ci-comparator "xyz" "zyx")) (check-equal -1 (comparator-if<=> string-ci-comparator "abc" "def" -1 0 1)) (check-equal -1 (comparator-if<=> string-ci-comparator "ABC" "def" -1 0 1)) (check-equal -1 (comparator-if<=> string-ci-comparator "abc" "DEF" -1 0 1)) (check-equal 0 (comparator-if<=> string-ci-comparator "ghi" "ghi" -1 0 1)) (check-equal 0 (comparator-if<=> string-ci-comparator "ghi" "GHI" -1 0 1)) (check-equal 1 (comparator-if<=> string-ci-comparator "mno" "jkl" -1 0 1)) (check-equal 1 (comparator-if<=> string-ci-comparator "MNO" "jkl" -1 0 1)) (check-equal 1 (comparator-if<=> string-ci-comparator "mno" "JKL" -1 0 1)) (check-equal #t (= (comparator-hash string-ci-comparator "xyz") (comparator-hash string-ci-comparator "xyz"))) (check-equal #t (= (comparator-hash string-ci-comparator "xyz") (comparator-hash string-ci-comparator "XYZ"))) (check-equal #f (= (comparator-hash string-ci-comparator "xyz") (comparator-hash string-ci-comparator "zyx"))) (check-equal #t (comparator-test-type symbol-comparator 'abc)) (check-equal #f (comparator-test-type symbol-comparator "abc")) (check-equal #t (=? symbol-comparator 'xyz 'xyz)) (check-equal #f (=? symbol-comparator 'XYZ 'xyz)) (check-equal -1 (comparator-if<=> symbol-comparator 'abc 'def -1 0 1)) (check-equal 0 (comparator-if<=> symbol-comparator 'ghi 'ghi -1 0 1)) (check-equal 1 (comparator-if<=> symbol-comparator 'mno 'jkl -1 0 1)) (check-equal #t (= (comparator-hash symbol-comparator 'pqr) (comparator-hash symbol-comparator 'pqr))) (check-equal #f (= (comparator-hash symbol-comparator 'stu) (comparator-hash symbol-comparator 'vwx))) (check-equal #t (<? default-comparator #f #t)) (check-equal #f (<? default-comparator #f #f)) (check-equal #f (<? default-comparator #t #t)) (check-equal #f (<? default-comparator #t #f)) ;; Tests from the reference implementation of comparators. (define (vector-cdr vec) (let* ((len (vector-length vec)) (result (make-vector (- len 1)))) (let loop ((n 1)) (cond ((= n len) result) (else (vector-set! result (- n 1) (vector-ref vec n)) (loop (+ n 1))))))) (check-equal #(2 3 4) (vector-cdr '#(1 2 3 4))) (check-equal #() (vector-cdr '#(1))) ; (define default-comparator (make-default-comparator)) (define real-comparator (make-comparator real? = < number-hash)) (define degenerate-comparator (make-comparator (lambda (x) #t) equal? #f #f)) ; (define boolean-comparator ; (make-comparator boolean? eq? (lambda (x y) (and (not x) y)) boolean-hash)) (define bool-pair-comparator (make-pair-comparator boolean-comparator boolean-comparator)) (define num-list-comparator (make-list-comparator real-comparator list? null? car cdr)) (define num-vector-comparator (make-vector-comparator real-comparator vector? vector-length vector-ref)) (define vector-qua-list-comparator (make-list-comparator real-comparator vector? (lambda (vec) (= 0 (vector-length vec))) (lambda (vec) (vector-ref vec 0)) vector-cdr)) (define list-qua-vector-comparator (make-vector-comparator default-comparator list? length list-ref)) ; (define eq-comparator (make-eq-comparator)) ; (define eqv-comparator (make-eqv-comparator)) ; (define equal-comparator (make-equal-comparator)) ; (define symbol-comparator ; (make-comparator ; symbol? ; eq? ; (lambda (a b) (string<? (symbol->string a) (symbol->string b))) ; symbol-hash)) (check-equal #t (comparator? real-comparator)) (check-equal #t (not (comparator? =))) (check-equal #t (comparator-ordered? real-comparator)) (check-equal #t (comparator-hashable? real-comparator)) (check-equal #t (not (comparator-ordered? degenerate-comparator))) (check-equal #t (not (comparator-hashable? degenerate-comparator))) (check-equal #t (=? boolean-comparator #t #t)) (check-equal #t (not (=? boolean-comparator #t #f))) (check-equal #t (<? boolean-comparator #f #t)) (check-equal #t (not (<? boolean-comparator #t #t))) (check-equal #t (not (<? boolean-comparator #t #f))) (check-equal #t (comparator-test-type bool-pair-comparator '(#t . #f))) (check-equal #t (not (comparator-test-type bool-pair-comparator 32))) (check-equal #t (not (comparator-test-type bool-pair-comparator '(32 . #f)))) (check-equal #t (not (comparator-test-type bool-pair-comparator '(#t . 32)))) (check-equal #t (not (comparator-test-type bool-pair-comparator '(32 . 34)))) (check-equal #t (=? bool-pair-comparator '(#t . #t) '(#t . #t))) (check-equal #t (not (=? bool-pair-comparator '(#t . #t) '(#f . #t)))) (check-equal #t (not (=? bool-pair-comparator '(#t . #t) '(#t . #f)))) (check-equal #t (<? bool-pair-comparator '(#f . #t) '(#t . #t))) (check-equal #t (<? bool-pair-comparator '(#t . #f) '(#t . #t))) (check-equal #t (not (<? bool-pair-comparator '(#t . #t) '(#t . #t)))) (check-equal #t (not (<? bool-pair-comparator '(#t . #t) '(#f . #t)))) (check-equal #t (not (<? bool-pair-comparator '(#f . #t) '(#f . #f)))) (check-equal #t (comparator-test-type num-vector-comparator '#(1 2 3))) (check-equal #t (comparator-test-type num-vector-comparator '#())) (check-equal #t (not (comparator-test-type num-vector-comparator 1))) (check-equal #t (not (comparator-test-type num-vector-comparator '#(a 2 3)))) (check-equal #t (not (comparator-test-type num-vector-comparator '#(1 b 3)))) (check-equal #t (not (comparator-test-type num-vector-comparator '#(1 2 c)))) (check-equal #t (=? num-vector-comparator '#(1 2 3) '#(1 2 3))) (check-equal #t (not (=? num-vector-comparator '#(1 2 3) '#(4 5 6)))) (check-equal #t (not (=? num-vector-comparator '#(1 2 3) '#(1 5 6)))) (check-equal #t (not (=? num-vector-comparator '#(1 2 3) '#(1 2 6)))) (check-equal #t (<? num-vector-comparator '#(1 2) '#(1 2 3))) (check-equal #t (<? num-vector-comparator '#(1 2 3) '#(2 3 4))) (check-equal #t (<? num-vector-comparator '#(1 2 3) '#(1 3 4))) (check-equal #t (<? num-vector-comparator '#(1 2 3) '#(1 2 4))) (check-equal #t (<? num-vector-comparator '#(3 4) '#(1 2 3))) (check-equal #t (not (<? num-vector-comparator '#(1 2 3) '#(1 2 3)))) (check-equal #t (not (<? num-vector-comparator '#(1 2 3) '#(1 2)))) (check-equal #t (not (<? num-vector-comparator '#(1 2 3) '#(0 2 3)))) (check-equal #t (not (<? num-vector-comparator '#(1 2 3) '#(1 1 3)))) (check-equal #t (not (<? vector-qua-list-comparator '#(3 4) '#(1 2 3)))) (check-equal #t (<? list-qua-vector-comparator '(3 4) '(1 2 3))) (define bool-pair (cons #t #f)) (define bool-pair-2 (cons #t #f)) (define reverse-bool-pair (cons #f #t)) (check-equal #t (=? eq-comparator #t #t)) (check-equal #t (not (=? eq-comparator #f #t))) (check-equal #t (=? eqv-comparator bool-pair bool-pair)) (check-equal #t (not (=? eqv-comparator bool-pair bool-pair-2))) (check-equal #t (=? equal-comparator bool-pair bool-pair-2)) (check-equal #t (not (=? equal-comparator bool-pair reverse-bool-pair))) (check-equal #t (exact-integer? (boolean-hash #f))) (check-equal #t (not (negative? (boolean-hash #t)))) (check-equal #t (exact-integer? (char-hash #\a))) (check-equal #t (not (negative? (char-hash #\b)))) (check-equal #t (exact-integer? (char-ci-hash #\a))) (check-equal #t (not (negative? (char-ci-hash #\b)))) (check-equal #t (= (char-ci-hash #\a) (char-ci-hash #\A))) (check-equal #t (exact-integer? (string-hash "f"))) (check-equal #t (not (negative? (string-hash "g")))) (check-equal #t (exact-integer? (string-ci-hash "f"))) (check-equal #t (not (negative? (string-ci-hash "g")))) (check-equal #t (= (string-ci-hash "f") (string-ci-hash "F"))) (check-equal #t (exact-integer? (symbol-hash 'f))) (check-equal #t (not (negative? (symbol-hash 't)))) (check-equal #t (exact-integer? (number-hash 3))) (check-equal #t (not (negative? (number-hash 3)))) (check-equal #t (exact-integer? (number-hash -3))) (check-equal #t (not (negative? (number-hash -3)))) (check-equal #t (exact-integer? (number-hash 3.0))) (check-equal #t (not (negative? (number-hash 3.0)))) (check-equal #t (<? default-comparator '() '(a))) (check-equal #t (not (=? default-comparator '() '(a)))) (check-equal #t (=? default-comparator #t #t)) (check-equal #t (not (=? default-comparator #t #f))) (check-equal #t (<? default-comparator #f #t)) (check-equal #t (not (<? default-comparator #t #t))) (check-equal #t (=? default-comparator #\a #\a)) (check-equal #t (<? default-comparator #\a #\b)) (check-equal #t (comparator-test-type default-comparator '())) (check-equal #t (comparator-test-type default-comparator #t)) (check-equal #t (comparator-test-type default-comparator #\t)) (check-equal #t (comparator-test-type default-comparator '(a))) (check-equal #t (comparator-test-type default-comparator 'a)) (check-equal #t (comparator-test-type default-comparator (make-bytevector 10))) (check-equal #t (comparator-test-type default-comparator 10)) (check-equal #t (comparator-test-type default-comparator 10.0)) (check-equal #t (comparator-test-type default-comparator "10.0")) (check-equal #t (comparator-test-type default-comparator '#(10))) (check-equal #t (=? default-comparator '(#t . #t) '(#t . #t))) (check-equal #t (not (=? default-comparator '(#t . #t) '(#f . #t)))) (check-equal #t (not (=? default-comparator '(#t . #t) '(#t . #f)))) (check-equal #t (<? default-comparator '(#f . #t) '(#t . #t))) (check-equal #t (<? default-comparator '(#t . #f) '(#t . #t))) (check-equal #t (not (<? default-comparator '(#t . #t) '(#t . #t)))) (check-equal #t (not (<? default-comparator '(#t . #t) '(#f . #t)))) (check-equal #t (not (<? default-comparator '#(#f #t) '#(#f #f)))) (check-equal #t (=? default-comparator '#(#t #t) '#(#t #t))) (check-equal #t (not (=? default-comparator '#(#t #t) '#(#f #t)))) (check-equal #t (not (=? default-comparator '#(#t #t) '#(#t #f)))) (check-equal #t (<? default-comparator '#(#f #t) '#(#t #t))) (check-equal #t (<? default-comparator '#(#t #f) '#(#t #t))) (check-equal #t (not (<? default-comparator '#(#t #t) '#(#t #t)))) (check-equal #t (not (<? default-comparator '#(#t #t) '#(#f #t)))) (check-equal #t (not (<? default-comparator '#(#f #t) '#(#f #f)))) (check-equal #t (= (comparator-hash default-comparator #t) (boolean-hash #t))) (check-equal #t (= (comparator-hash default-comparator #\t) (char-hash #\t))) (check-equal #t (= (comparator-hash default-comparator "t") (string-hash "t"))) (check-equal #t (= (comparator-hash default-comparator 't) (symbol-hash 't))) (check-equal #t (= (comparator-hash default-comparator 10) (number-hash 10))) (check-equal #t (= (comparator-hash default-comparator 10.0) (number-hash 10.0))) (comparator-register-default! (make-comparator procedure? (lambda (a b) #t) (lambda (a b) #f) (lambda (obj) 200))) (check-equal #t (=? default-comparator (lambda () #t) (lambda () #f))) (check-equal #t (not (<? default-comparator (lambda () #t) (lambda () #f)))) (check-equal 200 (comparator-hash default-comparator (lambda () #t))) (define ttp (lambda (x) #t)) (define eqp (lambda (x y) #t)) (define orp (lambda (x y) #t)) (define hf (lambda (x) 0)) (define comp (make-comparator ttp eqp orp hf)) (check-equal #t (equal? ttp (comparator-type-test-predicate comp))) (check-equal #t (equal? eqp (comparator-equality-predicate comp))) (check-equal #t (equal? orp (comparator-ordering-predicate comp))) (check-equal #t (equal? hf (comparator-hash-function comp))) (check-equal #t (comparator-test-type real-comparator 3)) (check-equal #t (comparator-test-type real-comparator 3.0)) (check-equal #t (not (comparator-test-type real-comparator "3.0"))) (check-equal #t (comparator-check-type boolean-comparator #t)) (check-error (assertion-violation comparator-check-type) (comparator-check-type boolean-comparator 't)) (check-equal #t (=? real-comparator 2 2.0 2)) (check-equal #t (<? real-comparator 2 3.0 4)) (check-equal #t (>? real-comparator 4.0 3.0 2)) (check-equal #t (<=? real-comparator 2.0 2 3.0)) (check-equal #t (>=? real-comparator 3 3.0 2)) (check-equal #t (not (=? real-comparator 1 2 3))) (check-equal #t (not (<? real-comparator 3 1 2))) (check-equal #t (not (>? real-comparator 1 2 3))) (check-equal #t (not (<=? real-comparator 4 3 3))) (check-equal #t (not (>=? real-comparator 3 4 4.0))) (check-equal less (comparator-if<=> real-comparator 1 2 'less 'equal 'greater)) (check-equal equal (comparator-if<=> real-comparator 1 1 'less 'equal 'greater)) (check-equal greater (comparator-if<=> real-comparator 2 1 'less 'equal 'greater)) (check-equal less (comparator-if<=> "1" "2" 'less 'equal 'greater)) (check-equal equal (comparator-if<=> "1" "1" 'less 'equal 'greater)) (check-equal greater (comparator-if<=> "2" "1" 'less 'equal 'greater)) (check-equal #t (exact-integer? (hash-bound))) (check-equal #t (exact-integer? (hash-salt))) (check-equal #t (< (hash-salt) (hash-bound))) ;; ;; ---- SRFI 125: Hash Tables ---- ;; (import (foment base)) (import (scheme hash-table)) (import (scheme comparator)) (import (scheme list)) (define default (make-default-comparator)) (check-equal #t (hash-table? (make-eq-hash-table))) (check-equal #f (hash-table? #(1 2 3 4))) (check-equal #f (hash-table? '(1 2 3 4))) (check-equal #t (hash-table? (make-hash-table default))) (check-equal #t (hash-table? (make-hash-table string=? string-hash 2345))) (check-equal #t (hash-table? (make-hash-table string-ci=?))) (check-equal #t (hash-table? (make-hash-table string=? string-hash 2345 'weak-keys))) (check-equal #t (hash-table? (make-hash-table string-ci=? 'thread-safe))) (check-error (assertion-violation make-hash-table) (make-hash-table char=?)) (check-error (assertion-violation make-hash-table) (make-hash-table 1234)) (check-error (assertion-violation make-hash-table) (make-hash-table string=? 'bad-food)) (check-error (assertion-violation make-hash-table) (make-hash-table string=? string-hash 'weak-knees)) (check-error (assertion-violation make-hash-table) (make-hash-table string=? string-hash 'weak-keys 'ephemeral-keys)) (check-error (assertion-violation hash-table) (hash-table)) (check-error (assertion-violation make-hash-table) (hash-table char=?)) (check-equal #t (hash-table? (hash-table default))) (define htbl (hash-table default 'a "a" 'b "b" 'c "c" 'd "d")) (check-equal "a" (hash-table-ref/default htbl 'a #f)) (check-equal "b" (hash-table-ref/default htbl 'b #f)) (check-equal "c" (hash-table-ref/default htbl 'c #f)) (check-equal "d" (hash-table-ref/default htbl 'd #f)) (check-equal #f (hash-table-ref/default htbl 'e #f)) (check-error (assertion-violation hash-table-set!) (hash-table-set! htbl 'e "e")) (check-equal #f (hash-table-ref/default htbl 'e #f)) (check-equal #t (hash-table=? default (hash-table default 'a 1 'b 2 'c 3 'd 4) (hash-table default 'a 1 'b 2 'c 3 'd 4))) (check-equal #f (hash-table=? default (hash-table default 'a 1 'b 2 'c 3 'd 5) (hash-table default 'a 1 'b 2 'c 3 'd 4))) (check-equal #f (hash-table=? default (hash-table default 'a 1 'b 2 'c 3) (hash-table default 'a 1 'b 2 'c 3 'd 4))) (check-equal #f (hash-table=? default (hash-table default 'a 1 'b 2 'c 3 'd 4) (hash-table default 'a 1 'b 2 'c 3))) (check-equal #f (hash-table=? default (hash-table default 'a 1 'b 2 'c 3 'e 4) (hash-table default 'a 1 'b 2 'c 3 'd 4))) (check-error (assertion-violation hash-table-unfold) (hash-table-unfold)) (check-error (assertion-violation make-hash-table) (hash-table-unfold (lambda (seed) (> seed 8)) (lambda (seed) (values (number->string seed) seed)) (lambda (seed) (+ seed 1)) 1 char=?)) (check-equal #t (hash-table=? default (hash-table default "1" 1 "2" 2 "3" 3 "4" 4 "5" 5 "6" 6 "7" 7 "8" 8) (hash-table-unfold (lambda (seed) (> seed 8)) (lambda (seed) (values (number->string seed) seed)) (lambda (seed) (+ seed 1)) 1 default))) (check-equal 8 (hash-table-size (hash-table-unfold (lambda (seed) (> seed 8)) (lambda (seed) (values (number->string seed) seed)) (lambda (seed) (+ seed 1)) 1 default))) (check-error (assertion-violation alist->hash-table) (alist->hash-table '())) (check-error (assertion-violation make-hash-table) (alist->hash-table '() char=?)) (check-error (assertion-violation car) (alist->hash-table '(a) default)) (check-equal #t (hash-table=? default (hash-table default 'a 1 'b 2 'c 3 'd 4 'e 5) (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5)) default))) (check-equal #t (hash-table=? default (hash-table default 'a 1 'b 2 'c 3) (alist->hash-table '((a . 1) (b . 2) (c . 3) (a . 4) (b . 5)) default))) (check-error (assertion-violation hash-table-contains?) (hash-table-contains? htbl)) (check-error (assertion-violation hash-table-contains?) (hash-table-contains? htbl 123 456)) (check-equal #t (hash-table-contains? (hash-table default 'a 1) 'a)) (check-equal #f (hash-table-contains? (hash-table default 'a 1) 'b)) (check-equal #t (hash-table-empty? (hash-table default))) (check-equal #f (hash-table-empty? (hash-table default 'a 1))) (check-equal #t (hash-table-mutable? (make-hash-table default))) (check-equal #f (hash-table-mutable? (hash-table default))) (check-equal #t (hash-table-mutable? (hash-table-unfold (lambda (seed) (> seed 8)) (lambda (seed) (values (number->string seed) seed)) (lambda (seed) (+ seed 1)) 1 default))) (check-equal #t (hash-table-mutable? (alist->hash-table '() default))) (define htbl2 (hash-table default 'a 1 'b 2 'c 3 'd 4)) (check-error (assertion-violation hash-table-ref) (hash-table-ref)) (check-error (assertion-violation hash-table-ref) (hash-table-ref htbl2)) (check-error (assertion-violation hash-table-ref) (hash-table-ref htbl2 'e)) (check-equal 1 (hash-table-ref htbl2 'a)) (check-equal 10 (hash-table-ref htbl2 'e (lambda () 10))) (check-equal 30 (hash-table-ref htbl2 'c (lambda () #f) (lambda (val) (* val 10)))) (check-error (assertion-violation hash-table-ref/default) (hash-table-ref/default htbl2)) (check-error (assertion-violation hash-table-ref/default) (hash-table-ref/default htbl2 'e)) (check-equal 1 (hash-table-ref/default htbl2 'a 10)) (check-equal 10 (hash-table-ref/default htbl2 'e 10)) (define (test-hash-table initial test expected) (let ((htbl (alist->hash-table initial default))) (test htbl) (hash-table=? default htbl (alist->hash-table expected default)))) (check-equal #t (test-hash-table '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5)) (lambda (htbl) (hash-table-set! htbl 'a 10) (hash-table-set! htbl 'b 20 'c 30) (hash-table-set! htbl)) '((a . 10) (b . 20) (c . 30) (d . 4) (e . 5)))) (check-error (assertion-violation hash-table-set!) (hash-table-set! (hash-table default 'a 1) 'a 10)) (check-equal #t (test-hash-table '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5)) (lambda (htbl) (hash-table-delete! htbl 'a) (hash-table-delete! htbl 'b 'c) (hash-table-delete! htbl) (hash-table-delete! htbl 'f)) '((d . 4) (e . 5)))) (check-error (assertion-violation hash-table-delete!) (hash-table-delete! (hash-table default 'a 1) 'a)) (check-equal #t (test-hash-table '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5)) (lambda (htbl) (hash-table-intern! htbl 'a (lambda () 100)) (hash-table-intern! htbl 'f (lambda () 6))) '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5) (f . 6)))) (check-error (assertion-violation hash-table-intern!) (hash-table-intern! (hash-table default 'a 1) 'b 2)) (check-equal #t (test-hash-table '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5)) (lambda (htbl) (hash-table-update! htbl 'a (lambda (val) (* val 100))) (hash-table-update! htbl 'f (lambda (val) (- val)) (lambda () 6))) '((a . 100) (b . 2) (c . 3) (d . 4) (e . 5) (f . -6)))) (check-error (assertion-violation hash-table-set!) (hash-table-update! (hash-table default 'a 1) 'a (lambda (val) (* val 10)))) (check-equal #t (test-hash-table '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5)) (lambda (htbl) (hash-table-update!/default htbl 'a (lambda (val) (* val 100)) -1) (hash-table-update!/default htbl 'f (lambda (val) (- val)) 6)) '((a . 100) (b . 2) (c . 3) (d . 4) (e . 5) (f . -6)))) (check-error (assertion-violation hash-table-set!) (hash-table-update!/default (hash-table default 'a 1) 'a (lambda (val) (* val 10)) 6)) (check-equal #t (let* ((alist '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5))) (htbl (alist->hash-table alist default))) (define (accum lst) (if (> (hash-table-size htbl) 0) (accum (cons (let-values (((key val) (hash-table-pop! htbl))) (cons key val)) lst)) lst)) (hash-table=? default (alist->hash-table (accum '()) default) (alist->hash-table alist default)))) (check-equal (a . 1) (let-values (((key val) (hash-table-pop! (alist->hash-table '((a . 1)) default)))) (cons key val))) (check-error (assertion-violation hash-table-pop!) (hash-table-pop! (hash-table default 'a 1))) (check-error (assertion-violation %hash-table-pop!) (hash-table-pop! (alist->hash-table '() default))) (check-equal 0 (let ((htbl (alist->hash-table '((a . 1) (b . 2)) default))) (hash-table-clear! htbl) (hash-table-size htbl))) (check-error (assertion-violation hash-table-clear!) (hash-table-clear! (hash-table default 'a 1))) (check-equal 0 (hash-table-size (hash-table default))) (check-equal 3 (hash-table-size (hash-table default 'a 1 'b 2 'c 3))) (check-equal #t (lset= eq? '(a b c d) (hash-table-keys (hash-table default 'a 1 'b 2 'c 3 'd 4)))) (check-equal #t (lset= eq? '(1 2 3 4) (hash-table-values (hash-table default 'a 1 'b 2 'c 3 'd 4)))) (check-equal #t (lset= equal? '((a . 1) (b . 2) (c . 3) (d . 4)) (let-values (((keys values) (hash-table-entries (hash-table default 'a 1 'b 2 'c 3 'd 4)))) (map cons keys values)))) (check-equal 4 (hash-table-find (lambda (key val) (if (eq? key 'd) val #f)) (hash-table default 'a 1 'b 2 'c 3 'd 4) (lambda () 'not-found))) (check-equal not-found (hash-table-find (lambda (key val) (if (eq? key 'e) val #f)) (hash-table default 'a 1 'b 2 'c 3 'd 4) (lambda () 'not-found))) (check-equal 3 (hash-table-count (lambda (key val) (odd? val)) (hash-table default 'a 1 'b 2 'c 3 'd 4 'e 5))) (check-equal #t (hash-table=? default (hash-table default 'a 10 'b 20 'c 30 'd 40) (hash-table-map (lambda (val) (* val 10)) default (hash-table default 'a 1 'b 2 'c 3 'd 4)))) (check-equal #t (lset= equal? '((a . 1) (b . 2) (c . 3) (d . 4)) (let ((lst '())) (hash-table-for-each (lambda (key val) (set! lst (cons (cons key val) lst))) (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default)) lst))) (check-error (assertion-violation hash-table-map!) (hash-table-map! (lambda (key val) (* val 10)) (hash-table default 'a 1 'b 2))) (check-equal #t (hash-table=? default (alist->hash-table '((a . 1) (b . 4) (c . 9) (d . 16)) default) (let ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default))) (hash-table-map! (lambda (key val) (* val val)) htbl) htbl))) (check-equal #t (lset= equal? '((a . 1) (b . 2) (c . 3) (d . 4)) (hash-table-map->list (lambda (key val) (cons key val)) (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default)))) (check-equal #t (lset= equal? '((a . 1) (b . 2) (c . 3) (d . 4)) (hash-table-fold (lambda (key val lst) (cons (cons key val) lst)) '() (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default)))) (check-equal #t (hash-table=? default (alist->hash-table '((a . 1) (c . 3)) default) (let ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default))) (hash-table-prune! (lambda (key val) (even? val)) htbl) htbl))) (check-equal #t (let ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default))) (hash-table=? default htbl (hash-table-copy htbl)))) (check-equal #t (let ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default))) (hash-table=? default htbl (hash-table-copy htbl #t)))) (check-equal #t (let ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default))) (hash-table=? default htbl (hash-table-copy htbl #f)))) (check-error (assertion-violation hash-table-set!) (let ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default))) (hash-table-set! (hash-table-copy htbl) 'a 10))) (check-error (assertion-violation hash-table-set!) (let ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default))) (hash-table-set! (hash-table-copy htbl #f) 'a 10))) (check-equal #f (let* ((htbl (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default)) (copy (hash-table-copy htbl #t))) (hash-table-set! copy 'a 10) (hash-table=? default htbl copy))) (check-equal #t (lset= equal? '((a . 1) (b . 2) (c . 3) (d . 4)) (hash-table->alist (alist->hash-table '((a . 1) (b . 2) (c . 3) (d . 4)) default)))) (define (test-hash-set initial1 initial2 proc expected) (let ((htbl1 (alist->hash-table initial1 default)) (htbl2 (alist->hash-table initial2 default))) (if (not (eq? htbl1 (proc htbl1 htbl2))) #f (lset= equal? expected (hash-table->alist htbl1))))) (check-equal #t (test-hash-set '((a . 1) (b . 2) (c . 3)) '((c . 4) (d . 5) (e . 6)) hash-table-union! '((a . 1) (b . 2) (c . 3) (d . 5) (e . 6)))) (check-equal #t (test-hash-set '((a . 1) (b . 2) (c . 3)) '((c . 4) (d . 5) (e . 6)) hash-table-intersection! '((c . 3)))) (check-equal #t (test-hash-set '((a . 1) (b . 2) (c . 3)) '((c . 4) (d . 5) (e . 6)) hash-table-difference! '((a . 1) (b . 2)))) (check-equal #t (test-hash-set '((a . 1) (b . 2) (c . 3)) '((c . 4) (d . 5) (e . 6)) hash-table-xor! '((a . 1) (b . 2) (d . 5) (e . 6)))) (define (test-hash-table-add htbl size max make-key) (let ((vec (make-vector size #f))) (define (test-add n) (if (< n max) (let* ((idx (random-integer size)) (key (make-key idx))) (if (not (vector-ref vec idx)) (begin (vector-set! vec idx #t) (hash-table-set! htbl key idx))) (test-add (+ n 1))))) (test-add 0) vec)) (define (test-hash-table-ref htbl vec size make-key) (define (test-ref idx cnt) (if (< idx size) (begin (if (vector-ref vec idx) (let ((key (make-key idx))) (if (not (= (hash-table-ref/default htbl key 'fail) idx)) (begin (display "failed: hash-table-ref/default: ") (display idx) (newline) (test-ref (+ idx 1) cnt)) (test-ref (+ idx 1) (+ cnt 1)))) (test-ref (+ idx 1) cnt))) cnt)) (test-ref 0 0)) (define (make-string-key idx) (number->string idx)) (define htbl (make-hash-table string=? string-hash)) (define vec (test-hash-table-add htbl 1024 512 make-string-key)) (check-equal #t (= (test-hash-table-ref htbl vec 1024 make-string-key) (hash-table-size htbl))) ;; ;; ---- SRFI 133: Vector Library (R7RS-compatible) ---- ;; (import (scheme vector)) (check-equal #(a b c d) (vector-concatenate '(#(a b) #(c d)))) (check-equal #f (vector-empty? '#(a))) (check-equal #f (vector-empty? '#(()))) (check-equal #f (vector-empty? '#(#()))) (check-equal #t (vector-empty? '#())) (check-equal #t (vector= eq? '#(a b c d) '#(a b c d))) (check-equal #f (vector= eq? '#(a b c d) '#(a b d c))) (check-equal #f (vector= = '#(1 2 3 4 5) '#(1 2 3 4))) (check-equal #t (vector= = '#(1 2 3 4) '#(1 2 3 4))) (check-equal #t (vector= eq?)) (check-equal #t (vector= eq? '#(a))) (check-equal #f (vector= eq? (vector (vector 'a)) (vector (vector 'a)))) (check-equal #t (vector= equal? (vector (vector 'a)) (vector (vector 'a)))) (check-equal #t (vector= = '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 4))) (check-equal #f (vector= = '#(1 2 3 4 5) '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 4))) (check-equal #f (vector= = '#(1 2 3 4) '#(1 2 3) '#(1 2 3 4) '#(1 2 3 4))) (check-equal #f (vector= = '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 4 5) '#(1 2 3 4))) (check-equal #f (vector= = '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3))) (check-equal #f (vector= = '#(9 2 3 4) '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 4))) (check-equal #f (vector= = '#(1 2 3 4) '#(1 9 3 4) '#(1 2 3 4) '#(1 2 3 4))) (check-equal #f (vector= = '#(1 2 3 4) '#(1 2 3 4) '#(1 2 9 4) '#(1 2 3 4))) (check-equal #f (vector= = '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 4) '#(1 2 3 9))) (check-equal 6 (vector-fold (lambda (len str) (max (string-length str) len)) 0 '#("abc" "defghi" "jklmn" "pqrs"))) (check-equal (d c b a) (vector-fold (lambda (tail elt) (cons elt tail)) '() '#(a b c d))) (check-equal 4 (vector-fold (lambda (counter n) (if (even? n) (+ counter 1) counter)) 0 '#(1 2 3 4 5 6 7 8))) (check-equal (a b c d) (vector-fold-right (lambda (tail elt) (cons elt tail)) '() '#(a b c d))) (check-equal #(1 4 9 16) (vector-map (lambda (x) (* x x)) (vector-unfold (lambda (i x) (values x (+ x 1))) 4 1))) (check-equal #(5 8 9 8 5) (vector-map (lambda (x y) (* x y)) (vector-unfold (lambda (i x) (values x (+ x 1))) 5 1) (vector-unfold (lambda (i x) (values x (- x 1))) 5 5))) (check-equal #t (let* ((count 0) (ret (vector-map (lambda (ignored-elt) (set! count (+ count 1)) count) '#(a b)))) (or (equal? ret #(1 2)) (equal? ret #(2 1))))) (check-equal #(1 4 9 16) (vector-map (lambda (x) (* x x)) (vector-unfold (lambda (i x) (values x (+ x 1))) 4 1))) (check-equal #(5 8 9 8 5) (vector-map (lambda (x y) (* x y)) (vector-unfold (lambda (i x) (values x (+ x 1))) 5 1) (vector-unfold (lambda (i x) (values x (- x 1))) 5 5))) (check-equal #t (let* ((count 0) (ret (vector-map (lambda (ignored-elt) (set! count (+ count 1)) count) '#(a b)))) (or (equal? ret #(1 2)) (equal? ret #(2 1))))) (check-equal #(1 4 9 16) (let ((vec (vector-unfold (lambda (i x) (values x (+ x 1))) 4 1))) (vector-map! (lambda (x) (* x x)) vec) vec)) (check-equal #(5 8 9 8 5) (let ((vec1 (vector-unfold (lambda (i x) (values x (+ x 1))) 5 1)) (vec2 (vector-unfold (lambda (i x) (values x (- x 1))) 5 5))) (vector-map! (lambda (x y) (* x y)) vec1 vec2) vec1)) (check-equal #t (let* ((count 0) (ret (vector 'a 'b))) (vector-map! (lambda (ignored-elt) (set! count (+ count 1)) count) ret) (or (equal? ret #(1 2)) (equal? ret #(2 1))))) (check-equal 3 (vector-count even? '#(3 1 4 1 5 9 2 5 6))) (check-equal 2 (vector-count < '#(1 3 6 9) '#(2 4 6 8 10 12))) (check-equal #(3 4 8 9 14 23 25 30 36) (vector-cumulate + 0 '#(3 1 4 1 5 9 2 5 6))) (check-equal 2 (vector-index even? '#(3 1 4 1 5 9))) (check-equal 1 (vector-index < '#(3 1 4 1 5 9 2 5 6) '#(2 7 1 8 2))) (check-equal #f (vector-index = '#(3 1 4 1 5 9 2 5 6) '#(2 7 1 8 2))) (check-equal 5 (vector-index-right odd? '#(3 1 4 1 5 9 6))) (check-equal 3 (vector-index-right < '#(3 1 4 1 5) '#(2 7 1 8 2))) (check-equal 2 (vector-skip number? '#(1 2 a b 3 4 c d))) (check-equal 2 (vector-skip = '#(1 2 3 4 5) '#(1 2 -3 4))) (check-equal 7 (vector-skip-right number? '#(1 2 a b 3 4 c d))) (check-equal 3 (vector-skip-right = '#(1 2 3 4 5) '#(1 2 -3 -4 5))) (check-equal (#f 0 1 2 3 4 5 6 7 #f) (let ((vec '#(1 2 3 4 5 6 7 8))) (map (lambda (val) (vector-binary-search vec val -)) '(0 1 2 3 4 5 6 7 8 9)))) (check-equal (#f 0 1 2 3 4 5 6 #f) (let ((vec '#(1 2 3 4 5 6 7))) (map (lambda (val) (vector-binary-search vec val -)) '(0 1 2 3 4 5 6 7 8)))) (check-equal #t (vector-any number? '#(1 2 x y z))) (check-equal #t (vector-any < '#(1 2 3 4 5) '#(2 1 3 4 5))) (check-equal #f (vector-any number? '#(a b c d e))) (check-equal #f (vector-any > '#(1 2 3 4 5) '#(1 2 3 4 5))) (check-equal yes (vector-any (lambda (x) (if (number? x) 'yes #f)) '#(1 2 x y z))) (check-equal #f (vector-every number? '#(1 2 x y z))) (check-equal #t (vector-every number? '#(1 2 3 4 5))) (check-equal #f (vector-every < '#(1 2 3) '#(2 3 3))) (check-equal #t (vector-every < '#(1 2 3) '#(2 3 4))) (check-equal nope (vector-every (lambda (x) (if (= x 1) 'yeah 'nope)) '#(1 2 3 4 5))) (check-equal #(2 1 3) (let ((v (vector 1 2 3))) (vector-swap! v 0 1) v)) (check-equal #(1 3 2) (let ((v (vector 1 2 3))) (vector-swap! v 2 1) v)) (check-equal #(4 3 2 1) (let ((v (vector 1 2 3 4))) (vector-reverse! v) v)) (check-equal #(5 4 3 2 1) (let ((v (vector 1 2 3 4 5))) (vector-reverse! v) v)) (check-equal #(1 4 3 2) (let ((v (vector 1 2 3 4))) (vector-reverse! v 1) v)) (check-equal #(1 5 4 3 2) (let ((v (vector 1 2 3 4 5))) (vector-reverse! v 1) v)) (check-equal #(1 3 2 4) (let ((v (vector 1 2 3 4))) (vector-reverse! v 1 3) v)) (check-equal #(1 4 3 2 5) (let ((v (vector 1 2 3 4 5))) (vector-reverse! v 1 4) v)) (check-equal (#(1 2 3 a b c d) 3) (call-with-values (lambda () (vector-partition number? '#(a 1 b 2 c 3 d))) (lambda (vec cnt) (list vec cnt)))) (check-equal (#(1 2 3 4 5) 5) (call-with-values (lambda () (vector-partition number? '#(1 2 3 4 5))) (lambda (vec cnt) (list vec cnt)))) (check-equal (#(a b c d) 0) (call-with-values (lambda () (vector-partition number? '#(a b c d))) (lambda (vec cnt) (list vec cnt)))) (check-equal #(0 -1 -2 -3 -4 -5 -6 -7 -8 -9) (vector-unfold (lambda (i x) (values x (- x 1))) 10 0)) (check-equal #(0 1 2 3 4 5) (vector-unfold values 6)) (check-equal #(0 3 4 9 8 15 12 21) (vector-unfold (lambda (i x y z) (values (if (even? x) y z) (+ x 1) (+ y 2) (+ z 3))) 8 0 0 0)) (check-equal #(0 0 3 4 9 8 15 12 21 0) (let ((vec (make-vector 10 0))) (vector-unfold! (lambda (i x y z) (values (if (even? x) y z) (+ x 1) (+ y 2) (+ z 3))) vec 1 9 0 0 0) vec)) (check-equal #((0 . 4) (1 . 3) (2 . 2) (3 . 1) (4 . 0)) (vector-unfold-right (lambda (i x) (values (cons i x) (+ x 1))) 5 0)) (check-equal #(5 4 3 2 1 0) (let ((vec (vector 0 1 2 3 4 5))) (vector-unfold-right (lambda (i x) (values (vector-ref vec x) (+ x 1))) (vector-length vec) 0))) (check-equal #(1 2 3 4) (vector-reverse-copy '#(5 4 3 2 1 0) 1 5)) (check-equal #(10 5 4 3 2 60) (let ((vec (vector 10 20 30 40 50 60))) (vector-reverse-copy! vec 1 #(0 1 2 3 4 5 6 7 8) 2 6) vec)) (check-equal #(a b h i) (vector-append-subvectors '#(a b c d e) 0 2 '#(f g h i j) 2 4)) (check-equal #(b c d h i j q r) (vector-append-subvectors '#(a b c d e) 1 4 '#(f g h i j) 2 5 #(k l m n o p q r s t) 6 8)) (check-equal (3 2 1) (reverse-vector->list '#(1 2 3))) (check-equal (3 2) (reverse-vector->list '#(1 2 3) 1)) (check-equal (2 1) (reverse-vector->list '#(1 2 3) 0 2)) (check-equal #(3 2 1) (reverse-list->vector '(1 2 3))) ;; ;; ---- SRFI 14: Character-set Library ---- ;; (import (scheme charset)) (check-equal #t (char-set? (char-set #\A))) (check-equal #f (char-set? "abcd")) (check-equal #f (char-set? #\A)) (check-equal #t (char-set=)) (check-equal #t (char-set= (char-set #\A))) (check-equal #t (char-set= (char-set) (char-set))) (check-equal #t (char-set= (char-set #\a #\Z) (char-set #\a #\Z))) (check-equal #t (char-set= (char-set #\a #\z #\A #\Z) (char-set #\A #\z #\a #\Z))) (check-equal #f (char-set= (char-set #\a #\^ #\Z) (char-set #\a #\Z))) (check-equal #f (char-set= (char-set #\a #\Z) (char-set #\a #\^ #\Z))) (check-equal #f (char-set= (char-set #\A #\Z) (char-set #\a #\Z))) (check-equal #f (char-set= (char-set #\a #\Z) (char-set #\A #\Z))) (check-equal #f (char-set= (char-set #\a #\z) (char-set #\a #\Z))) (check-equal #f (char-set= (char-set #\a #\Z) (char-set #\a #\z))) (check-equal #t (char-set= (char-set #\a #\b #\c #\d) (char-set #\a #\b #\c #\d))) (check-equal #f (char-set= (char-set #\a #\b #\d) (char-set #\a #\b #\c #\d))) (check-equal #t (char-set= (char-set #\a #\A #\B #\C #\D #\E #\Z) (char-set #\a #\A #\B #\C #\D #\E #\Z))) (check-equal #t (char-set= (char-set #\a #\b #\c) (char-set #\a #\b #\c) (char-set #\a #\b #\c))) (check-equal #f (char-set= (char-set #\a #\b #\c) (char-set #\a #\b #\c) (char-set #\a #\b))) (check-equal #t (char-set<=)) (check-equal #t (char-set<= (char-set #\A))) (check-equal #t (char-set<= (char-set) (char-set))) (check-equal #t (char-set<= (char-set #\a #\Z) (char-set #\a #\Z))) (check-equal #t (char-set<= (char-set #\a #\Z) (char-set #\a #\A #\B #\C #\Z))) (check-equal #f (char-set<= (char-set #\a #\z #\Z) (char-set #\a #\A #\B #\C #\Z))) (check-equal #t (char-set<= (char-set) (char-set #\a))) (check-equal #t (char-set<= (char-set) (char-set #\a) (char-set #\a #\b) (char-set #\a #\b #\c))) (check-equal #t (char-set<= (char-set #\l #\m #\n) (char-set #\a #\b #\c #\l #\m #\n #\x #\y #\z))) (check-equal #t (char-set<= (char-set #\l #\m #\n) (char-set #\a #\b #\c #\k #\l #\m #\n #\x #\y #\z))) (check-equal #t (char-set<= (char-set #\l #\m #\n) (char-set #\a #\b #\c #\k #\l #\m #\n #\o #\x #\y #\z))) (check-equal #f (char-set<= (char-set #\l #\m #\n) (char-set #\a #\b #\c #\l #\m #\x #\y #\z))) (check-equal #f (char-set<= (char-set #\l #\m #\n) (char-set #\a #\b #\c #\k #\l #\n #\x #\y #\z))) (check-equal #f (char-set<= (char-set #\l #\m #\n) (char-set #\a #\b #\c #\k #\l #\m #\o #\x #\y #\z))) (check-equal #t (>= (char-set-hash (char-set)) 0)) (check-equal #t (>= (char-set-hash (char-set #\a #\b #\c)) 0)) (check-equal #t (= (char-set-hash (char-set)) (char-set-hash (char-set)))) (check-equal #t (= (char-set-hash (char-set #\a #\b #\c)) (char-set-hash (char-set #\a #\b #\c)))) (check-equal #f (= (char-set-hash (char-set #\a #\b #\c)) (char-set-hash (char-set #\x #\y #\z)))) (check-equal #f (= (char-set-hash (char-set #\a #\b #\c) 123) (char-set-hash (char-set #\a #\b #\c)))) (check-equal #t (end-of-char-set? (char-set-cursor (char-set)))) (check-equal #f (end-of-char-set? (char-set-cursor (char-set #\A)))) (check-equal #\A (let* ((cset (char-set #\A)) (cursor (char-set-cursor cset))) (char-set-ref cset cursor))) (check-equal (#\A #\B #\C #\Q #\X #\a #\d #\e #\x #\y #\z) (let ((cset (char-set #\Q #\d #\C #\a #\z #\X #\x #\y #\e #\B #\A))) (define (walk cursor) (if (end-of-char-set? cursor) '() (cons (char-set-ref cset cursor) (walk (char-set-cursor-next cset cursor))))) (walk (char-set-cursor cset)))) (check-equal (#\c #\b #\a) (char-set-fold cons '() (char-set #\a #\b #\c))) (check-equal 5 (char-set-fold (lambda (ch cnt) (+ cnt 1)) 0 (char-set #\1 #\2 #\3 #\4 #\5))) (check-equal 3 (char-set-fold (lambda (ch cnt) (if (char-numeric? ch) (+ cnt 1) cnt)) 0 (char-set #\a #\2 #\b #\4 #\c #\6 #\d))) (check-equal #t (char-set= (char-set #\a #\b #\y #\z) (char-set-unfold car null? cdr '(#\a #\b #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\y #\z) (char-set-unfold car null? cdr '(#\a #\b) (char-set #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\y #\z) (char-set-unfold! car null? cdr '(#\a #\b) (char-set #\y #\z)))) (check-equal #t (char-set= (char-set #\A #\B #\C) (char-set-map char-upcase (char-set #\a #\b #\c)))) (check-equal (#\A #\B #\C #\D) (let ((lst '())) (char-set-for-each (lambda (ch) (set! lst (cons ch lst))) (char-set #\A #\B #\C #\D)) lst)) (check-equal #t (char-set= (char-set #\A #\B #\C) (char-set-map char-upcase (char-set #\a #\b #\c)))) (check-equal #t (let ((cset (char-set #\a #\B #\c #\D))) (char-set= cset (char-set-copy cset)))) (check-equal #t (char-set= (list->char-set '(#\1 #\2 #\3 #\a #\b #\c)) (string->char-set "abc123"))) (check-equal #t (char-set= (list->char-set '(#\1 #\2 #\3) (char-set #\a #\b #\c)) (char-set #\1 #\2 #\3 #\a #\b #\c))) (check-equal #t (char-set= (string->char-set "123" (char-set #\a #\b #\c)) (char-set #\1 #\2 #\3 #\a #\b #\c))) (check-equal #t (char-set= (list->char-set '(#\1 #\2 #\3 #\a #\b #\c) (char-set #\x #\y #\z)) (char-set #\x #\y #\z #\1 #\2 #\3 #\a #\b #\c))) (check-equal #t (char-set= (string->char-set "xyz123" (char-set #\a #\b #\c)) (char-set #\x #\y #\z #\1 #\2 #\3 #\a #\b #\c))) (check-equal #t (char-set= (char-set #\2 #\4 #\6) (char-set-filter char-numeric? (char-set #\a #\2 #\b #\4 #\c #\6 #\d)))) (check-equal #t (char-set= (char-set #\2 #\4 #\6 #\x #\y #\z) (char-set-filter char-numeric? (char-set #\a #\2 #\b #\4 #\c #\6 #\d) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\2 #\4 #\6 #\x #\y #\z) (char-set-filter! char-numeric? (char-set #\a #\2 #\b #\4 #\c #\6 #\d) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c) (->char-set "abc"))) (check-equal #t (char-set= (char-set #\a) (->char-set #\a))) (check-equal #t (char-set= (char-set #\a #\b #\c) (->char-set (char-set #\a #\b #\c)))) (check-equal 0 (char-set-size (char-set))) (check-equal 5 (char-set-size (char-set #\a #\b #\c #\d #\e))) (check-equal 3 (char-set-count char-numeric? (char-set #\a #\2 #\b #\4 #\c #\6 #\d))) (check-equal (#\c #\b #\a) (char-set->list (char-set #\a #\b #\c))) (check-equal "cba" (char-set->string (char-set #\a #\b #\c))) (check-equal #t (char-set-contains? (char-set #\a #\b #\c) #\b)) (check-equal #f (char-set-contains? (char-set #\a #\b #\c) #\B)) (check-equal #f (char-set-every char-numeric? (char-set #\a #\2 #\b #\4 #\c #\6 #\d))) (check-equal #t (char-set-every char-numeric? (char-set #\2 #\4 #\6))) (check-equal #t (char-set-any char-numeric? (char-set #\a #\2 #\b #\4 #\c #\6 #\d))) (check-equal #\A (char-set-any (lambda (ch) (and (char-upper-case? ch) ch)) (char-set #\a #\b #\A))) (check-equal #t (char-set= (char-set #\a #\b #\c #\x #\y #\z) (char-set-adjoin (char-set #\x #\y #\z) #\a #\b #\c))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-delete (char-set #\a #\b #\c #\x #\y #\z) #\a #\b #\c))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-delete (char-set #\x #\y #\z) #\a #\b #\c))) (check-equal #t (char-set= char-set:empty (char-set-union))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-union (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\x #\y #\z) (char-set-union (char-set #\a #\b #\c) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\x #\y #\z) (char-set-union (char-set #\a #\b #\c #\x #\y #\z) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\m #\n #\l #\c #\x #\y #\z) (char-set-union (char-set #\a #\b #\c) (char-set #\x #\y #\z) (char-set #\m #\n #\l)))) (check-equal #t (char-set= (char-set #\a #\b #\c) (char-set-union (char-set #\a #\b #\c) char-set:empty))) (check-equal #t (char-set= (char-set #\a #\b #\m #\n #\l #\c #\x #\y #\z) (char-set-union char-set:empty (char-set #\a #\b #\c) char-set:empty (char-set #\x #\y #\z) char-set:empty (char-set #\m #\n #\l)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-union! (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\x #\y #\z) (char-set-union! (char-set #\a #\b #\c) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\x #\y #\z) (char-set-union! (char-set #\a #\b #\c #\x #\y #\z) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\m #\n #\l #\c #\x #\y #\z) (char-set-union! (char-set #\a #\b #\c) (char-set #\x #\y #\z) (char-set #\m #\n #\l)))) (check-equal #t (char-set= char-set:full (char-set-intersection))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection (char-set #\x #\y #\z)))) (check-equal #t (char-set= char-set:empty (char-set-intersection (char-set #\a #\b #\c) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection (char-set #\a #\b #\c #\x #\y #\z) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection (char-set #\x #\y #\z) (char-set #\a #\b #\c #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection char-set:ascii (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\A #\B #\C #\X #\Y #\Z) (char-set-intersection char-set:ascii (char-set #\A #\B #\C #\X #\Y #\Z)))) (check-equal #t (char-set= (char-set #\A #\B #\C #\X #\Y #\Z) (char-set-intersection (char-set #\A #\B #\C #\X #\Y #\Z) char-set:ascii))) (check-equal #t (char-set= (char-set #\A #\B #\C #\X #\Y #\Z) (char-set-intersection char-set:ascii (char-set #\A #\B #\C) (char-set #\X #\Y #\Z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection! (char-set #\x #\y #\z)))) (check-equal #t (char-set= char-set:empty (char-set-intersection! (char-set #\a #\b #\c) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection! (char-set #\a #\b #\c #\x #\y #\z) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection! (char-set #\x #\y #\z) (char-set #\a #\b #\c #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-intersection! char-set:ascii (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\A #\B #\C #\X #\Y #\Z) (char-set-intersection! char-set:ascii (char-set #\A #\B #\C #\X #\Y #\Z)))) (check-equal #t (char-set= (char-set #\A #\B #\C #\X #\Y #\Z) (char-set-intersection! (char-set #\A #\B #\C #\X #\Y #\Z) char-set:ascii))) (check-equal #t (char-set= (char-set #\A #\B #\C #\X #\Y #\Z) (char-set-intersection! char-set:ascii (char-set #\A #\B #\C) (char-set #\X #\Y #\Z)))) (check-equal #t (char-set= (char-set) (char-set-intersection (char-set #\a #\b #\c) (char-set #\d #\f #\g)))) (check-equal #t (char-set= (char-set) (char-set-intersection (char-set #\d #\f #\g) (char-set #\a #\b #\c)))) (check-equal #t (char-set= (char-set #\d #\e #\h #\i) (char-set-intersection (char-set #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j) (char-set #\d #\e #\h #\i)))) (check-equal #t (char-set= (char-set #\d #\e #\h #\i #\j) (char-set-intersection (char-set #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j) (char-set #\A #\B #\C #\d #\e #\h #\i #\j #\k #\l)))) (check-equal #t (char-set= (char-set #\d #\e #\h #\i) (char-set-intersection (char-set #\d #\e #\h #\i) (char-set #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j)))) (check-equal #t (char-set= (char-set #\d #\e #\h #\i #\j) (char-set-intersection (char-set #\A #\B #\C #\d #\e #\h #\i #\j #\k #\l) (char-set #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j)))) (check-equal #t (char-set= (char-set #\a #\b #\c) (char-set-difference (char-set #\a #\b #\c)))) (check-equal #t (char-set= (char-set #\a #\b #\c) (char-set-difference (char-set #\a #\b #\c) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-difference (char-set #\x #\y #\z) (char-set #\a #\b #\c)))) (check-equal #t (char-set= (char-set #\a #\b #\c) (char-set-difference (char-set #\a #\b #\c #\x #\y #\z) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-difference (char-set #\a #\b #\c #\x #\y #\z) (char-set #\a #\b #\c)))) (check-equal #t (char-set= char-set:empty (char-set-difference (char-set #\x #\y #\z) (char-set #\a #\b #\c #\x #\y #\z)))) (check-equal #t (char-set= char-set:empty (char-set-difference (char-set #\a #\b #\c) (char-set #\a #\b #\c #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\l #\m #\n) (char-set-difference (char-set #\a #\b #\c #\l #\m #\n #\x #\y #\z) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\l #\n) (char-set-difference (char-set #\a #\b #\c #\l #\m #\n #\x #\y #\z) (char-set #\m #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\A #\B #\C #\x #\y #\z) (char-set-difference (char-set #\A #\B #\C #\a #\b #\c #\x #\y #\z) (char-set #\a #\b #\c)))) (check-equal #t (char-set= char-set:empty (char-set-xor))) (check-equal #t (char-set= (char-set #\x #\y #\z) (char-set-xor (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\x #\y #\z) (char-set-xor (char-set #\a #\b #\c) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\c) (char-set-xor (char-set #\a #\b #\c #\x #\y #\z) (char-set #\x #\y #\z)))) (check-equal #t (char-set= (char-set #\a #\b #\m #\n #\l #\c #\x #\y #\z) (char-set-xor (char-set #\a #\b #\c) (char-set #\x #\y #\z) (char-set #\m #\n #\l)))) (check-equal #t (char-set= (char-set #\a #\b #\c #\n #\l #\y #\z) (char-set-xor (char-set #\a #\b #\c #\m #\x) (char-set #\x #\y #\z) (char-set #\m #\n #\l)))) (check-equal 128 (char-set-size char-set:ascii)) (check-equal #t (char-set-contains? char-set:ascii #\a)) (check-equal #f (char-set-contains? char-set:ascii (integer->char 128))) (check-equal 0 (char-set-size char-set:empty)) (check-equal #f (char-set-contains? char-set:empty #\a)) ;; From Chibi Scheme (check-equal #f (char-set? 5)) (check-equal #t (char-set? (char-set #\a #\e #\i #\o #\u))) (check-equal #t (char-set=)) (check-equal #t (char-set= (char-set))) (check-equal #t (char-set= (char-set #\a #\e #\i #\o #\u) (string->char-set "ioeauaiii"))) (check-equal #f (char-set= (char-set #\e #\i #\o #\u) (string->char-set "ioeauaiii"))) (check-equal #t (char-set<=)) (check-equal #t (char-set<= (char-set))) (check-equal #t (char-set<= (char-set #\a #\e #\i #\o #\u) (string->char-set "ioeauaiii"))) (check-equal #t (char-set<= (char-set #\e #\i #\o #\u) (string->char-set "ioeauaiii"))) (check-equal #t (<= 0 (char-set-hash char-set:ascii 100) 99)) (check-equal 4 (char-set-fold (lambda (c i) (+ i 1)) 0 (char-set #\e #\i #\o #\u #\e #\e))) (check-equal #t (char-set= (string->char-set "eiaou2468013579999") (char-set-unfold car null? cdr '(#\a #\e #\i #\o #\u #\u #\u) (char-set-intersection char-set:ascii (char-set #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9))))) (check-equal #t (char-set= (string->char-set "eiaou246801357999") (char-set-unfold! car null? cdr '(#\a #\e #\i #\o #\u) (string->char-set "0123456789")))) (check-equal #f (char-set= (string->char-set "eiaou246801357") (char-set-unfold! car null? cdr '(#\a #\e #\i #\o #\u) (string->char-set "0123456789")))) (check-equal #t (char-set= (string->char-set "97531") (let ((cs (string->char-set "0123456789"))) (char-set-for-each (lambda (c) (set! cs (char-set-delete cs c))) (string->char-set "02468000")) cs))) (check-equal #f (let ((cs (string->char-set "0123456789"))) (char-set-for-each (lambda (c) (set! cs (char-set-delete cs c))) (string->char-set "02468")) (char-set= cs (string->char-set "7531")))) (check-equal #t (char-set= (string->char-set "IOUAEEEE") (char-set-map char-upcase (string->char-set "aeiou")))) (check-equal #f (char-set= (char-set-map char-upcase (string->char-set "aeiou")) (string->char-set "OUAEEEE"))) (check-equal #t (char-set= (string->char-set "aeiou") (char-set-copy (string->char-set "aeiou")))) (check-equal #t (char-set= (string->char-set "xy") (char-set #\x #\y))) (check-equal #f (char-set= (char-set #\x #\y #\z) (string->char-set "xy"))) (check-equal #t (char-set= (string->char-set "xy") (list->char-set '(#\x #\y)))) (check-equal #f (char-set= (string->char-set "axy") (list->char-set '(#\x #\y)))) (check-equal #t (char-set= (string->char-set "xy12345") (list->char-set '(#\x #\y) (string->char-set "12345")))) (check-equal #f (char-set= (string->char-set "y12345") (list->char-set '(#\x #\y) (string->char-set "12345")))) (check-equal #t (char-set= (string->char-set "xy12345") (list->char-set! '(#\x #\y) (string->char-set "12345")))) (check-equal #f (char-set= (string->char-set "y12345") (list->char-set! '(#\x #\y) (string->char-set "12345")))) (define (vowel? ch) (member ch '(#\a #\e #\i #\o #\u))) (check-equal #t (char-set= (string->char-set "aeiou12345") (char-set-filter vowel? char-set:ascii (string->char-set "12345")))) (check-equal #f (char-set= (string->char-set "aeou12345") (char-set-filter vowel? char-set:ascii (string->char-set "12345")))) (check-equal #t (char-set= (string->char-set "aeiou12345") (char-set-filter! vowel? char-set:ascii (string->char-set "12345")))) (check-equal #f (char-set= (string->char-set "aeou12345") (char-set-filter! vowel? char-set:ascii (string->char-set "12345")))) (check-equal #t (char-set= (string->char-set "abcdef12345") (ucs-range->char-set 97 103 #t (string->char-set "12345")))) (check-equal #f (char-set= (string->char-set "abcef12345") (ucs-range->char-set 97 103 #t (string->char-set "12345")))) (check-equal #t (char-set= (string->char-set "abcdef12345") (ucs-range->char-set! 97 103 #t (string->char-set "12345")))) (check-equal #f (char-set= (string->char-set "abcef12345") (ucs-range->char-set! 97 103 #t (string->char-set "12345")))) (check-equal #t (char-set= (->char-set #\x) (->char-set "x") (->char-set (char-set #\x)))) (check-equal #f (char-set= (->char-set #\x) (->char-set "y") (->char-set (char-set #\x)))) (check-equal 10 (char-set-size (char-set-intersection char-set:ascii (string->char-set "0123456789")))) (check-equal 5 (char-set-count vowel? char-set:ascii)) (check-equal (#\x) (char-set->list (char-set #\x))) (check-equal #f (equal? '(#\X) (char-set->list (char-set #\x)))) (check-equal "x" (char-set->string (char-set #\x))) (check-equal #f (equal? "X" (char-set->string (char-set #\x)))) (check-equal #t (char-set-contains? (->char-set "xyz") #\x)) (check-equal #f (char-set-contains? (->char-set "xyz") #\a)) (check-equal #t (char-set-every char-lower-case? (->char-set "abcd"))) (check-equal #f (char-set-every char-lower-case? (->char-set "abcD"))) (check-equal #t (char-set-any char-lower-case? (->char-set "abcd"))) (check-equal #f (char-set-any char-lower-case? (->char-set "ABCD"))) (check-equal #t (char-set= (->char-set "ABCD") (let ((cs (->char-set "abcd"))) (let lp ((cur (char-set-cursor cs)) (ans '())) (if (end-of-char-set? cur) (list->char-set ans) (lp (char-set-cursor-next cs cur) (cons (char-upcase (char-set-ref cs cur)) ans))))))) (check-equal #t (char-set= (->char-set "123xa") (char-set-adjoin (->char-set "123") #\x #\a))) (check-equal #f (char-set= (char-set-adjoin (->char-set "123") #\x #\a) (->char-set "123x"))) (check-equal #t (char-set= (->char-set "123xa") (char-set-adjoin! (->char-set "123") #\x #\a))) (check-equal #f (char-set= (char-set-adjoin! (->char-set "123") #\x #\a) (->char-set "123x"))) (check-equal #t (char-set= (->char-set "13") (char-set-delete (->char-set "123") #\2 #\a #\2))) (check-equal #f (char-set= (char-set-delete (->char-set "123") #\2 #\a #\2) (->char-set "13a"))) (check-equal #t (char-set= (->char-set "13") (char-set-delete! (->char-set "123") #\2 #\a #\2))) (check-equal #f (char-set= (char-set-delete! (->char-set "123") #\2 #\a #\2) (->char-set "13a"))) (define digit (char-set #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)) (define hex-digit (char-set #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\a #\b #\c #\d #\e #\f #\A #\B #\C #\D #\E #\F)) (check-equal #t (char-set= (->char-set "abcdefABCDEF") (char-set-intersection hex-digit (char-set-complement digit)))) (check-equal #t (char-set= (->char-set "abcdefABCDEF") (char-set-intersection! (char-set-complement! (->char-set "0123456789")) hex-digit))) (check-equal #t (char-set= (->char-set "abcdefABCDEFghijkl0123456789") (char-set-union hex-digit (->char-set "abcdefghijkl")))) (check-equal #t (char-set= (->char-set "abcdefABCDEFghijkl0123456789") (char-set-union! (->char-set "abcdefghijkl") hex-digit))) (check-equal #t (char-set= (->char-set "ghijklmn") (char-set-difference (->char-set "abcdefghijklmn") hex-digit))) (check-equal #t (char-set= (->char-set "ghijklmn") (char-set-difference! (->char-set "abcdefghijklmn") hex-digit))) (check-equal #t (char-set= (->char-set "abcdefABCDEF") (char-set-xor (->char-set "0123456789") hex-digit))) (check-equal #t (char-set= (->char-set "abcdefABCDEF") (char-set-xor! (->char-set "0123456789") hex-digit))) (define letter (string->char-set "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")) (check-equal (#t . #t) (call-with-values (lambda () (char-set-diff+intersection hex-digit letter)) (lambda (d i) (cons (char-set= d (->char-set "0123456789")) (char-set= i (->char-set "abcdefABCDEF")))))) (check-equal (#t . #t) (call-with-values (lambda () (char-set-diff+intersection! (char-set-copy hex-digit) (char-set-copy letter))) (lambda (d i) (cons (char-set= d (->char-set "0123456789")) (char-set= i (->char-set "abcdefABCDEF")))))) ;; ;; ---- SRFI 151: Bitwise Operations ;; (import (srfi 151)) (check-equal -11 (bitwise-not 10)) (check-equal 36 (bitwise-not -37)) (check-equal -1 (bitwise-eqv)) (check-equal 123 (bitwise-eqv 123)) (check-equal -123 (bitwise-eqv -123)) (check-equal 11 (bitwise-ior 3 10)) (check-equal 10 (bitwise-and 11 26)) (check-equal 9 (bitwise-xor 3 10)) (check-equal -42 (bitwise-eqv 37 12)) (check-equal 4 (bitwise-and 37 12)) (check-equal -11 (bitwise-nand 11 26)) (check-equal -28 (bitwise-nor 11 26)) (check-equal 16 (bitwise-andc1 11 26)) (check-equal 1 (bitwise-andc2 11 26)) (check-equal -2 (bitwise-orc1 11 26)) (check-equal -17 (bitwise-orc2 11 26)) (check-equal 32 (arithmetic-shift 8 2)) (check-equal 4 (arithmetic-shift 4 0)) (check-equal 4 (arithmetic-shift 8 -1)) (check-equal -79 (arithmetic-shift -100000000000000000000000000000000 -100)) (check-equal 0 (bit-count 0)) (check-equal 0 (bit-count -1)) (check-equal 3 (bit-count 7)) (check-equal 3 (bit-count 13)) (check-equal 2 (bit-count -13)) (check-equal 4 (bit-count 30)) (check-equal 4 (bit-count -30)) (check-equal 1 (bit-count (expt 2 100))) (check-equal 100 (bit-count (- (expt 2 100)))) (check-equal 1 (bit-count (- (+ (expt 2 100) 1)))) (check-equal 0 (integer-length 0)) (check-equal 1 (integer-length 1)) (check-equal 0 (integer-length -1)) (check-equal 3 (integer-length 7)) (check-equal 3 (integer-length -7)) (check-equal 4 (integer-length 8)) (check-equal 3 (integer-length -8)) (check-equal 9 (bitwise-if 3 1 8)) (check-equal 0 (bitwise-if 3 8 1)) (check-equal 3 (bitwise-if 1 1 2)) (check-equal #b00110011 (bitwise-if #b00111100 #b11110000 #b00001111)) (check-equal #f (bit-set? 1 1)) (check-equal #t (bit-set? 0 1)) (check-equal #t (bit-set? 3 10)) (check-equal #t (bit-set? 1000000 -1)) (check-equal #t (bit-set? 2 6)) (check-equal #f (bit-set? 0 6)) (check-equal #b1 (copy-bit 0 0 #t)) (check-equal #b100 (copy-bit 2 0 #t)) (check-equal #b1011 (copy-bit 2 #b1111 #f)) (check-equal #b1 (bit-swap 0 2 4)) (check-equal #t (any-bit-set? 3 6)) (check-equal #f (any-bit-set? 3 12)) (check-equal #t (every-bit-set? 4 6)) (check-equal #f (every-bit-set? 7 6)) (check-equal 0 (first-set-bit 1)) (check-equal 1 (first-set-bit 2)) (check-equal -1 (first-set-bit 0)) (check-equal 3 (first-set-bit 40)) (check-equal 2 (first-set-bit -28)) (check-equal 99 (first-set-bit (expt 2 99))) (check-equal 99 (first-set-bit (expt -2 99))) (check-equal #b1010 (bit-field #b1101101010 0 4)) (check-equal #b101101 (bit-field #b1101101010 3 9)) (check-equal #b10110 (bit-field #b1101101010 4 9)) (check-equal #b110110 (bit-field #b1101101010 4 10)) (check-equal 0 (bit-field 6 0 1)) (check-equal 3 (bit-field 6 1 3)) (check-equal 1 (bit-field 6 2 999)) (check-equal 1 (bit-field #x100000000000000000000000000000000 128 129)) (check-equal #t (bit-field-any? #b1001001 1 6)) (check-equal #f (bit-field-any? #b1000001 1 6)) (check-equal #t (bit-field-every? #b1011110 1 5)) (check-equal #f (bit-field-every? #b1011010 1 5)) (check-equal #b100000 (bit-field-clear #b101010 1 4)) (check-equal #b101110 (bit-field-set #b101010 1 4)) (check-equal #b100100 (bit-field-replace #b101010 #b010 1 4)) (check-equal #b111 (bit-field-replace #b110 1 0 1)) (check-equal #b110 (bit-field-replace #b110 1 1 2)) (check-equal #b1001 (bit-field-replace-same #b1111 #b0000 1 3)) (check-equal #b110 (bit-field-rotate #b110 0 0 10)) (check-equal #b110 (bit-field-rotate #b110 0 0 256)) (check-equal 1 (bit-field-rotate #x100000000000000000000000000000000 1 0 129)) (check-equal #b110 (bit-field-rotate #b110 1 1 2)) (check-equal #b1010 (bit-field-rotate #b110 1 2 4)) (check-equal #b1011 (bit-field-rotate #b0111 -1 1 4)) (check-equal 6 (bit-field-reverse 6 1 3)) (check-equal 12 (bit-field-reverse 6 1 4)) (check-equal #x80000000 (bit-field-reverse 1 0 32)) (check-equal #x40000000 (bit-field-reverse 1 0 31)) (check-equal #x20000000 (bit-field-reverse 1 0 30)) (check-equal 5 (bit-field-reverse #x140000000000000000000000000000000 0 129)) (check-equal (#t #f #t #f #t #t #t) (bits->list #b1110101)) (check-equal (#t #t #f #f #f) (bits->list 3 5)) (check-equal (#f #t #t #f) (bits->list 6 4)) (check-equal #(#t #f #t #f #t #t #t) (bits->vector #b1110101)) (check-equal #b1110101 (list->bits '(#t #f #t #f #t #t #t))) (check-equal #b111010100 (list->bits '(#f #f #t #f #t #f #t #t #t))) (check-equal 6 (list->bits '(#f #t #t))) (check-equal 6 (list->bits '(#f #t #t #f))) (check-equal 12 (list->bits '(#f #f #t #t))) (check-equal #b1110101 (vector->bits '#(#t #f #t #f #t #t #t))) (check-equal #b111010100 (vector->bits '#(#f #f #t #f #t #f #t #t #t))) (check-equal 6 (vector->bits '#(#f #t #t))) (check-equal 6 (vector->bits '#(#f #t #t #f))) (check-equal 12 (vector->bits '#(#f #f #t #t))) (check-equal #b1110101 (bits #t #f #t #f #t #t #t)) (check-equal #b111010100 (bits #f #f #t #f #t #f #t #t #t)) (check-equal (#t #f #t #f #t #t #t) (bitwise-fold cons '() #b1010111)) (define (bitcount n) (let ((count 0)) (bitwise-for-each (lambda (b) (if b (set! count (+ count 1)))) n) count)) (check-equal 0 (bitcount 0)) (check-equal 3 (bitcount 7)) (check-equal 3 (bitcount 13)) (check-equal 4 (bitcount 30)) (check-equal 1 (bitcount (expt 2 100))) (check-equal #b101010101 (bitwise-unfold (lambda (i) (= i 10)) even? (lambda (i) (+ i 1)) 0)) (define g (make-bitwise-generator #b110)) (check-equal #f (g)) (check-equal #t (g)) (check-equal #t (g)) (check-equal #f (g)) (check-equal #f (g)) (check-equal #f (g)) ;; ;; ---- SRFI 166: Monadic Formatting ---- ;; (import (srfi 166)) ; Parts from Chibi Scheme and https://gitlab.com/nieper/show (check-equal "" (show #f "")) (check-equal "\n" (show #f "\n")) (check-equal "\n\n" (show #f "\n\n")) (check-equal "hi" (show #f "hi")) (check-equal "\"hi\"" (show #f (written "hi"))) (check-equal "\"hi \\\"bob\\\"\"" (show #f (written "hi \"bob\""))) (check-equal "\"hello\\nworld\"" (show #f (written "hello\nworld"))) (check-equal "#(1 2 3)" (show #f (written '#(1 2 3)))) (check-equal "#(1)" (show #f (written '#(1)))) (check-equal "#()" (show #f (written '#()))) (check-equal "(1 2 3)" (show #f (written '(1 2 3)))) (check-equal "(1 2 . 3)" (show #f (written '(1 2 . 3)))) (check-equal "(1)" (show #f (written '(1)))) (check-equal "()" (show #f (written '()))) (check-equal "ABC" (show #f (upcased "abc"))) (check-equal "ABCDEF" (show #f (upcased "abc" "def"))) (check-equal "abcABCDEFghi" (show #f (downcased "ABC") (upcased "abc" "def") (downcased "GHI"))) (check-equal "a b" (show #f "a" (space-to 5) "b")) (check-equal "ab" (show #f "a" (space-to 0) "b")) (check-equal "abc def" (show #f "abc" (tab-to) "def")) (check-equal "abc def" (show #f "abc" (tab-to 5) "def")) (check-equal "abcdef" (show #f "abc" (tab-to 3) "def")) (check-equal "abc\ndef\n" (show #f "abc" nl "def" nl)) (check-equal "abc\ndef\n" (show #f "abc" fl "def" nl fl)) (check-equal "abc\ndef\n" (show #f "abc" fl "def" fl fl)) (check-equal "ab" (show #f "a" nothing "b")) (define ls '("abc" "def" "ghi")) (check-equal "abcdefghi" (show #f (let lp ((ls ls)) (if (pair? ls) (each (car ls) (lp (cdr ls))) nothing)))) (check-equal "abcdefghi" (show #f (let lp ((ls ls)) (if (pair? ls) (each (car ls) (fn () (lp (cdr ls)))) nothing)))) (check-equal "" (show #f nothing)) (check-equal "" (show #f nothing nothing "" nothing)) (check-equal "" (show #f (each nothing "" (with ((radix 16)) nothing)))) (check-equal "abcdefg" (show #f (with ((radix 16)) "abc" "defg"))) (check-equal "port? #t" (show #f "port? " (fn (port) (port? port)))) (check-equal "port? #t ****" (show #f "port? " (fn ((p port)) (port? p)) " ****")) (check-equal "column: 8" (show #f "column: " (fn (col) col))) (check-equal "column: 8, 11" (show #f "column: " (fn ((col1 col)) (each col1 ", " (fn ((col2 col)) col2))))) (check-equal "hi, bob!" (show #f (escaped "hi, bob!"))) (check-equal "hi, \\\"bob!\\\"" (show #f (escaped "hi, \"bob!\""))) (check-equal "hi, \\'bob\\'" (show #f (escaped "hi, 'bob'" #\'))) (check-equal "hi, ''bob''" (show #f (escaped "hi, 'bob'" #\' #\'))) (check-equal "hi, ''bob''" (show #f (escaped "hi, 'bob'" #\' #f))) (check-equal "line1\\nline2\\nkapow\\a\\n" (show #f (escaped "line1\nline2\nkapow\a\n" #\" #\\ (lambda (c) (case c ((#\newline) #\n) ((#\alarm) #\a) (else #f)))))) (check-equal "bob" (show #f (maybe-escaped "bob" char-whitespace?))) (check-equal "\"hi, bob!\"" (show #f (maybe-escaped "hi, bob!" char-whitespace?))) (check-equal "\"foo\\\"bar\\\"baz\"" (show #f (maybe-escaped "foo\"bar\"baz" char-whitespace?))) (check-equal "'hi, ''bob'''" (show #f (maybe-escaped "hi, 'bob'" (lambda (c) #f) #\' #f))) (check-equal "\\" (show #f (maybe-escaped "\\" (lambda (c) #f) #\' #f))) (check-equal "''''" (show #f (maybe-escaped "'" (lambda (c) #f) #\' #f))) (check-equal "-1" (show #f -1)) (check-equal "0" (show #f 0)) (check-equal "1" (show #f 1)) (check-equal "10" (show #f 10)) (check-equal "100" (show #f 100)) (check-equal "-1" (show #f (numeric -1))) (check-equal "0" (show #f (numeric 0))) (check-equal "1" (show #f (numeric 1))) (check-equal "10" (show #f (numeric 10))) (check-equal "100" (show #f (numeric 100))) (check-equal "57005" (show #f #xDEAD)) ;; radix (check-equal "#xdead" (show #f (with ((radix 16)) #xDEAD))) (check-equal "#xdead1234" (show #f (with ((radix 16)) #xDEAD) 1234)) (check-equal "de.ad" (show #f (with ((radix 16) (precision 2)) (numeric (/ #xDEAD #x100))))) (check-equal "d.ead" (show #f (with ((radix 16) (precision 3)) (numeric (/ #xDEAD #x1000))))) (check-equal "0.dead" (show #f (with ((radix 16) (precision 4)) (numeric (/ #xDEAD #x10000))))) (check-equal "1g" (show #f (with ((radix 17)) (numeric 33)))) (check-equal "(#x11 #x22 #x33)" (show #f (with ((radix 16)) '(#x11 #x22 #x33)))) (check-equal "0" (show #f (numeric 0 2))) (check-equal "0" (show #f (numeric 0 10))) (check-equal "0" (show #f (numeric 0 36))) (check-equal "0.0" (show #f (numeric 0.0 2))) (check-equal "0.0" (show #f (numeric 0.0 10))) (check-equal "0.0" (show #f (numeric 0.0 36))) (check-equal "1" (show #f (numeric 1 2))) (check-equal "1" (show #f (numeric 1 10))) (check-equal "1" (show #f (numeric 1 36))) (check-equal "1.0" (show #f (numeric 1.0 2))) (check-equal "1.0" (show #f (numeric 1.0 10))) (check-equal "1.0" (show #f (numeric 1.0 36))) (check-equal "0" (show #f (numeric 0.0 10 0))) (check-equal "0" (show #f (numeric 0.0 9 0))) (check-equal "3/4" (show #f (numeric #e.75))) (check-equal "0.0000000000000027" (show #f (numeric 1e-23 36))) (check-equal "100000000000000000000000000000000000000000000000000000000000000000000000000000000.0" (show #f (numeric (expt 2.0 80) 2))) ;; numeric, radix=2 (check-equal "10" (show #f (numeric 2 2))) (check-equal "10.0" (show #f (numeric 2.0 2))) (check-equal "11/10" (show #f (numeric 3/2 2))) (check-equal "1001" (show #f (numeric 9 2))) (check-equal "1001.0" (show #f (numeric 9.0 2))) (check-equal "1001.01" (show #f (numeric 9.25 2))) ;; numeric, radix=3 (check-equal "11" (show #f (numeric 4 3))) (check-equal "10.0" (show #f (numeric 3.0 3))) (check-equal "11/10" (show #f (numeric 4/3 3))) (check-equal "1001" (show #f (numeric 28 3))) (check-equal "1001.0" (show #f (numeric 28.0 3))) (check-equal "1001.01" (show #f (numeric #i253/9 3 2))) ;; radix 36 (check-equal "zzz" (show #f (numeric (- (* 36 36 36) 1) 36))) ;; precision ;(check-equal "3.14159" (show #f 3.14159)) (check-equal "3.14" (show #f (with ((precision 2)) 3.14159))) (check-equal "3.14" (show #f (with ((precision 2)) 3.14))) (check-equal "3.00" (show #f (with ((precision 2)) 3.))) (check-equal "1.10" (show #f (with ((precision 2)) 1.099))) (check-equal "0.00" (show #f (with ((precision 2)) 1e-17))) (check-equal "0.0000000010" (show #f (with ((precision 10)) 1e-9))) (check-equal "0.0000000000" (show #f (with ((precision 10)) 1e-17))) (check-equal "0.000004" (show #f (with ((precision 6)) 0.000004))) (check-equal "0.0000040" (show #f (with ((precision 7)) 0.000004))) (check-equal "0.00000400" (show #f (with ((precision 8)) 0.000004))) (check-equal "1.00" (show #f (with ((precision 2)) .997554209949891))) (check-equal "1.00" (show #f (with ((precision 2)) .99755420))) (check-equal "1.00" (show #f (with ((precision 2)) .99755))) (check-equal "1.00" (show #f (with ((precision 2)) .997))) (check-equal "0.99" (show #f (with ((precision 2)) .99))) (check-equal "-15" (show #f (with ((precision 0)) -14.99995999999362))) (check-equal "+inf.0" (show #f +inf.0)) (check-equal "-inf.0" (show #f -inf.0)) (check-equal "+nan.0" (show #f +nan.0)) (check-equal "+inf.0" (show #f (numeric +inf.0))) (check-equal "-inf.0" (show #f (numeric -inf.0))) (check-equal "+nan.0" (show #f (numeric +nan.0))) (check-equal "333.333333333333333333333333333333" (show #f (with ((precision 30)) (numeric 1000/3)))) (check-equal "33.333333333333333333333333333333" (show #f (with ((precision 30)) (numeric 100/3)))) (check-equal "3.333333333333333333333333333333" (show #f (with ((precision 30)) (numeric 10/3)))) (check-equal "0.333333333333333333333333333333" (show #f (with ((precision 30)) (numeric 1/3)))) (check-equal "0.033333333333333333333333333333" (show #f (with ((precision 30)) (numeric 1/30)))) (check-equal "0.003333333333333333333333333333" (show #f (with ((precision 30)) (numeric 1/300)))) (check-equal "0.000333333333333333333333333333" (show #f (with ((precision 30)) (numeric 1/3000)))) (check-equal "0.666666666666666666666666666667" (show #f (with ((precision 30)) (numeric 2/3)))) (check-equal "0.090909090909090909090909090909" (show #f (with ((precision 30)) (numeric 1/11)))) (check-equal "1.428571428571428571428571428571" (show #f (with ((precision 30)) (numeric 10/7)))) (check-equal "0.123456789012345678901234567890" (show #f (with ((precision 30)) (numeric (/ 123456789012345678901234567890 1000000000000000000000000000000))))) (check-equal " 333.333333333333333333333333333333" (show #f (with ((precision 30) (decimal-align 5)) (numeric 1000/3)))) (check-equal " 33.333333333333333333333333333333" (show #f (with ((precision 30) (decimal-align 5)) (numeric 100/3)))) (check-equal " 3.333333333333333333333333333333" (show #f (with ((precision 30) (decimal-align 5)) (numeric 10/3)))) (check-equal " 0.333333333333333333333333333333" (show #f (with ((precision 30) (decimal-align 5)) (numeric 1/3)))) (check-equal " 3.14159" (show #f (with ((decimal-align 5) (precision 5)) (numeric 3.14159)))) (check-equal " 31.4159" (show #f (with ((decimal-align 5) (precision 4)) (numeric 31.4159)))) (check-equal " 314.159" (show #f (with ((decimal-align 5) (precision 3)) (numeric 314.159)))) (check-equal "3141.59" (show #f (with ((decimal-align 5) (precision 2)) (numeric 3141.59)))) (check-equal "31415.9" (show #f (with ((decimal-align 5) (precision 1)) (numeric 31415.9)))) (check-equal " -3.14159" (show #f (with ((decimal-align 5) (precision 5)) (numeric -3.14159)))) (check-equal " -31.4159" (show #f (with ((decimal-align 5) (precision 4)) (numeric -31.4159)))) (check-equal "-314.159" (show #f (with ((decimal-align 5) (precision 3)) (numeric -314.159)))) (check-equal "-3141.59" (show #f (with ((decimal-align 5) (precision 2)) (numeric -3141.59)))) (check-equal "-31415.9" (show #f (with ((decimal-align 5) (precision 1)) (numeric -31415.9)))) (check-equal "11.75" (show #f (with ((precision 2)) (/ 47 4)))) (check-equal "-11.75" (show #f (with ((precision 2)) (/ -47 4)))) ;; Precision: (check-equal "1.1250" (show #f (numeric 9/8 10 4))) (check-equal "1.125" (show #f (numeric 9/8 10 3))) (check-equal "1.12" (show #f (numeric 9/8 10 2))) (check-equal "1.1" (show #f (numeric 9/8 10 1))) (check-equal "1" (show #f (numeric 9/8 10 0))) (check-equal "1.1250" (show #f (numeric #i9/8 10 4))) (check-equal "1.125" (show #f (numeric #i9/8 10 3))) ;(check-equal "1.12" (show #f (numeric #i9/8 10 2))) (check-equal "1.1" (show #f (numeric #i9/8 10 1))) (check-equal "1" (show #f (numeric #i9/8 10 0))) ;; precision-show, base-4 (check-equal "1.1230" (show #f (numeric 91/64 4 4))) (check-equal "1.123" (show #f (numeric 91/64 4 3))) (check-equal "1.13" (show #f (numeric 91/64 4 2))) (check-equal "1.2" (show #f (numeric 91/64 4 1))) (check-equal "1" (show #f (numeric 91/64 4 0))) (check-equal "1.1230" (show #f (numeric #i91/64 4 4))) (check-equal "1.123" (show #f (numeric #i91/64 4 3))) (check-equal "1.13" (show #f (numeric #i91/64 4 2))) (check-equal "1.2" (show #f (numeric #i91/64 4 1))) (check-equal "1" (show #f (numeric #i91/64 4 0))) (check-equal "1.0010" (show #f (numeric 1001/1000 10 4))) (check-equal "1.001" (show #f (numeric 1001/1000 10 3))) (check-equal "1.00" (show #f (numeric 1001/1000 10 2))) (check-equal "1.0" (show #f (numeric 1001/1000 10 1))) (check-equal "1" (show #f (numeric 1001/1000 10 0))) (check-equal "1.0190" (show #f (numeric 1019/1000 10 4))) (check-equal "1.019" (show #f (numeric 1019/1000 10 3))) (check-equal "1.02" (show #f (numeric 1019/1000 10 2))) (check-equal "1.0" (show #f (numeric 1019/1000 10 1))) (check-equal "1" (show #f (numeric 1019/1000 10 0))) (check-equal "1.9990" (show #f (numeric 1999/1000 10 4))) (check-equal "1.999" (show #f (numeric 1999/1000 10 3))) (check-equal "2.00" (show #f (numeric 1999/1000 10 2))) (check-equal "2.0" (show #f (numeric 1999/1000 10 1))) (check-equal "2" (show #f (numeric 1999/1000 10 0))) ;; sign (check-equal "+1" (show #f (numeric 1 10 #f #t))) (check-equal "+1" (show #f (with ((sign-rule #t)) (numeric 1)))) (check-equal "(1)" (show #f (with ((sign-rule '("(" . ")"))) (numeric -1)))) (check-equal "-1" (show #f (with ((sign-rule '("-" . ""))) (numeric -1)))) (check-equal "−1-" (show #f (with ((sign-rule '("−" . "-"))) (numeric -1)))) (check-equal "-0.0" (show #f (with ((sign-rule #t)) (numeric -0.0)))) (check-equal "+0.0" (show #f (with ((sign-rule #t)) (numeric +0.0)))) (check-equal "+inf.0" (show #f (with ((sign-rule #f)) (numeric +inf.0)))) (check-equal "-inf.0" (show #f (with ((sign-rule #f)) (numeric -inf.0)))) (check-equal "+nan.0" (show #f (with ((sign-rule #f)) (numeric +nan.0)))) (check-equal "+inf.0" (show #f (with ((sign-rule #t)) (numeric +inf.0)))) (check-equal "-inf.0" (show #f (with ((sign-rule #t)) (numeric -inf.0)))) (check-equal "+nan.0" (show #f (with ((sign-rule #t)) (numeric +nan.0)))) (check-equal "+inf.0" (show #f (with ((sign-rule '("(" . ")"))) (numeric +inf.0)))) (check-equal "-inf.0" (show #f (with ((sign-rule '("(" . ")"))) (numeric -inf.0)))) (check-equal "+nan.0" (show #f (with ((sign-rule '("(" . ")"))) (numeric +nan.0)))) ;; comma-rule (check-equal "299792458" (show #f (with ((comma-rule 3)) 299792458))) (check-equal "299,792,458" (show #f (with ((comma-rule 3)) (numeric 299792458)))) (check-equal "-29,97,92,458" (show #f (with ((comma-rule '(3 2))) (numeric -299792458)))) (check-equal "299.792.458" (show #f (with ((comma-rule 3) (comma-sep #\.)) (numeric 299792458)))) (check-equal "299.792.458,0" (show #f (with ((comma-rule 3) (decimal-sep #\,)) (numeric 299792458.0)))) (check-equal "100,000" (show #f (with ((comma-rule 3)) (numeric 100000)))) (check-equal "100,000.0" (show #f (with ((comma-rule 3) (precision 1)) (numeric 100000)))) (check-equal "100,000.00" (show #f (with ((comma-rule 3) (precision 2)) (numeric 100000)))) ;; comma (check-equal "1,234,567" (show #f (numeric 1234567 10 #f #f 3))) (check-equal "567" (show #f (numeric 567 10 #f #f 3))) (check-equal "1,23,45,67" (show #f (numeric 1234567 10 #f #f 2))) (check-equal "12,34,567" (show #f (numeric 1234567 10 #f #f '(3 2)))) ;; comma-sep (check-equal "1|234|567" (show #f (numeric 1234567 10 #f #f 3 #\|))) (check-equal "1&234&567" (show #f (with ((comma-sep #\&)) (numeric 1234567 10 #f #f 3)))) (check-equal "1*234*567" (show #f (with ((comma-sep #\&)) (numeric 1234567 10 #f #f 3 #\*)))) (check-equal "567" (show #f (numeric 567 10 #f #f 3 #\|))) (check-equal "1,23,45,67" (show #f (numeric 1234567 10 #f #f 2))) (check-equal "1,234,567" (show #f (numeric/comma 1234567))) (check-equal "1,234,567" (show #f (numeric/comma 1234567 3))) (check-equal "123,4567" (show #f (numeric/comma 1234567 4))) (check-equal "123,456,789" (show #f (numeric/comma 123456789))) (check-equal "1,23,45,67,89" (show #f (numeric/comma 123456789 2))) (check-equal "12,34,56,789" (show #f (numeric/comma 123456789 '(3 2)))) ;; decimal (check-equal "1_5" (show #f (with ((decimal-sep #\_)) (numeric 1.5)))) (check-equal "1,5" (show #f (with ((comma-sep #\.)) (numeric 1.5)))) (check-equal "1,5" (show #f (numeric 1.5 10 #f #f #f #\.))) (check-equal "1%5" (show #f (numeric 1.5 10 #f #f #f #\. #\%))) (check-equal "1+2i" (show #f (string->number "1+2i"))) (check-equal "1.00+2.00i" (show #f (with ((precision 2)) (string->number "1+2i")))) (check-equal "3.14+2.00i" (show #f (with ((precision 2)) (string->number "3.14159+2i")))) (check-equal "123/4567" (show #f 123/4567)) (check-equal "123/4567" (show #f (numeric 123/4567))) (check-equal "608" (show #f (numeric/si 608))) (check-equal "608 B" (show #f (numeric/si 608 1000 " ") "B")) (check-equal "4k" (show #f (numeric/si 3986))) (check-equal "3.9Ki" (show #f (numeric/si 3986 1024))) (check-equal "4kB" (show #f (numeric/si 3986 1000) "B")) (check-equal "1.2M" (show #f (numeric/si 1.23e6 1000))) (check-equal "123k" (show #f (numeric/si 1.23e5 1000))) (check-equal "12.3k" (show #f (numeric/si 1.23e4 1000))) (check-equal "1.2k" (show #f (numeric/si 1.23e3 1000))) (check-equal "123" (show #f (numeric/si 1.23e2 1000))) (check-equal "12.3" (show #f (numeric/si 1.23e1 1000))) (check-equal "1.2" (show #f (numeric/si 1.23 1000))) (check-equal "1.2 m" (show #f (numeric/si 1.23 1000 " ") "m")) (check-equal "123m" (show #f (numeric/si 0.123 1000))) (check-equal "12.3m" (show #f (numeric/si 1.23e-2 1000))) (check-equal "1.2m" (show #f (numeric/si 1.23e-3 1000))) (check-equal "123n" (show #f (numeric/si 1.23e-7 1000))) (check-equal "12.3n" (show #f (numeric/si 1.23e-8 1000))) (check-equal "1.2n" (show #f (numeric/si 1.23e-9 1000))) (check-equal "1.2 nm" (show #f (numeric/si 1.23e-9 1000 " ") "m")) (check-equal "0" (show #f (numeric/si 0))) (check-equal "-608" (show #f (numeric/si -608))) (check-equal "-4k" (show #f (numeric/si -3986))) (check-equal "1.23" (show #f (numeric/fitted 4 1.2345 10 2))) (check-equal "1.00" (show #f (numeric/fitted 4 1 10 2))) (check-equal "#.##" (show #f (numeric/fitted 4 12.345 10 2))) (check-equal "#" (show #f (numeric/fitted 1 12.345 10 0))) (check-equal "##" (show #f (with ((precision 0)) (numeric/fitted 2 123.45)))) ;; joining (check-equal "1 2 3" (show #f (joined each '(1 2 3) " "))) (check-equal "a, b, c" (show #f (joined displayed '(a b c) ", "))) (check-equal "123-456-7890" (show #f (joined displayed '("123" "456" "7890") "-"))) (check-equal "abc3def7ghijk13lmn" (show #f (joined displayed '("abc" "def" "ghijk" "lmn") (fn (col) col)))) (check-equal "" (show #f (joined (lambda (obj) (raise obj)) '() "****"))) (check-equal "abcd" (show #f (joined displayed '(abcd) "****"))) (check-equal "abcdef" (show #f (joined displayed '(ab ef) "cd"))) (check-equal "/usr/local/bin" (show #f (joined/prefix displayed '(usr local bin) "/"))) (check-equal "1\n2\n3\n" (show #f (joined/suffix displayed '(1 2 3) nl))) (check-equal "" (show #f (joined/prefix displayed '() "*"))) (check-equal "*ab" (show #f (joined/prefix displayed '(ab) "*"))) (check-equal "*ab*cd" (show #f (joined/prefix displayed '(ab cd) "*"))) (check-equal "*ab*cd*ef" (show #f (joined/prefix displayed '(ab cd ef) "*"))) (check-equal "" (show #f (joined/suffix displayed '() "*"))) (check-equal "ab*" (show #f (joined/suffix displayed '(ab) "*"))) (check-equal "ab*cd*" (show #f (joined/suffix displayed '(ab cd) "*"))) (check-equal "ab*cd*ef*" (show #f (joined/suffix displayed '(ab cd ef) "*"))) (check-equal "lions, tigers, and bears" (show #f (joined/last displayed (lambda (last) (each "and " last)) '(lions tigers bears) ", "))) (check-equal "" (show #f (joined/last displayed (lambda (last) (each "#" last "#")) '() "*"))) (check-equal "#ab#" (show #f (joined/last displayed (lambda (last) (each "#" last "#")) '(ab) "*"))) (check-equal "ab*#cd#" (show #f (joined/last displayed (lambda (last) (each "#" last "#")) '(ab cd) "*"))) (check-equal "ab*cd*#ef#" (show #f (joined/last displayed (lambda (last) (each "#" last "#")) '(ab cd ef) "*"))) (check-equal "(1 2 . 3)" (show #f "(" (joined/dot displayed (lambda (dot) (each ". " dot)) '(1 2 . 3) " ") ")")) (check-equal "" (show #f (joined/dot displayed (lambda (dot) (each "#" dot)) '() "*"))) (check-equal "ab" (show #f (joined/dot displayed (lambda (dot) (each "#" dot)) '(ab) "*"))) (check-equal "ab*cd" (show #f (joined/dot displayed (lambda (dot) (each "#" dot)) '(ab cd) "*"))) (check-equal "ab*cd*ef" (show #f (joined/dot displayed (lambda (dot) (each "#" dot)) '(ab cd ef) "*"))) (check-equal "ab*#cd" (show #f (joined/dot displayed (lambda (dot) (each "#" dot)) '(ab . cd) "*"))) (check-equal "ab*cd*#ef" (show #f (joined/dot displayed (lambda (dot) (each "#" dot)) '(ab cd . ef) "*"))) (check-equal "" (show #f (joined/range displayed 0 0 " "))) (check-equal "0" (show #f (joined/range displayed 0 1 " "))) (check-equal "0 1" (show #f (joined/range displayed 0 1.5 " "))) (check-equal "0 1" (show #f (joined/range displayed 0 2 " "))) (check-equal "0 1 2" (show #f (joined/range displayed 0 2.000001 " "))) (check-equal "0 1 2 3 4" (show #f (joined/range displayed 0 5 " "))) (check-equal ":abc:123" (show #f (joined/prefix (lambda (x) (trimmed/right 3 x)) '("abcdef" "123456") ":"))) (check-equal "abc\n123\n" (show #f (joined/suffix (lambda (x) (trimmed/right 3 x)) '("abcdef" "123456") nl))) (check-equal "lions, tigers, and bears" (show #f (joined/last each (lambda (x) (each "and " x)) '(lions tigers bears) ", "))) (check-equal "lions, tigers, or bears" (show #f (joined/dot each (lambda (x) (each "or " x)) '(lions tigers . bears) ", "))) ;; padding/trimming (check-equal "abc " (show #f (padded/right 5 "abc"))) (check-equal " abc" (show #f (padded 5 "abc"))) (check-equal "abcdefghi" (show #f (padded 5 "abcdefghi"))) (check-equal " abc " (show #f (padded/both 5 "abc"))) (check-equal " abc " (show #f (padded/both 6 "abc"))) (check-equal "abcde" (show #f (padded/right 5 "abcde"))) (check-equal "abcdef" (show #f (padded/right 5 "abcdef"))) (check-equal "abc" (show #f (trimmed/right 3 "abcde"))) (check-equal "abc" (show #f (trimmed/right 3 "abcd"))) (check-equal "abc" (show #f (trimmed/right 3 "abc"))) (check-equal "ab" (show #f (trimmed/right 3 "ab"))) (check-equal "a" (show #f (trimmed/right 3 "a"))) (check-equal "abcde" (show #f (trimmed/right 5 "abcdef"))) (check-equal "abcde" (show #f (trimmed 5 "abcde"))) (check-equal "cde" (show #f (trimmed 3 "abcde"))) (check-equal "bcdef" (show #f (trimmed 5 "abcdef"))) (check-equal "bcd" (show #f (trimmed/both 3 "abcde"))) (check-equal "abcd" (show #f (trimmed/both 4 "abcde"))) (check-equal "abcde" (show #f (trimmed/both 5 "abcdef"))) (check-equal "bcde" (show #f (trimmed/both 4 "abcdef"))) (check-equal "bcdef" (show #f (trimmed/both 5 "abcdefgh"))) (check-equal "abc" (show #f (trimmed/lazy 3 "abcde"))) (check-equal "abc" (show #f (trimmed/lazy 3 "abc\nde"))) (check-equal "abc" (show #f (trimmed/lazy 3 "a" "b" "c" "d" "e"))) (check-equal "prefix: abc" (show #f "prefix: " (trimmed/right 3 "abcde"))) (check-equal "prefix: cde" (show #f "prefix: " (trimmed 3 "abcde"))) (check-equal "prefix: bcd" (show #f "prefix: " (trimmed/both 3 "abcde"))) (check-equal "prefix: abc" (show #f "prefix: " (trimmed/lazy 3 "abcde"))) (check-equal "prefix: abc" (show #f "prefix: " (trimmed/lazy 3 "abc\nde"))) (check-equal "abc :suffix" (show #f (trimmed/right 3 "abcde") " :suffix")) (check-equal "cde :suffix" (show #f (trimmed 3 "abcde") " :suffix")) (check-equal "bcd :suffix" (show #f (trimmed/both 3 "abcde") " :suffix")) (check-equal "abc :suffix" (show #f (trimmed/lazy 3 "abcde") " :suffix")) (check-equal "abc :suffix" (show #f (trimmed/lazy 3 "abc\nde") " :suffix")) (check-equal "abc" (show #f (trimmed/lazy 10 (trimmed/lazy 3 "abcdefghijklmnopqrstuvwxyz")))) (check-equal "abc" (show #f (trimmed/lazy 3 (trimmed/lazy 10 "abcdefghijklmnopqrstuvwxyz")))) (check-equal "0 1 2 3 4" (show #f (trimmed/lazy 9 (joined/range displayed 0 #f " ")))) (check-equal "abcde" (show #f (with ((ellipsis "...")) (trimmed/right 5 "abcde")))) (check-equal "ab..." (show #f (with ((ellipsis "...")) (trimmed/right 5 "abcdef")))) (check-equal "abc..." (show #f (with ((ellipsis "...")) (trimmed/right 6 "abcdefg")))) (check-equal "abcde" (show #f (with ((ellipsis "...")) (trimmed 5 "abcde")))) (check-equal "...ef" (show #f (with ((ellipsis "...")) (trimmed 5 "abcdef")))) (check-equal "...efg" (show #f (with ((ellipsis "...")) (trimmed 6 "abcdefg")))) (check-equal "abcdefg" (show #f (with ((ellipsis "...")) (trimmed/both 7 "abcdefg")))) (check-equal "...d..." (show #f (with ((ellipsis "...")) (trimmed/both 7 "abcdefgh")))) (check-equal "...e..." (show #f (with ((ellipsis "...")) (trimmed/both 7 "abcdefghi")))) (check-equal "abc " (show #f (fitted/right 5 "abc"))) (check-equal " abc" (show #f (fitted 5 "abc"))) (check-equal " abc " (show #f (fitted/both 5 "abc"))) (check-equal "abcde" (show #f (fitted/right 5 "abcde"))) (check-equal "abcde" (show #f (fitted 5 "abcde"))) (check-equal "abcde" (show #f (fitted/both 5 "abcde"))) (check-equal "abcde" (show #f (fitted/right 5 "abcdefgh"))) (check-equal "defgh" (show #f (fitted 5 "abcdefgh"))) (check-equal "bcdef" (show #f (fitted/both 5 "abcdefgh"))) (check-equal "prefix: abc :suffix" (show #f "prefix: " (fitted/right 5 "abc") " :suffix")) (check-equal "prefix: abc :suffix" (show #f "prefix: " (fitted 5 "abc") " :suffix")) (check-equal "prefix: abc :suffix" (show #f "prefix: " (fitted/both 5 "abc") " :suffix")) (check-equal "prefix: abcde :suffix" (show #f "prefix: " (fitted/right 5 "abcde") " :suffix")) (check-equal "prefix: abcde :suffix" (show #f "prefix: " (fitted 5 "abcde") " :suffix")) (check-equal "prefix: abcde :suffix" (show #f "prefix: " (fitted/both 5 "abcde") " :suffix")) (check-equal "prefix: abcde :suffix" (show #f "prefix: " (fitted/right 5 "abcdefgh") " :suffix")) (check-equal "prefix: defgh :suffix" (show #f "prefix: " (fitted 5 "abcdefgh") " :suffix")) (check-equal "prefix: bcdef :suffix" (show #f "prefix: " (fitted/both 5 "abcdefgh") " :suffix")) ;; columnar (define (runner->list runner) (define (run tail) (let ((val (runner))) (if (string? val) (begin (set-cdr! tail (list val)) (run (cdr tail)))))) (let ((tail (list #f))) (run tail) (cdr tail))) (check-equal ("abc" "12" "345" "67") (runner->list (make-runner 67 (each "abc" nl "12\n345" nl (fn (width) width))))) (check-equal ("abc " "def ") (runner->list (make-runner 0 (each (padded/right 5 "abc") nl (padded/right 5 (displayed "def")))))) (check-equal ("123" "456") (runner->list (make-runner 0 (displayed "123\n456\n")))) (check-equal ("123" "" "456") (runner->list (make-runner 0 (displayed "123\n\n456\n")))) (check-equal (#t "" "abc") (let-values (((found first rest) (string-split "\nabc" #\newline))) (list found first rest))) (check-equal (#t "abc" "def") (let-values (((found first rest) (string-split "abc\ndef" #\newline))) (list found first rest))) (check-equal (#t "abc" "") (let-values (((found first rest) (string-split "abc\n" #\newline))) (list found first rest))) (check-equal (#f "abc" "") (let-values (((found first rest) (string-split "abc" #\newline))) (list found first rest))) (check-equal (#f "" "") (let-values (((found first rest) (string-split "" #\newline))) (list found first rest))) (check-equal (#t "" "ab\nc") (let-values (((found first rest) (string-split "\nab\nc" #\newline))) (list found first rest))) (check-equal (#t "abc" "d\nef\n") (let-values (((found first rest) (string-split "abc\nd\nef\n" #\newline))) (list found first rest))) (check-equal (#t "abc" "\n") (let-values (((found first rest) (string-split "abc\n\n" #\newline))) (list found first rest))) (check-equal ("abc") (runner->list (make-infinite-runner 67 (displayed "abc")))) (check-equal ("abc") (runner->list (make-infinite-runner 67 (displayed "abc\n")))) (check-equal ("abc" "12" "345") (runner->list (make-infinite-runner 67 (each "abc" nl "12\n345")))) (check-equal ("abc" "12" "345") (runner->list (make-infinite-runner 67 (each "abc" nl "12\n345" nl)))) (check-equal ("abc" "12" "345" "67") (runner->list (make-infinite-runner 67 (each "abc" nl "12\n345" nl (fn (width) width))))) (check-equal ("123" "" "456") (runner->list (make-infinite-runner 0 (displayed "123\n\n456")))) (check-equal " abc | def | ghi\n" (show #f (columnar 6 'right (displayed "abc") " | " 'center 8 (displayed "def") " | " 'right 5 (displayed "ghi")))) (check-equal " abc | def | ghi\n 1234 | 5678 | 90\n" (show #f (columnar 6 'right (displayed "abc\n1234") " | " 'center 8 (displayed "def\n5678") " | " 'right 5 (displayed "ghi\n90")))) (check-equal " abc | def | ghi\n 1234 | 5678 | 90\n" (show #f (columnar 6 'center (displayed "abc\n1234") " | " 'right 8 (displayed "def\n5678") " | " 'left 5 (displayed "ghi\n90")))) (check-equal " abc | def\n 1234 | 5678\n" (show #f (columnar 6 'right (displayed "abc\n1234") " | " 'center 8 (displayed "def\n5678")))) (check-equal "\n" (show #f (columnar))) (check-equal "\n" (show #f (columnar "*"))) (check-equal "*\n" (show #f (columnar (each "*")))) (check-equal "abc 123\ndef 456\n" (show #f (with ((width 16)) (columnar (displayed "abc\ndef") (displayed "123\n456"))))) (check-equal "/* abc | 123 */\n/* def | 456 */\n" (show #f (with ((width 15)) (columnar "/* " (displayed "abc\ndef") " | " (displayed "123\n456") " */")))) (check-equal "abc\ndef\n" (show #f (columnar (displayed "abc\ndef\n")))) (check-equal "abc123\ndef456\n" (show #f (with ((width 0)) (columnar (displayed "abc\ndef\n") (displayed "123\n456\n"))))) (check-equal "abc123\ndef456\n" (show #f (with ((width 0)) (columnar (displayed "abc\ndef\n") (displayed "123\n456"))))) (check-equal "abc123\ndef456\n" (show #f (with ((width 0)) (columnar (displayed "abc\ndef") (displayed "123\n456\n"))))) (check-equal "abc123\ndef456\n" (show #f (with ((width 0)) (columnar (displayed "abc\ndef") (displayed "123\n456"))))) (check-equal "abc123\n \ndef456\n" (show #f (with ((width 1)) (columnar (displayed "abc\n\ndef") (displayed "123\n\n456"))))) (check-equal "abc123\ndef\n 456\n" (show #f (with ((width 1)) (columnar (displayed "abc\ndef") (displayed "123\n\n456"))))) (check-equal "abc123\n 456\ndef\n" (show #f (with ((width 1)) (columnar (displayed "abc\n\ndef") (displayed "123\n456"))))) (check-equal "abc123\ndef456\nghi789\n" (show #f (with ((width 0)) (columnar (displayed "abc\ndef\nghi\n") (displayed "123\n456\n789\n"))))) (check-equal "abc123wuv\ndef456xyz\n" (show #f (with ((width 0)) (columnar (displayed "abc\ndef\n") (displayed "123\n456\n") (displayed "wuv\nxyz\n"))))) (check-equal "abc 123\ndef 456\n" (show #f (with ((width 0)) (columnar (each (padded/right 5 "abc") nl (padded/right 5 "def")) (displayed "123\n456\n"))))) (check-equal "ABC 123\nDEF 456\n" (show #f (with ((width 0)) (columnar (each (upcased (padded/right 5 (displayed "abc"))) nl (upcased (padded/right 5 (displayed "def")))) (displayed "123\n456\n"))))) (check-equal "ABC 123\nDEF 456\n" (show #f (with ((width 0)) (columnar (each (padded/right 5 (upcased (displayed "abc"))) nl (padded/right 5 (upcased (displayed "def")))) (displayed "123\n456\n"))))) (check-equal " 1 first line\n 2 second line\n 3 third line\n" (show #f (columnar 4 'right 'infinite (line-numbers) " " (displayed "first line\nsecond line\nthird line")))) (check-equal " 1 first line\n 2 second line\n 3 third line\n" (show #f (columnar 4 'right 'infinite (line-numbers) " " (displayed "first line\nsecond line\nthird line\n")))) (check-equal "a | 123\nbc | 45\ndef | 6\n" (show #f (with ((width 20)) (tabular (each "a\nbc\ndef\n") " | " (each "123\n45\n6\n"))))) (check-equal "|a |123|\n|bc |45 |\n|def|6 |\n" (show #f (tabular "|" (each "a\nbc\ndef\n") "|" (each "123\n45\n6\n") "|"))) (check-equal "|a |123|\n|bc |45 |\n|def |6 |\n" (show #f (tabular "|" 8 (each "a\nbc\ndef\n") "|" (each "123\n45\n6\n") "|"))) (check-equal "| a| 123 |\n| bc| 45 |\n| def| 6 |\n" (show #f (tabular "|" 'right 8 (each "a\nbc\ndef\n") "|" 10 'center (each "123\n45\n6\n") "|"))) (check-equal "| 8 | a| 123 |\n| 9 | bc| 45 |\n|10 | def| 6 |\n" (show #f (tabular "|" 3 'infinite 'center (line-numbers 8) "|" 'right 8 (each "a\nbc\ndef\n") "|" 10 'center (each "123\n45\n6\n") "|"))) (check-equal "1234567890\nabcdefghij\nkl\n" (show #f (with ((width 10)) (wrapped/char "12345" "67890abcdefghijkl")))) (check-equal "abc\ndef g\nhijklmn \nopq\n" (show #f (with ((width 8)) (wrapped/char "abc\ndef ghijklmn opq")))) (check-equal "abcdefgh\nijklmnop\nqrstuvwx\nyz\n" (show #f (with ((width 8)) (wrapped/char "abcdefghijklmnopqrstuvwxyz")))) (check-equal "abcdefghijklmnopqrstuvwxyz\n" (show #f (with ((width 30)) (wrapped/char "abcdefghijklmnopqrstuvwxyz")))) (check-equal "abcdefghijklmnopqrstuvwxyz\n" (show #f (with ((width 26)) (wrapped/char "abcdefghijklmnopqrstuvwxyz")))) (check-equal "abcdefghijklmnopqrstuvwxy\nz\n" (show #f (with ((width 25)) (wrapped/char "abcdefghijklmnopqrstuvwxyz")))) (check-equal "\na\n" (show #f (with ((width 4)) (wrapped/char "\na\n")))) (check-equal "\n\n" (show #f (with ((width 4)) (wrapped/char "\n\n")))) (check-equal "\n" (show #f (with ((width 4)) (wrapped/char "\n")))) (check-equal "\n" (show #f (with ((width 4)) (wrapped/char "")))) (check-equal ("abc" "defghi" "jklmn") (string->words "abc defghi jklmn" char-whitespace?)) (check-equal ("abc" "defghi" "jklmn") (string->words " abc defghi jklmn " char-whitespace?)) (check-equal ("abc" "defghi" "jklmn") (string->words "\nabc \n defghi \njklmn \n " char-whitespace?)) (check-equal "" (show #f (wrapped " "))) (check-equal "hello\nworld" (show #f (with ((width 8)) (wrapped "hello world")))) ;(check-equal "hello\nworld" ; (show #f (with ((width 16)) (terminal-aware (wrapped "hello world"))))) (check-equal "The fundamental list iterator.\nApplies KONS to each element of\nLS and the result of the previous\napplication, beginning with KNIL.\nWith KONS as CONS and KNIL as '(),\nequivalent to REVERSE." (show #f (with ((width 36)) (wrapped "The fundamental list iterator. Applies KONS to each element of LS and the result of the previous application, beginning with KNIL. With KONS as CONS and KNIL as '(), equivalent to REVERSE.")))) (check-equal "foo" (show #f (wrapped "foo"))) (check-equal "- Item 1: The text here is\n indented according\n to the space \"Item\n 1\" takes, and one\n does not known what\n goes here.\n" (show #f (columnar 9 (each "- Item 1:") " " (with ((width 20)) (wrapped "The text here is indented according to the space \"Item 1\" takes, and one does not known what goes here."))))) (check-equal "- Item 1: The text here is\n indented according\n to the space \"Item\n 1\" takes, and one\n does not known what\n goes here.\n" (show #f (columnar 9 (each "- Item 1:\n") " " (with ((width 20)) (wrapped "The text here is indented according to the space \"Item 1\" takes, and one does not known what goes here."))))) (check-equal "- Item 1: The-text-here-is----\n--------- indented-according--\n--------- to-the-space-\"Item--\n--------- 1\"-takes,-and-one---\n--------- does-not-known-what-\n--------- goes-here.----------\n" (show #f (with ((pad-char #\-) (width 30)) (columnar 9 (each "- Item 1:\n") " " (with ((width 20)) (wrapped "The text here is indented according to the space \"Item 1\" takes, and one does not known what goes here.")))))) (check-equal "The quick\nbrown fox\njumped\nover the\nlazy dog" (show #f (with ((width 10)) (justified "The quick brown fox jumped over the lazy dog")))) (check-equal "The--quick\nbrown--fox\njumped----\nover---the\nlazy-dog" (show #f (with ((width 10) (pad-char #\-)) (justified "The quick brown fox jumped over the lazy dog")))) (define output-166 "first line\nsecond line\nthird line") (call-with-output-file "output-166.txt" (lambda (file) (display output-166 file))) (check-equal "first line\nsecond line\nthird line\n" (show #f (from-file "output-166.txt"))) (check-equal " 1 first line\n 2 second line\n 3 third line\n" (show #f (columnar 4 'right 'infinite (line-numbers) " " (from-file "output-166.txt")))) ;; shared structures (check-equal "#0=(1 . #0#)" (show #f (written (let ((ones (list 1))) (set-cdr! ones ones) ones)))) (check-equal "(0 . #0=(1 . #0#))" (show #f (written (let ((ones (list 1))) (set-cdr! ones ones) (cons 0 ones))))) (check-equal "(sym . #0=(sym . #0#))" (show #f (written (let ((syms (list 'sym))) (set-cdr! syms syms) (cons 'sym syms))))) (check-equal "(#0=(1 . #0#) #1=(2 . #1#))" (show #f (written (let ((ones (list 1)) (twos (list 2))) (set-cdr! ones ones) (set-cdr! twos twos) (list ones twos))))) (check-equal "(#0=(1 . #0#) #0#)" (show #f (written (let ((ones (list 1))) (set-cdr! ones ones) (list ones ones))))) (check-equal "((1) (1))" (show #f (written (let ((ones (list 1))) (list ones ones))))) (check-equal "(#0=(1) #0#)" (show #f (written-shared (let ((ones (list 1))) (list ones ones))))) ;; cycles without shared detection (check-equal "(1 1 1 1 1" (show #f (trimmed/lazy 10 (written-simply (let ((ones (list 1))) (set-cdr! ones ones) ones))))) (check-equal "(1 1 1 1 1 " (show #f (trimmed/lazy 11 (written-simply (let ((ones (list 1))) (set-cdr! ones ones) ones))))) #| ;; color (check-equal "\x1B;[31mred\x1B;[39m" (show #f (as-red "red"))) (check-equal "\x1B;[31mred\x1B;[34mblue\x1B;[31mred\x1B;[39m" (show #f (as-red "red" (as-blue "blue") "red"))) ;(check-equal "\x1b;[31m1234567\x1b;[39m col: 7" ; (show #f (terminal-aware (as-red "1234567") (fn (col) (each " col: " col))))) (check-equal "\x1b;[31m\x1b;[4m\x1b;[1mabc\x1b;[22mdef\x1b;[24mghi\x1b;[39m" (show #f (as-red (each (as-underline (as-bold "abc") "def") "ghi")))) (check-equal "\x1b;[44m\x1b;[33mabc\x1b;[39mdef\x1b;[49m" (show #f (on-blue (each (as-yellow "abc") "def")))) |# #| (define-library (srfi 166 test) (export run-tests) (import (scheme base) (scheme char) (scheme read) (scheme file) (only (srfi 1) circular-list) (chibi test) (srfi 166)) (begin (define-syntax test-pretty (syntax-rules () ((test-pretty str) (let ((sexp (read (open-input-string str)))) (test str (show #f (pretty sexp))))))) (define (run-tests) (test-begin "show") ;; pretty printing (test-pretty "(foo bar)\n") (test-pretty "((self . aquanet-paper-1991) (type . paper) (title . \"Aquanet: a hypertext tool to hold your\")) ") (test-pretty "(abracadabra xylophone bananarama yellowstonepark cryptoanalysis zebramania delightful wubbleflubbery)\n") (test-pretty "#(0 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)\n") (test-pretty "(0 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)\n") (test-pretty "(#(0 1) #(2 3) #(4 5) #(6 7) #(8 9) #(10 11) #(12 13) #(14 15) #(16 17) #(18 19))\n") (test-pretty "#(#(0 1) #(2 3) #(4 5) #(6 7) #(8 9) #(10 11) #(12 13) #(14 15) #(16 17) #(18 19))\n") (test-pretty "(define (fold kons knil ls) (define (loop ls acc) (if (null? ls) acc (loop (cdr ls) (kons (car ls) acc)))) (loop ls knil))\n") (test-pretty "(do ((vec (make-vector 5)) (i 0 (+ i 1))) ((= i 5) vec) (vector-set! vec i i))\n") (test-pretty "(do ((vec (make-vector 5)) (i 0 (+ i 1))) ((= i 5) vec) (vector-set! vec i 'supercalifrajalisticexpialidocious))\n") (test-pretty "(do ((my-vector (make-vector 5)) (index 0 (+ index 1))) ((= index 5) my-vector) (vector-set! my-vector index index))\n") (test-pretty "(define (fold kons knil ls) (let loop ((ls ls) (acc knil)) (if (null? ls) acc (loop (cdr ls) (kons (car ls) acc)))))\n") (test-pretty "(define (file->sexp-list pathname) (call-with-input-file pathname (lambda (port) (let loop ((res '())) (let ((line (read port))) (if (eof-object? line) (reverse res) (loop (cons line res))))))))\n") (test-pretty "(design (module (name \"\\\\testshiftregister\") (attributes (attribute (name \"\\\\src\")))) (wire (name \"\\\\shreg\") (attributes (attribute (name \"\\\\src\")))))\n") (test-pretty "(design (module (name \"\\\\testshiftregister\") (attributes (attribute (name \"\\\\src\") (value \"testshiftregister.v:10\")))) (wire (name \"\\\\shreg\") (attributes (attribute (name \"\\\\src\") (value \"testshiftregister.v:15\")))))\n") (test "(let ((ones '#0=(1 . #0#))) ones)\n" (show #f (pretty (let ((ones (list 1))) (set-cdr! ones ones) `(let ((ones ',ones)) ones))))) '(test "(let ((zeros '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) (ones '#0=(1 . #0#))) (append zeros ones))\n" (show #f (pretty (let ((ones (list 1))) (set-cdr! ones ones) `(let ((zeros '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) (ones ',ones)) (append zeros ones)))))) ;; pretty-simply (let* ((d (let ((d (list 'a 'b #f))) (list-set! d 2 d) (list d))) (ca (circular-list 'a))) (test "((a b (a b (a b" (show #f (trimmed/lazy 15 (pretty-simply '((a b (a b (a b (a b))))))))) (test "((a b\n (a b\n" (show #f (trimmed/lazy 15 (pretty-simply d)))) (test "'(a a\n a\n " (show #f (trimmed/lazy 15 (pretty-simply `(quote ,ca))))) (test "(foo\n (a a\n " (show #f (trimmed/lazy 15 (pretty-simply `(foo ,ca))))) (test "(with-x \n (a a" (show #f (trimmed/lazy 15 (pretty-simply `(with-x ,ca))))) ) (test "(define (fold kons knil ls) (let lp ((ls ls) (acc knil)) (if (null? ls) acc (lp (cdr ls) (kons (car ls) acc))))) " (show #f (with ((width 36)) (pretty '(define (fold kons knil ls) (let lp ((ls ls) (acc knil)) (if (null? ls) acc (lp (cdr ls) (kons (car ls) acc))))))))) '(test "(define (fold kons knil ls) ; The fundamental list iterator. (let lp ((ls ls) (acc knil)) ; Applies KONS to each element of (if (null? ls) ; LS and the result of the previous acc ; application, beginning with KNIL. (lp (cdr ls) ; With KONS as CONS and KNIL as '(), (kons (car ls) acc))))) ; equivalent to REVERSE. " (show #f (show-columns (list (lambda (x) (padded/right 36 x)) (with ((width 36)) (pretty '(define (fold kons knil ls) (let lp ((ls ls) (acc knil)) (if (null? ls) acc (lp (cdr ls) (kons (car ls) acc)))))))) (list (lambda (x) (each " ; " x)) (with ((width 36)) (wrapped "The fundamental list iterator. Applies KONS to each element of LS and the result of the previous application, beginning with KNIL. With KONS as CONS and KNIL as '(), equivalent to REVERSE.")))))) (test "(define (fold kons knil ls) ; The fundamental list iterator. (let lp ((ls ls) (acc knil)) ; Applies KONS to each element of (if (null? ls) ; LS and the result of the previous acc ; application, beginning with KNIL. (lp (cdr ls) ; With KONS as CONS and KNIL as '(), (kons (car ls) acc))))) ; equivalent to REVERSE. " (show #f (with ((width 76)) (columnar (pretty '(define (fold kons knil ls) (let lp ((ls ls) (acc knil)) (if (null? ls) acc (lp (cdr ls) (kons (car ls) acc)))))) " ; " (wrapped "The fundamental list iterator. Applies KONS to each element of LS and the result of the previous application, beginning with KNIL. With KONS as CONS and KNIL as '(), equivalent to REVERSE."))))) ;; unicode (test "〜日本語〜" (show #f (with ((pad-char #\〜)) (padded/both 5 "日本語")))) (test "日本語" (show #f (terminal-aware (with ((pad-char #\〜)) (padded/both 5 "日本語"))))) (test "本語" (show #f (trimmed 2 "日本語"))) (test "語" (show #f (terminal-aware (trimmed 2 "日本語")))) (test "日本" (show #f (trimmed/right 2 "日本語"))) (test "日" (show #f (terminal-aware (trimmed/right 2 "日本語")))) (test "\x1B;[31m日\x1B;[46m\x1B;[49m\x1B;[39m" (show #f (terminal-aware (trimmed/right 2 (as-red "日本語" (on-cyan "!!!!")))))) (test "日本語" (show #f (trimmed/right 3 "日本語"))) (test "日" (show #f (terminal-aware (trimmed/right 3 "日本語")))) (test "日本語 col: 6" (show #f (terminal-aware "日本語" (fn (col) (each " col: " col))))) (test "日本語ΠΜΕ col: 9" (show #f (terminal-aware "日本語ΠΜΕ" (fn (col) (each " col: " col))))) (test "日本語ΠΜΕ col: 12" (show #f (with ((ambiguous-is-wide? #t)) (terminal-aware "日本語ΠΜΕ" (fn (col) (each " col: " col)))))) (test "abc" (substring-terminal-width "abc" 0 6)) (test "ab" (substring-terminal-width "abc" 0 4)) (test "bc" (substring-terminal-width "abc" 2 6)) (test "ab" (substring-terminal-width "abc" 1 4)) (test "ab" (substring-terminal-width "abc" 1 5)) (test "b" (substring-terminal-width "abc" 2 4)) (test "" (substring-terminal-width "abc" 2 3)) (test "a" (substring-terminal-width "abc" -1 2)) (test-end)))) |# ;; ;; ---- SRFI 207: String-notated bytevectors ---- ;; (import (srfi 207)) (check-equal #u8(65 66 67 68) #u8"ABCD") (check-equal #u8(#x9 #x41 #x72 #x74 #x68 #x75 #x72 #xa) #u8"\tArthur\n") (check-equal #u8(#x41 #x42 #x3d #x1f #x0d #x43 #x44) #u8"AB\x3d;\x1f;\x0d;CD") (define (check-read-bytestring s) (bytestring-error? (guard (o (else o)) (let ((port (open-input-string s))) (read port))))) (check-equal #t (check-read-bytestring "#u8\"\\x100;\"")) (check-equal #t (check-read-bytestring "#u8\"\\x0ABC\"")) (check-equal #t (check-read-bytestring "#u8\"\\xE000;\"")) (check-equal #u8(108 111 114 101 109) (bytestring "lo" #\r #x65 #u8(#x6d))) (check-equal #t (equal? (bytestring) (bytevector))) (check-equal #u8(0 97 98 99 127 0 255 0 127) (make-bytestring '("\x0;abc\x7f;" 0 255 #\x0 #\x7F))) (define (check-make-bytestring . args) (bytestring-error? (guard (o (else o)) (make-bytestring args)))) (check-equal #t (check-make-bytestring "abc" #x100 "efg")) (check-equal #t (check-make-bytestring "abc\x3BB;efg")) (check-equal #t (check-make-bytestring "abc" -1 "efg")) (check-equal #t (check-make-bytestring "abc" 256 "efg")) (check-equal #t (check-make-bytestring "abc" #\x80 "efg")) (check-equal #f (check-make-bytestring "abc" #\x10 "efg")) (check-equal #u8"lorem" (bytestring "lo" #\r #x65 #u8(#x6d))) (check-equal #u8() (bytestring)) (check-equal #t (check-make-bytestring "\x3BB;")) (check-equal #t (check-make-bytestring #x100)) (check-equal #u8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16) (make-bytestring '(#u8(0 1 2 3) #\x4 5 6 7 "\x8;\x9;\xa;" #u8(11 12) 13 14 #\xF #\x10))) (check-equal #u8(113 114 115 116 117 118 119 120 121 122 123 124 125 126 127) (bytestring #u8(113 114 115 116) 117 #\x76 #\x77 "xyz{|}~" 127)) (check-equal #u8"lorem" (let ((bv (make-bytevector 5))) (make-bytestring! bv 0 '(#x6c #x6f #x72 #x65 #x6d)) bv)) (check-equal #u8" lorem " (let ((bv (make-bytevector 9 #x20))) (make-bytestring! bv 2 '("lo" #\r #x65 #u8(#x6d))) bv)) (check-equal #u8" scheme " (let ((bv (make-bytevector 10 #x20))) (make-bytestring! bv 2 '(#\s #\c "he" #u8(#x6d #x65))) bv)) (check-equal #u8(#x46 #x6f #x72 #x64) #u8"Ford") (check-equal "466f7264" (bytevector->hex-string #u8"Ford")) (check-equal #u8"Zaphod" (hex-string->bytevector "5a6170686f64")) (check-equal "6c6f72656d" (bytevector->hex-string #u8"lorem")) (check-equal #u8"lorem" (hex-string->bytevector "6c6f72656d")) (check-equal #t (bytestring-error? (guard (o (else o)) (hex-string->bytevector "c6f72656d")))) (check-equal #t (bytestring-error? (guard (o (else o)) (hex-string->bytevector "6czf72656d")))) (define homer (bytestring "The Man, O Muse, informe, who many a way / \ Wound in his wisedome to his wished stay;")) (define homer64 "VGhlIE1hbiwgTyBNdXNlLCBpbmZvcm1lLCB3aG8gbWFueSBhIHdheSAvIFdvd\ W5kIGluIGhpcyB3aXNlZG9tZSB0byBoaXMgd2lzaGVkIHN0YXk7") (define homer64-w "VGhlIE1hb iwgTyBNdXNlL CBpbmZvcm1lL\nCB3aG8gbWF\tueSBhIH\rdheSAvIFdvd\ W5kIGluI GhpcyB 3aXNlZ\t\t\nG9tZSB0b yBoaXMgd\t2lzaGVkIHN0YXk7") (check-equal #t (equal? (hex-string->bytevector (bytevector->hex-string homer)) homer)) (check-equal #u8() (hex-string->bytevector (bytevector->hex-string #u8()))) (check-equal "bG9yZW0=" (bytevector->base64 (bytestring "lorem"))) (check-equal "/+//" (bytevector->base64 #u8(#xff #xef #xff))) (check-equal "@*@@" (bytevector->base64 #u8(#xff #xef #xff) "*@")) (check-equal #t (equal? (bytevector->base64 homer) homer64)) (check-equal "AQ==" (bytevector->base64 #u8(1))) (check-equal "" (bytevector->base64 #u8())) (check-equal #u8"lorem" (base64->bytevector "bG9yZW0=")) (check-equal #u8(#xff #xef #xff) (base64->bytevector "/+//")) (check-equal #u8(#xff #xef #xff) (base64->bytevector "@*@@" "*@")) (check-equal #t (equal? (base64->bytevector homer64) homer)) (check-equal #t (equal? (base64->bytevector homer64-w) homer)) (check-equal #u8(1) (base64->bytevector "AQ==")) (check-equal #u8() (base64->bytevector "")) ;(check-equal #u8() (base64->bytevector "\n\n\n==\t\r\n")) (check-equal "AQIDBAUG" (bytevector->base64 #u8(1 2 3 4 5 6))) (check-equal "QXJ0aHVyIERlbnQ=" (bytevector->base64 #u8"Arthur Dent")) (check-equal #u8(#xfb #xff #xfe) (base64->bytevector "+/ /+")) (check-equal #t (bytestring-error? (guard (o (else o)) (base64->bytevector "bG9@frob")))) (check-equal "" (bytevector->base64 #u8"")) (check-equal "Zg==" (bytevector->base64 #u8"f")) (check-equal "Zm8=" (bytevector->base64 #u8"fo")) (check-equal "Zm9v" (bytevector->base64 #u8"foo")) (check-equal "Zm9vYg==" (bytevector->base64 #u8"foob")) (check-equal "Zm9vYmE=" (bytevector->base64 #u8"fooba")) (check-equal "Zm9vYmFy" (bytevector->base64 #u8"foobar")) (check-equal #u8"" (base64->bytevector "")) (check-equal #u8"f" (base64->bytevector "Zg = =")) (check-equal #u8"fo" (base64->bytevector "Zm 8=")) (check-equal #u8"foo" (base64->bytevector " Zm9v")) (check-equal #u8"foob" (base64->bytevector "Zm9vYg ==")) (check-equal #u8"fooba" (base64->bytevector "Zm9vYmE= ")) (check-equal #u8"foobar" (base64->bytevector "Zm 9vYmFy ")) (check-equal () (bytestring->list #u8())) (check-equal (#\F #\R 0 #\B) (bytestring->list (bytestring 70 82 0 66))) (check-equal (7 9 9 10 200) (bytestring->list (bytestring "\a\t\t\n" 200))) (check-equal #u8"lorem" (make-bytestring (bytestring->list #u8"lorem"))) (check-equal #u8"rem" (make-bytestring (bytestring->list #u8"lorem" 2))) (check-equal #u8"or" (make-bytestring (bytestring->list #u8"lorem" 1 3))) (define (generator->list gen) (define (generate gen lst) (let ((val (gen))) (if (eof-object? val) (reverse lst) (generate gen (cons val lst))))) (generate gen '())) (check-equal (#x6c #x6f #x72 #x65 #x6d) (let ((g (make-bytestring-generator "lo" #\r #x65 #u8(#x6d)))) (generator->list g))) (check-equal #t (bytestring-error? (guard (o (else o)) (make-bytestring-generator "abc\x3BB;efg" #\m #\u)))) (check-equal #t (bytestring-error? (guard (o (else o)) (make-bytestring-generator 89 90 300)))) (check-equal #u8"____Zaphod" (bytestring-pad #u8"Zaphod" 10 #\_)) (check-equal #u8(#x80 #x7f 0 0 0 0 0 0) (bytestring-pad-right #u8(#x80 #x7f) 8 0)) (check-equal #u8"Trillian" (bytestring-trim #u8" Trillian" (lambda (b) (= b #x20)))) (check-equal #u8(#x80 #x7f) (bytestring-trim-both #u8(0 0 #x80 #x7f 0 0 0) zero?)) (check-equal #u8"lorem" (bytestring-pad #u8"lorem" (bytevector-length #u8"lorem") #x7a)) (check-equal "zzzlorem" (utf8->string (bytestring-pad #u8"lorem" 8 #x7a))) (check-equal #t (equal? (bytestring-pad #u8"lorem" 8 #\z) (bytestring-pad #u8"lorem" 8 (char->integer #\z)))) (check-equal #u8"lorem" (bytestring-pad-right #u8"lorem" (bytevector-length #u8"lorem") #x7a)) (check-equal "loremzzz" (utf8->string (bytestring-pad-right #u8"lorem" 8 #x7a))) (check-equal #t (equal? (bytestring-pad-right #u8"lorem" 8 #\z) (bytestring-pad-right #u8"lorem" 8 (char->integer #\z)))) (check-equal #u8"Trillian" (bytestring-trim #u8" Trillian" (lambda (b) (= b #x20)))) (check-equal #u8(#x80 #x7f) (bytestring-trim-both #u8(0 0 #x80 #x7f 0 0 0) zero?)) (define (always n) #t) (define (never n) #f) (define (eq-r? n) (= n 114)) (check-equal #u8() (bytestring-trim #u8"lorem" always)) (check-equal #u8"lorem" (bytestring-trim #u8"lorem" never) ) (check-equal #u8(#x72 #x65 #x6d) (bytestring-trim #u8"lorem" (lambda (u8) (< u8 #x70)))) (check-equal #u8() (bytestring-trim-right #u8"lorem" always)) (check-equal #u8"lorem" (bytestring-trim-right #u8"lorem" never)) (check-equal #u8(#x6c #x6f #x72) (bytestring-trim-right #u8"lorem" (lambda (u8) (< u8 #x70)))) (check-equal #u8() (bytestring-trim-both #u8"lorem" always)) (check-equal #u8"lorem" (bytestring-trim-both #u8"lorem" never)) (check-equal #u8(#x72) (bytestring-trim-both #u8"lorem" (lambda (u8) (< u8 #x70)))) (check-equal #u8"Vogon poetry" (bytestring-replace #u8"Vogon torture" #u8"poetry" 6 13)) (check-equal #u8"lists" (bytestring-replace #u8"lorem" (bytestring "mists") 1 5 1 5)) (check-equal #u8"loaded" (bytestring-replace #u8"lorem" (bytestring "faded") 2 5 1 5)) (check-equal #u8"lorem" (bytestring-replace (make-bytevector 5) #u8"lorem" 0 (bytevector-length #u8"lorem"))) (check-equal #u8"food food" (let ((bv1 (bytestring "food")) (bv2 (bytestring "od fo"))) (bytestring-replace bv1 bv2 2 2 0 5))) (check-equal #u8"food" (let ((bv1 (bytestring "food food"))) (bytestring-replace bv1 (bytevector) 2 7 0 0))) (check-equal #t (bytestring=? #u8"lorem" #u8"lorem")) (check-equal #f (bytestring=? #u8"lore" #u8"lorem")) (check-equal #f (bytestring=? #u8"lorem" #u8"lore")) (check-equal #f (bytestring=? #u8"abcdef" #u8"ghijklmno")) (check-equal #t (bytestring<? #u8"Heart Of Gold" #u8"Heart of Gold")) (check-equal #f (bytestring<=? #u8(#x81 #x95) #u8(#x80 #xa0))) (check-equal #t (bytestring>? #u8(1 2 3) #u8(1 2))) (define short-bstring (bytestring "lore")) (define long-bstring (bytestring "lorem ")) (define mixed-case-bstring (bytestring "loreM")) (check-equal #f (bytestring<? #u8"lorem" #u8"lorem")) (check-equal #t (bytestring<? short-bstring #u8"lorem")) (check-equal #t (bytestring<? mixed-case-bstring #u8"lorem")) (check-equal #f (bytestring>? #u8"lorem" #u8"lorem")) (check-equal #t (bytestring>? #u8"lorem" short-bstring)) (check-equal #t (bytestring>? #u8"lorem" mixed-case-bstring)) (check-equal #t (bytestring<=? #u8"lorem" #u8"lorem")) (check-equal #t (bytestring<=? short-bstring #u8"lorem")) (check-equal #t (bytestring<=? mixed-case-bstring #u8"lorem")) (check-equal #f (bytestring<=? #u8"lorem" mixed-case-bstring)) (check-equal #f (bytestring<=? long-bstring #u8"lorem")) (check-equal #t (bytestring>=? #u8"lorem" #u8"lorem")) (check-equal #t (bytestring>=? #u8"lorem" short-bstring)) (check-equal #t (bytestring>=? #u8"lorem" mixed-case-bstring)) (check-equal #f (bytestring>=? mixed-case-bstring #u8"lorem")) (check-equal #f (bytestring>=? short-bstring #u8"lorem")) (check-equal 2 (bytestring-index #u8(#x65 #x72 #x83 #x6f) (lambda (b) (> b #x7f)))) (check-equal #f (bytestring-index #u8"Beeblebrox" (lambda (b) (> b #x7f)))) (check-equal 4 (bytestring-index-right #u8"Zaphod" odd?)) (check-equal 0 (bytestring-index #u8"lorem" always)) (check-equal #f (bytestring-index #u8"lorem" never)) (check-equal 3 (bytestring-index #u8"lorem" always 3)) (check-equal 2 (bytestring-index #u8"lorem" eq-r?)) (check-equal 4 (bytestring-index-right #u8"lorem" always)) (check-equal #f (bytestring-index-right #u8"lorem" never)) (check-equal 4 (bytestring-index-right #u8"lorem" always 3)) (check-equal 2 (bytestring-index-right #u8"lorem" eq-r?)) (check-equal (#u8(#x50 #x4b) #u8(0 0 #x1 #x5)) (call-with-values (lambda () (bytestring-break #u8(#x50 #x4b 0 0 #x1 #x5) zero?)) list)) (check-equal (#u8"ABCD" #u8"efg") (call-with-values (lambda () (bytestring-span #u8"ABCDefg" (lambda (b) (and (> b 40) (< b 91))))) list)) (define (eq-r? b) (= b #x72)) (define (lt-r? b) (< b #x72)) (check-equal (#u8"lorem" #u8()) (call-with-values (lambda () (bytestring-span #u8"lorem" always)) list)) (check-equal (#u8() #u8"lorem") (call-with-values (lambda () (bytestring-span #u8"lorem" never)) list)) (check-equal (#u8"lo" #u8"rem") (call-with-values (lambda () (bytestring-span #u8"lorem" lt-r?)) list)) (check-equal (#u8() #u8"lorem") (call-with-values (lambda () (bytestring-break #u8"lorem" always)) list)) (check-equal (#u8"lorem" #u8()) (call-with-values (lambda () (bytestring-break #u8"lorem" never)) list)) (check-equal (#u8"lo" #u8"rem") (call-with-values (lambda () (bytestring-break #u8"lorem" eq-r?)) list)) (check-equal #u8"Heart of Gold" (bytestring-join '(#u8"Heart" #u8"of" #u8"Gold") #x20)) (check-equal #u8(0 #xef #xbb 0 #xbf) (bytestring-join '(#u8(#xef #xbb) #u8(#xbf)) 0 'prefix)) (check-equal #t (bytestring-error? (guard (o (else o)) (bytestring-join '() 0 'strict-infix)))) (define test-segments '(#u8(1) #u8(2) #u8(3))) (check-equal #u8(1 0 2 0 3) (bytestring-join test-segments #u8(0))) (check-equal #u8(0 1 0 2 0 3) (bytestring-join test-segments #u8(0) 'prefix)) (check-equal #u8(1 0 2 0 3 0) (bytestring-join test-segments #u8(0) 'suffix)) (check-equal #u8() (bytestring-join '() #u8(0))) (check-equal #u8(1 32 2 32 3) (bytestring-join test-segments #\space)) (check-equal #u8(1 0 2 0 3) (bytestring-join test-segments 0)) (check-equal #u8(1 65 66 2 65 66 3) (bytestring-join test-segments "AB")) (check-equal #u8(1 7 8 2 7 8 3) (bytestring-join test-segments #u8(7 8))) (check-equal #t (bytestring-error? (guard (o (else o)) (bytestring-join test-segments 300)))) (check-equal #t (bytestring-error? (guard (o (else o)) (bytestring-join '() #u8(0) 'strict-infix)))) (check-equal (#u8"Bee" #u8"le" #u8"rox") (bytestring-split #u8"Beeblebrox" #x62)) (check-equal (#u8(1) #u8(2)) (bytestring-split #u8(1 0 2 0) 0 'suffix)) (check-equal (#u8(1) #u8(2) #u8(3)) (bytestring-split #u8(1 0 2 0 3) 0 'infix)) (check-equal (#u8(1) #u8(2) #u8(3)) (bytestring-split #u8(0 1 0 2 0 3) 0 'prefix)) (check-equal (#u8(1) #u8(2) #u8(3)) (bytestring-split #u8(1 0 2 0 3 0) 0 'suffix)) (check-equal (#u8() #u8() #u8()) (bytestring-split #u8(0 0) 0)) (check-equal () (bytestring-split #u8() 0)) (define (read-bs prefix bs) (call-with-port (open-input-string bs) (lambda (port) (read-textual-bytestring prefix port)))) (check-equal #u8(#x41 #x42 #xad #xf0 #x0d #x43 #x44) (read-bs #t "#u8\"AB\\xad;\\xf0;\\x0d;CD\"")) (check-equal #u8() (read-bs #t "#u8\"\"")) (check-equal #u8"lorem" (read-bs #t "#u8\"lorem\"")) (check-equal #t (equal? (bytevector #xde #xad #xf0 #x0d) (read-bs #t "#u8\"\\xde;\\xad;\\xf0;\\x0d;\""))) (check-equal #t (equal? (bytestring #\" #\\ #\alarm #\backspace #\tab #\newline #\return #\|) (read-bs #t "#u8\"\\\"\\\\\\a\\b\\t\\n\\r\\\|\""))) (check-equal #u8"lorem" (read-bs #t "#u8\"lor\\\n\te\\ \r\n\tm\"")) (check-equal #u8"lorem" (read-bs #f "\"lorem\"")) (check-equal #t (bytestring-error? (guard (o (else o)) (read-bs #t "#u\"lorem\"")))) (check-equal #t (bytestring-error? (guard (o (else o)) (read-bs #t "#u8lorem\"")))) (check-equal #t (bytestring-error? (guard (o (else o)) (read-bs #t "#u8\"lorem")))) (check-equal #t (bytestring-error? (guard (o (else o)) (read-bs #t "#u8\"l\\orem\"")))) ;(check-equal #t ; (bytestring-error? (guard (o (else o)) (read-bs #t "#u8\"l\\ orem\"")))) (check-equal #t (bytestring-error? (guard (o (else o)) (read-bs #t "#u8\"l\\x6frem\"")))) (check-equal #t (bytestring-error? (guard (o (else o)) (read-bs #t "#u8\"l\\x6z;rem\"")))) (check-equal #t (bytestring-error? (guard (o (else o)) (read-bs #t "#u8\"\x100; equivalence\"")))) (define (write-textual-bs bs) (call-with-port (open-output-string) (lambda (port) (write-textual-bytestring bs port) (get-output-string port)))) (check-equal "#u8\"\\tArthur\\n\"" (write-textual-bs #u8(#x9 #x41 #x72 #x74 #x68 #x75 #x72 #xa))) (check-equal "#u8\"\"" (write-textual-bs #u8())) (check-equal "#u8\"lorem\"" (write-textual-bs #u8"lorem")) (check-equal "#u8\"\\xde;\\xad;\\xbe;\\xef;\"" (write-textual-bs (bytevector #xde #xad #xbe #xef))) (check-equal "#u8\"\\\"\\\\\\a\\b\\t\\n\\r\\\|\"" (write-textual-bs (bytestring #\" #\\ #\alarm #\backspace #\tab #\newline #\return #\|))) (check-equal #t (let ((lorems '(#u8(124 199 173 212 209 232 249 16 198 32 123 111 130 92 64 155) #u8(50 133 193 27 177 105 10 186 61 149 177 105 96 70 223 190) #u8(0 117 226 155 110 0 66 216 27 129 187 81 17 210 71 152) #u8(123 31 159 25 100 135 246 47 249 137 243 241 45 241 240 221) #u8(207 186 70 110 118 231 79 195 153 253 93 101 126 198 70 235) #u8(138 176 92 152 208 107 28 236 198 254 111 37 241 116 191 206) #u8(221 254 214 90 0 155 132 92 157 246 199 224 224 142 91 114) #u8(228 216 233 80 142 15 158 54 5 85 174 101 111 75 126 209) #u8(191 16 83 245 45 98 72 212 148 202 135 19 213 150 141 121) #u8(41 169 182 96 47 184 16 116 196 251 243 93 81 162 175 140) #u8(85 49 218 138 132 11 27 11 182 27 120 71 254 169 132 166) #u8(89 216 175 23 97 10 237 112 208 195 112 80 198 154 241 254) #u8(187 54 6 57 250 137 129 89 188 19 225 217 168 178 174 129) #u8(88 164 89 40 175 194 108 56 12 124 109 96 148 149 119 109) #u8(241 66 32 115 203 71 128 154 240 111 194 137 73 44 146 3) #u8(177 185 177 233 18 14 178 106 110 109 222 147 111 157 216 208)))) (every (lambda (bvec) (equal? bvec (read-bs #t (write-textual-bs bvec)))) lorems))) (define (write-binary-bs . args) (call-with-port (open-output-bytevector) (lambda (port) (apply write-binary-bytestring port args) (get-output-bytevector port)))) (check-equal #u8"Zaphod" (write-binary-bs #\Z #x61 #x70 "hod"))
true
8d79926533c853853cee3ab467f9a3b9262ec6b6
46588d6660964a91a0c93398e840c16854a0267f
/idol-csv.scm
cd2cfb5f7c80c157a38573542c697c46e19cffec
[]
no_license
hkdnet/gosh-playground
b3da61c188a87cbf908c945574b2a5ea57e8d6fe
3fb4563aa7f0eaf79e2c6e69b56bf16a2534b31d
refs/heads/master
2020-03-12T05:16:14.753823
2018-04-30T13:39:23
2018-04-30T13:39:23
130,460,498
0
0
null
2018-04-30T13:39:24
2018-04-21T09:47:29
Scheme
UTF-8
Scheme
false
false
611
scm
idol-csv.scm
(load "./csv.scm") (use gauche.record) (define header '()) (define bodies '()) (let ((data (file->csv "csv/idols.csv"))) (set! header (car data)) (set! bodies (cdr data))) (define-record-type idol #t #t header) (define (bodies->idols bodies) (let loop ([bs bodies] [idols '()]) (if (null? bs) idols (let ((b (car bs))) (let ((idol (make-idol b))) (loop (cdr bs) (cons idol idols))))))) (define idols (bodies->idols bodies)) (let loop ([idols idols]) (if (not (null? idols)) (let ((idol (car idols))) (display idol)(newline) (loop (cdr idols)))))
false
b35866115bfa4c74fe351ed8b2a14834b4a06aec
b43e36967e36167adcb4cc94f2f8adfb7281dbf1
/scheme/swl1.3/apps/design/dm.ss
49d4ac89e266df73492a5963035b171198abc1a8
[ "SWL", "TCL" ]
permissive
ktosiu/snippets
79c58416117fa646ae06a8fd590193c9dd89f414
08e0655361695ed90e1b901d75f184c52bb72f35
refs/heads/master
2021-01-17T08:13:34.067768
2016-01-29T15:42:14
2016-01-29T15:42:14
53,054,819
1
0
null
2016-03-03T14:06:53
2016-03-03T14:06:53
null
UTF-8
Scheme
false
false
9,162
ss
dm.ss
(define gidx 0) (define gdm #f) (define blink-binding #f) (define-swl-class (<design-markup>) (<markup>) (ivars (blink-thread #f) (syncat #f) (mini-text "") (expr #f) (exprdm #f) (env #f) (sidx #f) (eidx #f) (parent #f) (idx #f) (holes '()) ;;; a hole is a pair of offsets (text #f) (pop-ttls #f) (pop-acts #f) (pop #f) ) (inherited) (inheritable) (private) (protected [idx1+ (ix) (send text add-offset ix 1)] [idx1- (ix) (send text add-offset ix -1)] ) (public [get-syncat () syncat] [get-expr () expr] [get-exprdm () exprdm] [get-env () env] [get-sidx () sidx] [get-eidx () eidx] [get-parent () parent] [get-holes () holes] [get-text () text] [get-mini-text () mini-text] [get-pop-ttls () pop-ttls] [get-pop-acts () pop-acts] [set-syncat! (v) (set! syncat v)] [set-expr! (v) (set! expr v)] [set-exprdm! (v) (set! exprdm v)] [set-env! (v) (set! env v)] [set-sidx! (v) (set! sidx v)] [set-eidx! (v) (set! eidx v)] [set-parent! (v) (set! parent v)] [cons-hole! (v) (set! holes (cons v holes))] [set-text! (v) (set! text v)] [set-mini-text! (v) (set! mini-text v)] [set-pop-ttls! (v) (set! pop-ttls v)] [set-pop-acts! (v) (set! pop-acts v)] [class-name () '<design-markup>] [enable-blinking () (if blink-thread (assertion-violationf '<design-markup> "enable-blinking: already enabled") (set! blink-thread (thread-fork-group (lambda () (thread-name "<design-markup>:blinker") (let ((color (send self get-background-color))) (interrupt-handler (lambda () (send self set-background-color! color) (thread-kill))) (let loop () (if (memq color '(white yellow pink)) (send self set-background-color! 'gray) (send self set-background-color! 'white)) (thread-sleep 300) (send self set-background-color! color) (thread-sleep 300) (loop)))))))] [disable-blinking () (critical-section (when blink-thread (thread-break blink-thread) (set! blink-thread #f)))] [toggle-blinking () (if blink-thread (send self disable-blinking) (send self enable-blinking))] [move-to (dstidx) (send text unparse-expr) (let ((str (send text get-string sidx eidx))) (if (send text pos<? sidx dstidx) (let ((dstmk (send text floating-mark dstidx)) (sp (let f ([ch (send text get-char eidx)]) (if (char-whitespace? ch) (begin (send text delete eidx) (cons ch (f (send text get-char eidx)))) '())))) (send text delete sidx eidx) (send text insert-at dstmk (list->string sp)) (send text insert-at dstmk str) (send text set-cursor-pos! dstmk) ) (begin (send text delete sidx eidx) (let ((dstmk (send text floating-mark dstidx)) (sp (let f ([spix (idx1- sidx)] [ans '()]) (let ([ch (send text get-char spix)]) (if (char-whitespace? ch) (begin (send text delete spix) (f (idx1- spix) (cons ch ans))) ans))))) (send text insert-at dstmk str) (send text insert-at dstmk (list->string sp)) (send text set-cursor-pos! dstmk) ))) (send text raw-indent-current-line) (send text parse-expr) (send text add-version (string-append "move " (make-pretty str))) )] [mouse-press (text x y mods) (define not-ok (lambda () (send text display-mini "not a binding or binding form"))) (define nested-form? (lambda (src dest) (if (eq? src dest) #t (let ((parent (send src get-parent))) (and parent (nested-form? parent dest)))))) (send text clear-mini) (when pop (send pop destroy)) (case syncat [(varref-lexical) (set! pop (make-popup '("Substitute") (list (lambda () (let ((v (assq expr env))) (when v (let ((dm (cdr v))) (when (eq? 'binding (send dm get-syncat)) (let* ((rhsdm (cadr (send dm get-exprdm))) (rhssidx (send rhsdm get-sidx)) (rhseidx (send rhsdm get-eidx)) (rhsstr (send text get-string rhssidx rhseidx)) (ostr (send text get-string sidx eidx)) ) (send text unparse-expr) (send text set-enabled! #t) (send text delete sidx eidx) (send text insert-at sidx rhsstr) (send text set-enabled! #f) (send text parse-expr) (send text add-version (string-append "subst [" ostr " -> " (make-pretty rhsstr) "]")) )))))) ))) (show-popup pop (+ (send text get-root-x) x) (+ (send text get-root-y) y))] [(boundvar binding bindings let letstar letrec keyword) (if (not blink-binding) (begin (case syncat [(binding) (send self enable-blinking) (set! blink-binding self)] [(boundvar) (set! blink-binding (send self get-parent)) (send blink-binding enable-blinking)] [else #f])) (let ((srcbdm blink-binding)) (send blink-binding disable-blinking) (set! blink-binding #f) (let ((dstbdm (case syncat [(bindings) (car (send self get-exprdm))] [(binding) self] [(boundvar) (send self get-parent)] [else #f])) (dstformdm (case syncat [(bindings) (send self get-parent)] [(binding) (send (send self get-parent) get-parent)] [(boundvar) (send (send (send self get-parent) get-parent) get-parent)] [(keyword) (if (not (memq expr '(let letstar letrec))) (not-ok) (send self get-parent))] [(let letstar letrec) self] [else (assertion-violationf 'design:mouse-press "invalid syncat: ~s" syncat)]))) (unless (eq? srcbdm dstbdm) (let* ((srcformdm (send (send srcbdm get-parent) get-parent)) (srcform (send srcformdm get-expr)) (srcbexp (send srcbdm get-expr)) (srcbvar (car srcbexp)) (srcbsidx (send srcbdm get-sidx)) (srcformbody (caddr (send srcformdm get-expr)))) (let* ((dstform (send dstformdm get-expr)) (dstbvars (map car (cadr dstform))) (dstexprdm (send dstformdm get-exprdm)) (dstbsdm (cadr dstexprdm)) (dstbssidx (send dstbsdm get-sidx)) (dstformbody (caddr (send dstformdm get-expr))) (dstidx (if dstbdm (let ((dstbsidx (send dstbdm get-sidx))) (if (send text pos<? srcbsidx dstbsidx) (send dstbdm get-eidx) (send dstbdm get-sidx))) (idx1+ dstbssidx)))) (cond [(eq? srcformdm dstformdm) (send srcbdm move-to dstidx)] ;;; same form [(nested-form? dstformdm srcformdm) ;;; pushing down (if (or (occurs-free-except-for? srcbvar srcformbody dstform) (memq srcbvar dstbvars)) (send text display-mini "illegal move down") (send srcbdm move-to dstidx)) ] [(nested-form? srcformdm dstformdm) ;;; lifting up (if (or (occurs-free-except-for? srcbvar dstformbody srcform) (memq srcbvar dstbvars)) (send text display-mini "illegal move up") (send srcbdm move-to dstidx)) ] [else ;;; lateral move (if (or (occurs-free-except-for? srcbvar srcformbody srcform) (memq srcbvar dstbvars)) (send text display-mini "illegal lateral move") (send srcbdm move-to dstidx)) ])))))))] [else (not-ok)]) (send-base self mouse-press text x y mods)] [mouse-enter (text x y mods) (send text display-mini mini-text) (case syncat [(varref-lexical) (let ((v (assq expr env))) (when v (let ((dm (cdr v))) (case (send dm get-syncat) [(binding) (send (car (send dm get-exprdm)) enable-blinking)] [(boundvar) (send dm enable-blinking)] ))))] [(binding) (unless (eq? self blink-binding) (send self set-background-color! 'pink))] [(boundvar) (unless (eq? (send self get-parent) blink-binding) (send (send self get-parent) set-background-color! 'pink))] ) (send-base self mouse-enter text x y mods)] [mouse-leave (text x y mods) (send text clear-mini) (case syncat [(varref-lexical) (let ((v (assq expr env))) (when v (let ((dm (cdr v))) (case (send dm get-syncat) [(binding) (send (car (send dm get-exprdm)) disable-blinking)] [(boundvar) (send dm disable-blinking)] ))))] [(binding) (unless (eq? self blink-binding) (send self set-background-color! 'white))] [(boundvar) (unless (eq? (send self get-parent) blink-binding) (send (send self get-parent) set-background-color! 'white))] ) (send-base self mouse-leave text x y mods)] [destroy () (send self disable-blinking) (send-base self destroy)] [init ignore-args (set! gidx (1+ gidx)) (set! idx gidx) (send-base self init) ] ) ) (define make-pretty (lambda (str) (let ((ip (open-input-string str)) (op (open-output-string))) (parameterize ((print-level 2) (print-length 2)) (pretty-print (read ip) op) (let ((ostr (get-output-string op))) (substring ostr 0 (1- (string-length ostr))))))))
false
8f005ba2ee70fc08fc57126b0a83c42cae1a71f2
6e359a216e1e435de5d39bc64e75998945940a8c
/ex4.6.scm
5536d6e10ce5a05a07bb518687d10124418b973b
[]
no_license
GuoDangLang/SICP
03a774dd4470624165010f65c27acc35d844a93d
f81b7281fa779a9d8ef03997214e47397af1a016
refs/heads/master
2021-01-19T04:48:22.891605
2016-09-24T15:26:57
2016-09-24T15:26:57
69,106,376
0
0
null
null
null
null
UTF-8
Scheme
false
false
666
scm
ex4.6.scm
(define (let? exp) (tagged-list? exp 'let)) (define (v-e-b exp) (cdr exp)) (define (let-body exp) (cddr exp)) (define (let-ve-pairs exp) (cadr exp)) (define (eval-let exp) (let->combination (veb exp))) (define (clauses-vars ve-pairs) ;map (if (null? ve-pairs) '() (cons (caar ve-pairs) (clauses-vars (cdr ve-pairs))))) (define (clauses-exps ve-pairs) ;map (if (null? ve-pairs) '() (cons (cdar ve-pairs) (clauses-exps (cdr ve-pairs))))) (define (let->combination veb) (list (make-lambda (clauses-vars (car veb)) (cdr veb)) (clauses-vars (car veb)))) ((let? exp) (eval (eval-let exp) env)) ; add this to eval procedure;
false
6c01445b283e84eae7b251dc76258e169546dcad
b4e3e2194fcb5722ff6b0022831348ef5d36daeb
/macro.scm
1ae39a1e4018f524c4c71b773b9898717623a6e6
[]
no_license
nyaago/my-scheme-learning
3adf46cf99c8579d05f483851e30732912b2faa2
e1ccca44f577ba26a3a85532ba171ad7a4669425
refs/heads/master
2021-01-10T05:47:09.311306
2015-06-05T15:42:59
2015-06-05T15:42:59
36,940,789
0
0
null
null
null
null
UTF-8
Scheme
false
false
513
scm
macro.scm
(define-syntax nand (syntax-rules () ((_) #f) ((_ p q ...) (not (and p q ...))))) (define-syntax nand (syntax-rules () ((_) #f) ((_ p) (if p #f #t)) ((_ p q ...) (if p (nand q ...) #t )))) (define-syntax inc (syntax-rules () ((_ i) (begin (set! i (+ i 1)) i)) ((_ i k) (begin (set! i (+ i k)) i)))) (define-syntax dec (syntax-rules () ((_ i) (begin (set! i (- i 1)) i)) ((_ i k) (begin (set! i (- i k)) i))))
true
c2d5233a3ecf62b51bb5ffe9b25fa5a47c0dec28
4b480cab3426c89e3e49554d05d1b36aad8aeef4
/chapter-03/ex3.04-yarra.scm
94ea5efa2fa6929b4199dd378b6645acecedf223
[]
no_license
tuestudy/study-sicp
a5dc423719ca30a30ae685e1686534a2c9183b31
a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f
refs/heads/master
2021-01-12T13:37:56.874455
2016-10-04T12:26:45
2016-10-04T12:26:45
69,962,129
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,480
scm
ex3.04-yarra.scm
; 3.04 (load "../misc/scheme-test.scm") ; solution (define (make-account balance password) (define kaisu 0) (define (withdraw amount) (if (>= balance amount) (begin (set! kaisu 0) (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amount) (begin (set! kaisu 0) (set! balance (+ balance amount)) "piyo piyo") balance) (define (err amount) (if (>= kaisu 7) (begin (set! kaisu 0) "piyo piyo") (begin (set! kaisu (+ 1 kaisu)) "Incorrect password"))) (define (dispatch pwd m) (if (not (eq? pwd password)) err (cond ((eq? m 'withdraw) withdraw) ((eq? m 'deposit) deposit) (else (error "Unknown request -- MAKE-ACCOUNT" m))))) dispatch) ; test (define acc (make-account 100 'sesame!)) (run (make-testcase '(assert-equal? "Incorrect password" ((acc 'susemi! 'deposit) 10)) '(assert-equal? "Incorrect password" ((acc 'susemi! 'deposit) 10)) '(assert-equal? "Incorrect password" ((acc 'susemi! 'deposit) 10)) '(assert-equal? "Incorrect password" ((acc 'susemi! 'deposit) 10)) '(assert-equal? "Incorrect password" ((acc 'susemi! 'deposit) 10)) '(assert-equal? "Incorrect password" ((acc 'susemi! 'deposit) 10)) '(assert-equal? "Incorrect password" ((acc 'susemi! 'deposit) 10)) '(assert-equal? "piyo piyo" ((acc 'susemi! 'deposit) 10))))
false
8e04f7817de7baf127fe8d2c3874b99b63554bcb
a74932f6308722180c9b89c35fda4139333703b8
/edwin48/bufwmc.scm
db95050587099ecb70bd8c38e98d8b02e60e1af2
[]
no_license
scheme/edwin48
16b5d865492db5e406085e8e78330dd029f1c269
fbe3c7ca14f1418eafddebd35f78ad12e42ea851
refs/heads/master
2021-01-19T17:59:16.986415
2014-12-21T17:50:27
2014-12-21T17:50:27
1,035,285
39
10
null
2022-02-15T23:21:14
2010-10-29T16:08:55
Scheme
UTF-8
Scheme
false
false
19,332
scm
bufwmc.scm
#| -*-Scheme-*- $Id: bufwmc.scm,v 1.24 2008/01/30 20:01:59 cph Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. MIT/GNU Scheme is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. MIT/GNU Scheme is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MIT/GNU Scheme; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |# ;;;; Buffer Windows: Mark <-> Coordinate Maps (define (buffer-window/mark->x window mark) (buffer-window/index->x window (mark-index mark))) (define (buffer-window/mark->y window mark) (buffer-window/index->y window (mark-index mark))) (define (buffer-window/mark->coordinates window mark) (buffer-window/index->coordinates window (mark-index mark))) (define (buffer-window/point-x window) (buffer-window/index->x window (%window-point-index window))) (define (buffer-window/point-y window) (buffer-window/index->y window (%window-point-index window))) (define (buffer-window/point-coordinates window) (buffer-window/index->coordinates window (%window-point-index window))) (define (buffer-window/index->x window index) (let ((start (%window-line-start-index window index)) (group (%window-group window)) (char-image-strings (%window-char-image-strings window)) (tab-width (%window-tab-width window))) (column->x (group-columns group start index 0 tab-width char-image-strings) (window-x-size window) (%window-truncate-lines? window) (%window-line-end-index? window index)))) (define (buffer-window/index->y window index) (call-with-values (lambda () (start-point-for-index window index)) (lambda (start-index start-y line-start-index) line-start-index (predict-y window start-index start-y index)))) (define (buffer-window/index->coordinates window index) (call-with-values (lambda () (start-point-for-index window index)) (lambda (start-index start-y line-start-index) (let ((group (%window-group window)) (char-image-strings (%window-char-image-strings window)) (tab-width (%window-tab-width window))) (let ((xy (column->coordinates (group-columns group line-start-index index 0 tab-width char-image-strings) (window-x-size window) (%window-truncate-lines? window) (%window-line-end-index? window index)))) (cons (car xy) (fix:+ (cdr xy) (predict-y window start-index start-y line-start-index)))))))) (define (buffer-window/coordinates->mark window x y) (let ((index (buffer-window/coordinates->index window x y))) (and index (make-mark (%window-group window) index)))) (define (buffer-window/coordinates->index window x y) (call-with-values (lambda () (start-point-for-y window y)) (lambda (start-index start-y) (predict-index window start-index start-y x y)))) (define (buffer-window/mark-visible? window mark) ;; True iff cursor at this position would be on-screen. (let ((index (mark-index mark))) (and (fix:<= (%window-group-start-index window) index) (fix:<= index (%window-group-end-index window)) (call-with-values (lambda () (start-point-for-index window index)) (lambda (start-index start-y line-start-index) line-start-index (predict-index-visible? window start-index start-y index)))))) (define (start-point-for-index window index) (if (outlines-valid? window) (let ((start-index (%window-current-start-index window)) (start-y (%window-current-start-y window))) (if (and (fix:<= start-index index) (fix:<= index (%window-current-end-index window))) (let loop ((outline (%window-start-outline window)) (index* start-index) (y start-y)) (let ((index** (fix:+ index* (fix:+ (outline-index-length outline) 1)))) (if (fix:< index index**) (values index* y index*) (loop (outline-next outline) index** (fix:+ y (outline-y-size outline)))))) (values start-index start-y (%window-line-start-index window index)))) (begin (guarantee-start-mark! window) (values (%window-start-line-index window) (%window-start-line-y window) (%window-line-start-index window index))))) (define (start-point-for-y window y) (if (outlines-valid? window) (let ((start-index (%window-current-start-index window)) (start-y (%window-current-start-y window))) (if (fix:< y start-y) (values start-index start-y) (let loop ((outline (%window-start-outline window)) (index start-index) (y* start-y)) (let ((y** (fix:+ y* (outline-y-size outline)))) (cond ((fix:< y y**) (values index y*)) ((not (outline-next outline)) (values start-index start-y)) (else (loop (outline-next outline) (fix:+ index (fix:+ (outline-index-length outline) 1)) y**))))))) (begin (guarantee-start-mark! window) (values (%window-start-line-index window) (%window-start-line-y window))))) (define (outlines-valid? window) (and (fix:= (group-modified-tick (%window-group window)) (%window-modified-tick window)) (not (%window-start-clip-mark window)) (not (%window-point-moved? window)) (not (%window-force-redraw? window)) (%window-start-line-mark window) (fix:= (%window-start-line-index window) (%window-current-start-index window)))) (define (predict-y window start y index) ;; Assuming that the character at index START appears at coordinate ;; Y, return the coordinate for the character at INDEX. START is ;; assumed to be a line start. (if (fix:= index start) y (let ((group (%window-group window)) (char-image-strings (%window-char-image-strings window)) (tab-width (%window-tab-width window)) (x-size (window-x-size window)) (truncate-lines? (%window-truncate-lines? window))) (if (fix:< index start) (let ((group-start (%window-group-start-index window))) (let loop ((start start) (y y)) (let* ((end (fix:- start 1)) (start (or (%find-previous-newline group end group-start) group-start)) (columns (group-columns group start end 0 tab-width char-image-strings)) (y (fix:- y (column->y-size columns x-size truncate-lines?)))) (if (fix:< index start) (loop start y) (fix:+ y (column->y (group-columns group start index 0 tab-width char-image-strings) x-size truncate-lines? (%window-line-end-index? window index))))))) (let ((group-end (%window-group-end-index window))) (let loop ((start start) (y y)) (let ((e&c (group-line-columns group start group-end 0 tab-width char-image-strings))) (if (fix:> index (car e&c)) (loop (fix:+ (car e&c) 1) (fix:+ y (column->y-size (cdr e&c) x-size truncate-lines?))) (fix:+ y (column->y (group-columns group start index 0 tab-width char-image-strings) x-size truncate-lines? (%window-line-end-index? window index))))))))))) (define (predict-y-limited window start y index yl yu) ;; Like PREDICT-Y, except returns #F if the result is not in the ;; range specified by YL and YU. Prevents long search to find INDEX ;; when it is far away from the window. (if (fix:= index start) (and (fix:<= yl y) (fix:< y yu) y) (let ((group (%window-group window)) (char-image-strings (%window-char-image-strings window)) (tab-width (%window-tab-width window)) (x-size (window-x-size window)) (truncate-lines? (%window-truncate-lines? window))) (if (fix:< index start) (let ((group-start (%window-group-start-index window))) (let loop ((start start) (y y)) (and (fix:<= yl y) (let* ((end (fix:- start 1)) (start (or (%find-previous-newline group end group-start) group-start)) (columns (group-columns group start end 0 tab-width char-image-strings)) (y (fix:- y (column->y-size columns x-size truncate-lines?)))) (if (fix:< index start) (loop start y) (let ((y (fix:+ y (column->y (group-columns group start index 0 tab-width char-image-strings) x-size truncate-lines? (%window-line-end-index? window index))))) (and (fix:<= yl y) (fix:< y yu) y))))))) (let ((group-end (%window-group-end-index window))) (let loop ((start start) (y y)) (and (fix:< y yu) (let ((e&c (group-line-columns group start group-end 0 tab-width char-image-strings))) (if (fix:> index (car e&c)) (loop (fix:+ (car e&c) 1) (fix:+ y (column->y-size (cdr e&c) x-size truncate-lines?))) (let ((y (fix:+ y (column->y (group-columns group start index 0 tab-width char-image-strings) x-size truncate-lines? (%window-line-end-index? window index))))) (and (fix:<= yl y) (fix:< y yu) y))))))))))) (define (predict-index-visible? window start y index) (and (fix:>= index start) (let ((x-size (window-x-size window)) (y-size (window-y-size window)) (group (%window-group window)) (char-image-strings (%window-char-image-strings window)) (tab-width (%window-tab-width window)) (truncate-lines? (%window-truncate-lines? window)) (group-end (%window-group-end-index window))) (let loop ((start start) (y y)) (and (fix:< y y-size) (let ((e&c (group-line-columns group start group-end 0 tab-width char-image-strings))) (if (fix:> index (car e&c)) (loop (fix:+ (car e&c) 1) (fix:+ y (column->y-size (cdr e&c) x-size truncate-lines?))) (let ((y (fix:+ y (column->y (group-columns group start index 0 tab-width char-image-strings) x-size truncate-lines? (%window-line-end-index? window index))))) (and (fix:<= 0 y) (fix:< y y-size)))))))))) (define (predict-index window start y-start x y) ;; Assumes that START is a line start. (let ((group (%window-group window)) (char-image-strings (%window-char-image-strings window)) (tab-width (%window-tab-width window)) (x-size (window-x-size window)) (truncate-lines? (%window-truncate-lines? window))) (if (fix:< y y-start) (let ((group-start (%window-group-start-index window))) (let loop ((start start) (y-start y-start)) (and (fix:< group-start start) (let* ((end (fix:- start 1)) (start (or (%find-previous-newline group end group-start) group-start)) (columns (group-columns group start end 0 tab-width char-image-strings)) (y-start (fix:- y-start (column->y-size columns x-size truncate-lines?)))) (if (fix:< y y-start) (loop start y-start) (vector-ref (group-column->index group start end 0 (let ((column (coordinates->column x (fix:- y y-start) x-size))) (if (fix:< column columns) column columns)) tab-width char-image-strings) 0)))))) (let ((group-end (%window-group-end-index window))) (let loop ((start start) (y-start y-start)) (let ((e&c (group-line-columns group start group-end 0 tab-width char-image-strings))) (let ((y-end (fix:+ y-start (column->y-size (cdr e&c) x-size truncate-lines?)))) (if (fix:>= y y-end) (and (fix:< (car e&c) group-end) (loop (fix:+ (car e&c) 1) y-end)) (vector-ref (group-column->index group start (car e&c) 0 (let ((column (coordinates->column x (fix:- y y-start) x-size))) (if (fix:< column (cdr e&c)) column (cdr e&c))) tab-width char-image-strings) 0))))))))) (define (compute-window-start window index y-index) ;; INDEX is an index into WINDOW's buffer, and Y-INDEX is the ;; desired y coordinate, in WINDOW's coordinate space, at which ;; INDEX is desired to appear. Returns a vector of values: ;; 0 START-LINE, index at start of first line that is visible in the ;; window. ;; 1 Y-START, coordinate at which START-LINE will appear. Negative ;; if START-LINE is less than START, otherwise zero. ;; 2 START, index of first visible char (in upper left corner). ;; 3 START-COLUMN, first visible column of window. Positive if ;; START is greater than START-LINE, otherwise zero. ;; 4 START-PARTIAL. If START char is fully visible, this is zero. ;; Otherwise this is positive and indicates the number of columns ;; that *are* visible. ;; 5 #F means that it's not possible to place the INDEX char at ;; Y-INDEX, but that the other values are a starting point that ;; gets the INDEX char as close as possible to Y-INDEX. ;; Otherwise, this is #T indicating that the starting point is ;; satisfactory. (if (%window-truncate-lines? window) (compute-window-start-tl window index y-index) (compute-window-start-ntl window index y-index))) (define (compute-window-start-tl window index y-index) (let ((group (%window-group window))) (let ((group-start (group-display-start-index group)) (group-end (group-display-end-index group))) (let ((start (let ((index (group-find-previous-char group group-start index #\newline))) (if index (fix:+ index 1) group-start)))) (cond ((fix:= y-index 0) (vector start y-index start 0 0 #t)) ((fix:< y-index 0) (let loop ((start start) (y-start y-index)) (let ((nl (group-find-next-char group start group-end #\newline))) (if nl (let ((start (fix:+ nl 1)) (y-start (fix:+ y-start 1))) (if (fix:= y-start 0) (vector start y-start start 0 0 #t) (loop start y-start))) (vector start 0 start 0 0 #f))))) ((fix:= start group-start) (vector start 0 start 0 0 #f)) (else (let loop ((end (fix:- start 1)) (y-start y-index)) (let ((nl (group-find-previous-char group group-start end #\newline)) (y-start (fix:- y-start 1))) (cond ((fix:= y-start 0) (let ((start (if nl (fix:+ nl 1) group-start))) (vector start y-start start 0 0 #t))) ((not nl) (vector group-start 0 group-start 0 0 #f)) (else (loop nl y-start))))))))))) (define (compute-window-start-ntl window index y-index) (let ((group (%window-group window)) (char-image-strings (%window-char-image-strings window)) (tab-width (%window-tab-width window)) (x-size (window-x-size window))) (let ((group-start (group-display-start-index group)) (group-end (group-display-end-index group)) (x-max (fix:- x-size 1))) (let ((start (let ((index (group-find-previous-char group group-start index #\newline))) (if index (fix:+ index 1) group-start)))) (let ((y-start (fix:- y-index (column->y (group-columns group start index 0 tab-width char-image-strings) x-size #f (%window-line-end-index? window index))))) (cond ((fix:= y-start 0) (vector start y-start start 0 0 #t)) ((fix:< y-start 0) (let loop ((start start) (y-start y-start)) (let* ((column (fix:* (fix:- 0 y-start) x-max)) (icp (group-column->index group start group-end 0 column tab-width char-image-strings))) (cond ((fix:= (vector-ref icp 1) column) (vector start y-start (vector-ref icp 0) (vector-ref icp 1) (vector-ref icp 2) #t)) ((fix:= (vector-ref icp 0) group-end) (vector start 0 start 0 0 #f)) (else (loop (fix:+ (vector-ref icp 0) 1) (fix:+ y-start (column->y-size (vector-ref icp 1) x-size #f)))))))) ((fix:= start group-start) (vector start 0 start 0 0 #f)) (else (let loop ((end (fix:- start 1)) (y-start y-start)) (let ((nl (group-find-previous-char group group-start end #\newline))) (let ((start (if nl (fix:+ nl 1) group-start))) (let ((y-start (fix:- y-start (column->y-size (group-columns group start end 0 tab-width char-image-strings) x-size #f)))) (cond ((fix:= y-start 0) (vector start y-start start 0 0 #t)) ((fix:< y-start 0) (let ((icp (group-column->index group start end 0 (fix:* (fix:- 0 y-start) x-max) tab-width char-image-strings))) (vector start y-start (vector-ref icp 0) (vector-ref icp 1) (vector-ref icp 2) #t))) ((not nl) (vector group-start 0 group-start 0 0 #f)) (else (loop nl y-start)))))))))))))) ;;;; Column<->Coordinate Utilities (define (column->y-size column-size x-size truncate-lines?) ;; Assume X-SIZE > 1. (cond ((or truncate-lines? (fix:< column-size x-size)) 1) ((fix:= (fix:remainder column-size (fix:- x-size 1)) 0) (fix:quotient column-size (fix:- x-size 1))) (else (fix:+ (fix:quotient column-size (fix:- x-size 1)) 1)))) (define (column->coordinates column x-size truncate-lines? line-end?) (let ((x-max (fix:- x-size 1))) (cond ((fix:< column x-max) (cons column 0)) (truncate-lines? (cons x-max 0)) ((and line-end? (fix:= (fix:remainder column x-max) 0)) (cons x-max (fix:- (fix:quotient column x-max) 1))) (else (cons (fix:remainder column x-max) (fix:quotient column x-max)))))) (define (column->x column x-size truncate-lines? line-end?) (let ((x-max (fix:- x-size 1))) (cond ((fix:< column x-max) column) (truncate-lines? x-max) ((and line-end? (fix:= (fix:remainder column x-max) 0)) x-max) (else (fix:remainder column x-max))))) (define (column->y column x-size truncate-lines? line-end?) (let ((x-max (fix:- x-size 1))) (cond ((or truncate-lines? (fix:< column x-max)) 0) ((and line-end? (fix:= (fix:remainder column x-max) 0)) (fix:- (fix:quotient column x-max) 1)) (else (fix:quotient column x-max))))) (define (coordinates->column x y x-size) (fix:+ x (fix:* y (fix:- x-size 1))))
false
6ac7004033c8c5975680b65d67862774e0d034c9
5dd361bf04852b0c860bb6d02f79535979297e35
/scheme-projects/Lab5.ss
4aa44ca828934d736b5da8051a7bb2f5823dca19
[]
no_license
badams2527/4003-Labs
a87cec3da24a106d85150fd33cd64896fac42f2d
6936ba485ac18e5ef888b555614af73b44ee6f90
refs/heads/master
2016-09-10T14:54:12.982040
2015-04-26T04:12:06
2015-04-26T04:12:06
29,199,458
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,179
ss
Lab5.ss
(define int-builder (lambda (n) (if (= n 1) '() (append (int-builder (- n 1)) (cons n '()))))) (define filter-out-mults (lambda (num lst) (if (null? lst) '() (if (= (modulo (car lst) num) 0) (filter-out-mults num (cdr lst)) (cons (car lst) (filter-out-mults num (cdr lst))))))) (define sieve (lambda (lst) (if (null? lst) '() (cons (car lst) (sieve (filter-out-mults (car lst) (cdr lst))))))) (define primes (lambda (n) (sieve (int-builder n)))) (define stol (lambda (m) (let ((lst (primes (* m 20)))) (take m lst)))) (define take (lambda (m lst) (if (= m 0) '() (cons (car lst) (take (- m 1) (cdr lst)))))) (int-builder 20) ;Value: (2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) (int-builder 10) ;Value: (2 3 4 5 6 7 8 9 10) (filter-out-mults 2 (int-builder 20)) ;Value: (3 5 7 9 11 13 15 17 19) (filter-out-mults 3 '(3 5 7 9 11 13 15 17 19)) ;Value: (5 7 11 13 17 19) (filter-out-mults 5 '(5 7 11 13 17 19)) ;Value: (7 11 13 17 19) (filter-out-mults 7 '(7 11 13 17 19)) ;Value: (11 13 17 19) (stol 100)
false
0c3e6bf73d3c8636a825d78b8de9352310a2bea2
880304b2bb68f758f7fa5896f9dc4fb907030998
/13.ss
d31468f87a7a1abdcda3095ed365d5bfe0c40ef9
[]
no_license
chapmacl/PLC
e51c7c424880a191cd5ec0972621159421cdaa4b
fcb39f801fa066424dcae8eb80351a199ddf4b3d
refs/heads/master
2021-07-16T17:43:38.186406
2017-10-19T21:13:53
2017-10-19T21:13:53
107,576,768
0
0
null
null
null
null
UTF-8
Scheme
false
false
15,328
ss
13.ss
;; Clay Chapman and Jenner Wile ;; A13 Interpreter (load "chez-init.ss") ;---------------+ ; | ; DATATYPES | ; | ;---------------+ ; parsed expression (define-datatype expression expression? [var-exp (id symbol?)] [lit-exp (id literal?)] [lambda-exp (id symbol?) (bodies (list-of expression?))] [lambda-exp-var (ids (list-of symbol?)) (bodies (list-of expression?))] [lambda-exp-improper (ids (list-of symbol?)) (bodies (list-of expression?))] [if-then-exp (body expression?) (then expression?)] [if-then-else-exp (body expression?) (then expression?) (els expression?)] [set!-exp (id symbol?) (r-val-exp expression?)] [let-exp (ids (list-of symbol?)) (var-bodies (list-of expression?)) (bodies (list-of expression?))] [let-name-exp (name symbol?) (ids (list-of symbol?)) (var-bodies (list-of expression?)) (bodies (list-of expression?))] [let*-exp (ids (list-of symbol?)) (var-bodies (list-of expression?)) (bodies (list-of expression?))] [letrec-exp (ids (list-of symbol?)) (var-bodies (list-of expression?)) (bodies (list-of expression?))] [app-exp (rator expression?) (rands (list-of expression?))]) ;; environment type definitions (define scheme-value? (lambda (x) #t)) (define-datatype environment environment? [empty-env-record] [extended-env-record (syms (list-of symbol?)) (vals (list-of scheme-value?)) (env environment?)]) ; datatype for procedures. At first there is only one ; kind of procedure, but more kinds will be added later. (define-datatype proc-val proc-val? [prim-proc (name symbol?)] [closure (params (list-of symbol?)) (bodies (list-of expression?)) (env environment?)]) ;---------------+ ; | ; PARSER | ; | ;---------------+ (define parse-exp (lambda (datum) (cond [(symbol? datum) (var-exp datum)] [(literal? datum) (lit-exp datum)] [(and (pair? datum) (not (list? datum))) (eopl:error 'parse-exp "Improper list ~s" datum)] [(pair? datum) (cond [(eqv? (car datum) 'quote) (list 'lit-exp (cadr datum))] [(eqv? (car datum) 'lambda) (cond [(< (length datum) 3) (eopl:error 'parse-exp "Incorrect number of arguments for lambda ~s" datum)] [(not (all-symbols? (cadr datum))) (eopl:error 'parse-exp "Incorrect argument for lambda ~s" datum)] [(and (list? (cadr datum)) (andmap literal? (cadr datum))) (lambda-exp-var (cadr datum) (map parse-exp (cddr datum)))] [(and (pair? (cadr datum)) (not (list? (cadr datum)))) (lambda-exp-improper (i-to-p (cadr datum)) (map parse-exp (cddr datum)))] [else (lambda-exp (cadr datum) (map parse-exp (cddr datum)))])] [(eqv? (car datum) 'if) (cond [(< (length datum) 3) (eopl:error 'parse-exp "Not enough arguments for if statement ~s" datum)] [(> (length datum) 4) (eopl:error 'parse-exp "Too many arguments for if statement ~s" datum)] [(null? (cdddr datum)) (if-then-exp (parse-exp (cadr datum)) (parse-exp (caddr datum)))] [else (if-then-else-exp (parse-exp (cadr datum)) (parse-exp (caddr datum)) (parse-exp (cadddr datum)))])] [(eqv? (car datum) 'set!) (cond [(not (= (length datum) 3)) (eopl:error 'parse-exp "Incorrect number of arguments for set! ~s" datum)] [else (set!-exp (cadr datum) (parse-exp (caddr datum)))])] ;at least length 3, cadr is a list of lists of length 2, {map car {cadr datum}} are symbols [(eqv? (car datum) 'let) (cond [(< (length datum) 3) (eopl:error 'parse-exp "Not enough arguments for let statement ~s" datum)] [(not (list? (cadr datum))) (eopl:error 'parse-exp "Incorrect variable binding structure in let statement ~s" datum)] [(not (andmap list? (cadr datum))) (eopl:error 'parse-exp "Non-list inside of variable binding structure in let statement ~s" datum)] [(not (andmap (lambda (x) (equal? (length x) 2)) (cadr datum))) (eopl:error 'parse-exp "Variable bind is incorrect in let statement ~s" datum)] [(not (andmap symbol? (map car (cadr datum)))) (eopl:error 'parse-exp "Attempting to bind non-symbol in let statement ~s" datum)] [(not (andmap expression? (map parse-exp (map cadr (cadr datum))))) (eopl:error 'parse-exp "Attemping to bind variable to non-expression in let statement ~s" datum)] [else (let-exp (map car (cadr datum)) (map parse-exp (map cadr (cadr datum))) (map parse-exp (cddr datum)))])] [(eqv? (car datum) 'let*) (cond [(< (length datum) 3) (eopl:error 'parse-exp "Not enough arguments for let* statement ~s" datum)] [(not (list? (cadr datum))) (eopl:error 'parse-exp "Incorrect variable binding structure in let* statement ~s" datum)] [(not (andmap list? (cadr datum))) (eopl:error 'parse-exp "Non-list inside of variable binding structure in let* statement ~s" datum)] [(not (andmap (lambda (x) (equal? (length x) 2)) (cadr datum))) (eopl:error 'parse-exp "Variable bind is incorrect in let* statement ~s" datum)] [(not (andmap symbol? (map car (cadr datum)))) (eopl:error 'parse-exp "Attempting to bind non-symbol in let* statement ~s" datum)] [(not (andmap expression? (map parse-exp (map cadr (cadr datum))))) (eopl:error 'parse-exp "Attemping to bind variable to non-expression in let* statement ~s" datum)] [else (let*-exp (map car (cadr datum)) (map parse-exp (map cadr (cadr datum))) (map parse-exp (cddr datum)))])] [(eqv? (car datum) 'letrec) (cond [(< (length datum) 3) (eopl:error 'parse-exp "Not enough arguments for letrec statement ~s" datum)] [(not (list? (cadr datum))) (eopl:error 'parse-exp "Incorrect variable binding structure in letrec statement ~s" datum)] [(not (andmap list? (cadr datum))) (eopl:error 'parse-exp "Non-list inside of variable binding structure in letrec statement ~s" datum)] [(not (andmap (lambda (x) (equal? (length x) 2)) (cadr datum))) (eopl:error 'parse-exp "Variable bind is incorrect in letrec statement ~s" datum)] [(not (andmap symbol? (map car (cadr datum)))) (eopl:error 'parse-exp "Attempting to bind non-symbol in letrec statement ~s" datum)] [(not (andmap expression? (map parse-exp (map cadr (cadr datum))))) (eopl:error 'parse-exp "Attemping to bind variable to non-expression in letrec statement ~s" datum)] [else (letrec-exp (map car (cadr datum)) (map parse-exp (map cadr (cadr datum))) (map parse-exp (cddr datum)))])] [else (app-exp (parse-exp (car datum)) (map parse-exp (cdr datum)))])] [else (eopl:error 'parse-exp "Invalid concrete syntax ~s" datum)]))) (define literal? (lambda (x) (or (number? x) (boolean? x) (vector? x) (string? x) (not (pair? x))))) ;Convert improper list to proper (define i-to-p (lambda (lst) (cond [(pair? lst) (cons (car lst) (i-to-p (cdr lst)))] [else (list lst)]))) ;Convert proper list to improper (define p-to-i (lambda (lst) (cond [(null? (cdr lst)) (car lst)] [else (cons (car lst) (p-to-i (cdr lst)))]))) (define all-symbols? (lambda (lst) (cond [(null? lst) #t] [(symbol? lst) #t] [(not (symbol? (car lst))) #f] [else (all-symbols? (cdr lst))]))) (define unparse-exp (lambda (exp) (cases expression exp [var-exp (id) id] [lit-exp (id) id] [lambda-exp (id bodies) (cons* 'lambda id (map unparse-exp bodies))] [lambda-exp-var (ids bodies) (cons* 'lambda ids (map unparse-exp bodies))] [lambda-exp-improper (ids bodies) (cons* 'lambda (p-to-i ids) (map unparse-exp bodies))] [if-then-exp (body then) (list 'if (unparse-exp body) (unparse-exp then))] [if-then-else-exp (body then els) (list 'if (unparse-exp body) (unparse-exp then) (unparse-exp els))] [set!-exp (id r-val-exp) (cons* 'set! id (unparse-exp r-val-exp))] [let-exp (ids var-bodies bodies) (cons* 'let (map (lambda (x y) (list x y)) ids (map unparse-exp var-bodies)) (map unparse-exp bodies))] [let-name-exp (name ids var-bodies bodies) (cons* 'let name (map (lambda (x y) (list x y)) ids (map unparse-exp var-bodies)) (map unparse-exp bodies))] [let*-exp (ids var-bodies bodies) (cons* 'let* (map (lambda (x y) (list x y)) ids (map unparse-exp var-bodies)) (map unparse-exp bodies))] [letrec-exp (ids var-bodies bodies) (cons* 'letrec (map (lambda (x y) (list x y)) ids (map unparse-exp var-bodies)) (map unparse-exp bodies))] [app-exp (rator rands) (cons* (unparse-exp rator) (map unparse-exp rands))]))) ;---------------+ ; | ; ENVIRONMENTS | ; | ;---------------+ (define empty-env (lambda () (empty-env-record))) (define extend-env (lambda (syms vals env) (extended-env-record syms vals env))) (define list-find-position (lambda (sym los) (list-index (lambda (xsym) (eqv? sym xsym)) los))) (define list-index (lambda (pred ls) (cond [(null? ls) #f] [(pred (car ls)) 0] [else (let ([list-index-r (list-index pred (cdr ls))]) (if (number? list-index-r) (+ 1 list-index-r) #f))]))) (define apply-env (lambda (env sym succeed fail) ; succeed and fail are procedures applied if the var is or isn't found, respectively. (cases environment env [empty-env-record () (fail)] [extended-env-record (syms vals env) (let ([pos (list-find-position sym syms)]) (if (number? pos) (succeed (list-ref vals pos)) (apply-env env sym succeed fail)))]))) ;-------------------+ ; | ; SYNTAX EXPANSION | ; | ;-------------------+ ; To be added later ;---------------+ ; | ; INTERPRETER | ; | ;---------------+ ; top-level-eval evaluates a form in the global environment (define top-level-eval (lambda (form env) ; later we may add things that are not expressions. (eval-exp form env))) ; eval-exp is the main component of the interpreter (define eval-exp (let ([identity-proc (lambda (x) x)]) (lambda (exp env) (cases expression exp [lit-exp (datum) datum] [var-exp (id) (apply-env env id ; look up its value. (lambda (x) x) ; proc to call if id is in the environment (lambda () (eopl:error 'apply-env ; procedure to call if id not in env "variable not found in environment: ~s" id)))] [lambda-exp-var (id bodies) (closure id bodies env)] [let-exp (ids var-bodies bodies) (eval-bodies bodies (extend-env ids (eval-rands var-bodies env) env))] [if-then-exp (body then) (if (eval-exp body env) (eval-exp then env))] [if-then-else-exp (body then els) (if (eval-exp body env) (eval-exp then env) (eval-exp els env))] [app-exp (rator rands) (let ([proc-value (eval-exp rator env)] [args (eval-rands rands env)]) (apply-proc proc-value args))] [else (eopl:error 'eval-exp "Bad abstract syntax: ~a" exp)])))) ; evaluate the list of operands, putting results into a list (define eval-rands (lambda (rands env) (map (lambda (x) (eval-exp x env)) rands))) (define eval-bodies (lambda (bodies env) (let loop ([bodies bodies]) (if (null? (cdr bodies)) (eval-exp (car bodies) env) (begin (eval-exp (car bodies) env) (loop (cdr bodies))))))) ; Apply a procedure to its arguments. ; At this point, we only have primitive procedures. ; User-defined procedures will be added later. (define apply-proc (lambda (proc-value args) (cases proc-val proc-value [prim-proc (op) (apply-prim-proc op args)] [closure (params bodies env) (eval-bodies bodies (extend-env params args env))] [else (eopl:error 'apply-proc "Attempt to apply bad procedure: ~s" proc-value)]))) (define *prim-proc-names* '(+ - * / = <= >= add1 sub1 zero? not cons car cdr list null? assq eq? equal? atom? length list->vector list? pair? procedure? vector->list vector make-vector vector-ref vector? number? symbol? set-car! set-cdr! vector-set! display newline caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr)) (define init-env ; for now, our initial global environment only contains (extend-env ; procedure names. Recall that an environment associates *prim-proc-names* ; a value (not an expression) with an identifier. (map prim-proc *prim-proc-names*) (empty-env))) ; Usually an interpreter must define each ; built-in procedure individually. We are "cheating" a little bit. (define apply-prim-proc (lambda (prim-proc args) (case prim-proc [(+) (apply + args)] [(-) (apply - args)] [(*) (apply * args)] [(/) (apply / args)] [(add1) (+ (car args) 1)] [(sub1) (- (car args) 1)] [(cons) (cons (car args) (cadr args))] [(=) (= (car args) (cadr args))] [(zero?) (zero? (car args))] [(not) (not (car args))] [(<=) (<= (car args) (cadr args))] [(>=) (>= (car args) (cadr args))] [(car) (car (car args))] [(cdr) (cdr (car args))] [(list) (cons (car args) (cdr args))] [(null?) (null? (car args))] [(assq) (assq (car args) (cdr args))] [(eq?) (eq? (car args) (cadr args))] [(equal?) (equal? (car args) (cadr args))] [(atom?) (atom? (car args))] [(length) (length (car args))] [(list->vector) (list->vector (car args))] [(list?) (list? (car args))] [(pair?) (pair? (car args))] [(procedure?) (proc-val? (car args))] [(vector->list) (vector->list (car args))] [(vector) (vector (car args))] [(make-vector) (make-vector (car args))] [(vector-ref) (vector-ref (car args) (cadr args))] [(vector?) (vector? (car args))] [(number?) (number? (car args))] [(symbol?) (symbol? (car args))] [(set-car!) (set-car! (car args) (cadr args))] [(set-cdr!) (set-cdr! (car args) (cadr args))] [(vector-set!) (vector-set! (car args) (cadr args) (caddr args))] [(display) (display (car args))] [(newline) (newline)] [(caar) (caar (car args))] [(cadr) (cadr (car args))] [(cdar) (cdar (car args))] [(cddr) (cddr (car args))] [(caaar) (caaar (car args))] [(caadr) (caadr (car args))] [(cadar) (cadar (car args))] [(caddr) (caddr (car args))] [(cdaar) (cdaar (car args))] [(cdadr) (cdadr (car args))] [(cddar) (cddar (car args))] [(cdddr) (cdddr (car args))] [else (error 'apply-prim-proc "Bad primitive procedure name: ~s" prim-proc)]))) (define rep ; "read-eval-print" loop. (lambda () (display "--> ") ;; notice that we don't save changes to the environment... (let ([answer (top-level-eval (parse-exp (read)))]) ;; TODO: are there answers that should display differently? (eopl:pretty-print answer) (newline) (rep)))) ; tail-recursive, so stack doesn't grow. (define eval-one-exp (lambda (x) (top-level-eval (parse-exp x) init-env)))
false
26bd172572799cdc4a8789ebcc0bf6d648af5389
43612e5ed60c14068da312fd9d7081c1b2b7220d
/unit-tests/IFT3065/3/etape3-tail-call.scm
2646cd0d2df18a86f1285351c7c9b13a9d555097
[ "BSD-3-Clause" ]
permissive
bsaleil/lc
b1794065183b8f5fca018d3ece2dffabda6dd9a8
ee7867fd2bdbbe88924300e10b14ea717ee6434b
refs/heads/master
2021-03-19T09:44:18.905063
2019-05-11T01:36:38
2019-05-11T01:36:38
41,703,251
27
1
BSD-3-Clause
2018-08-29T19:13:33
2015-08-31T22:13:05
Scheme
UTF-8
Scheme
false
false
93
scm
etape3-tail-call.scm
(define (loop i) (if (< i 0) i (loop (- i 3)))) (println (loop 1000000)) ;-2
false
e80d23caf83182c9acaf8e7b175b309bb31bcdf3
e26e24bec846e848630bf97512f8158d8040689c
/benchmarks/gabriel/chibi-prelude.scm
3f9fb1d14ce1f2efcc8bcee13f9d862c059547b7
[ "BSD-3-Clause" ]
permissive
traviscross/chibi-scheme
f989df49cb76512dc59f807aeb2426bd6fe1c553
97b81d31300945948bfafad8b8a7dbffdcd61ee3
refs/heads/master
2023-09-05T16:57:14.338631
2014-04-01T22:02:02
2014-04-01T22:02:02
18,473,315
2
0
null
null
null
null
UTF-8
Scheme
false
false
872
scm
chibi-prelude.scm
(import (chibi time) (scheme cxr) (srfi 33) (srfi 39)) (define (timeval->milliseconds tv) (quotient (+ (* 1000000 (timeval-seconds tv)) (timeval-microseconds tv)) 1000)) (define (time* thunk) (call-with-output-string (lambda (out) (let* ((start (car (get-time-of-day))) (result (parameterize ((current-output-port out)) (thunk))) (end (car (get-time-of-day))) (msecs (- (timeval->milliseconds end) (timeval->milliseconds start)))) (display "user: ") (display msecs) (display " system: 0") (display " real: ") (display msecs) (display " gc: 0") (newline) (display "result: ") (write result) (newline) result)))) (define-syntax time (syntax-rules () ((_ expr) (time* (lambda () expr)))))
true
09e9ef729a62ba61d3724250e56fed10468d275d
18fb2e9f5ce1a5c876d9e0694ed001d8932b2fde
/examples/atomic-petrinets/examples/cookie-automaton.scm
7ce5f3546d4147577350e95befd21f45b02d9739
[ "MIT", "X11" ]
permissive
christoff-buerger/racr
0669a0ba537c6b6d7e4379dbb453c42ff8456d25
b83e18d751bb11f844e8face7a81770819f1a3a9
refs/heads/master
2023-09-04T05:25:04.113295
2023-08-19T22:29:23
2023-08-19T22:29:23
32,183,687
33
10
null
2017-02-13T20:38:03
2015-03-13T22:19:59
Scheme
UTF-8
Scheme
false
false
9,255
scm
cookie-automaton.scm
; This program and the accompanying materials are made available under the ; terms of the MIT license (X11 license) which accompanies this distribution. ; Author: C. Bürger ; Specification of the cookie automaton given on page 21, Figure 2.1 in ; ; "Petrinetze: Modellierungstechnik, Analysemethoden, Fallstudien" ; Wolfgang Reisig ; Vieweg+Teubner, 2010 ; 978-3-8348-1290-2 #!r6rs (import (rnrs) (racr core) (racr testing) (atomic-petrinets user-interface) (atomic-petrinets analyses)) (define Box 'Box) (define Box* 'Box*) (define Euro 'Euro) (define Token 'Token) (define (make-cookie-automaton) (petrinet: ; Places with start marking: ((H Box Box Box Box Box Box* Box*) ; H with tokens of two different kind (D Token) ; D with 'Token token (G Token) ; G with 'Token token (E 7) ; E with integer token of value 7 (A) (B) (C) (F)) ; All other places have no tokens. ; Transitions: (transition: c ((D (token (eq? token Token)))) ; Consume 'Token token from D. ((A 'Euro))) ; Produce 'Euro token in A. (transition: e ((A (euro (eq? euro Euro)))) ; Consume 'Euro token from A. ((D 'Token))) ; Produce 'Token token in D. (transition: a ((A (euro (eq? euro Euro))) ; Consume 'Euro token from A. (E (x (>= x 2))) ; Consume an x >= 2 token from E. (G (token (eq? token Token)))) ; Consume 'Token token from G. ((D 'Token) ; Produce 'Token token in D. (E (- x 2)) ; Put x decremented by two in E. (F 'Euro) ; Produce 'Euro token in F. (B 'Token))) ; Produce 'Token token in B. (transition: b ((B (token (eq? token Token))) ; Consume 'Euro token from B. (H (y #t) (z #t))) ; Consume two arbitrary tokens from H. ((G 'Token) ; Produce 'Token token in G. (C y z))) ; Put tokens consumed from H in C. (transition: d ((C (y #t))) ; Consume arbitrary token from C. ()))) ; d is cold-transition: produce nothing. (define (run-tests) ; Test fixture: Transition b nondeterministicly selects boxes from H! ; To test markings without an explosion of possible combinations... (set! Box* Box) ; ...rectify the box types. (let ((net (make-cookie-automaton))) (assert-marking net (list 'D Token) (list 'E 7) (list 'G Token) (list 'H Box Box Box Box Box Box* Box*)) (assert-enabled net 'c) (fire-transition! (=t-lookup net 'c)) (assert-marking net (list 'A Euro) (list 'E 7) (list 'G Token) (list 'H Box Box Box Box Box Box* Box*)) (assert-enabled net 'a 'e) (fire-transition! (=t-lookup net 'a)) (assert-marking net (list 'B Token) (list 'D Token) (list 'E 5) (list 'F Euro) (list 'H Box Box Box Box Box Box* Box*)) (assert-enabled net 'b 'c) (fire-transition! (=t-lookup net 'c)) (assert-marking net (list 'A Euro) (list 'B Token) (list 'E 5) (list 'F Euro) (list 'H Box Box Box Box Box Box* Box*)) (assert-enabled net 'b 'e) (fire-transition! (=t-lookup net 'e)) (assert-marking net (list 'B Token) (list 'D Token) (list 'E 5) (list 'F Euro) (list 'H Box Box Box Box Box Box* Box*)) (assert-enabled net 'b 'c) (fire-transition! (=t-lookup net 'c)) (assert-marking net (list 'A Euro) (list 'B Token) (list 'E 5) (list 'F Euro) (list 'H Box Box Box Box Box Box* Box*)) (assert-enabled net 'b 'e) (fire-transition! (=t-lookup net 'b)) (assert-marking net (list 'A Euro) (list 'C Box Box) (list 'E 5) (list 'F Euro) (list 'G Token) (list 'H Box Box Box Box* Box*)) (assert-enabled net 'a 'd 'e) (fire-transition! (=t-lookup net 'e)) (assert-marking net (list 'C Box Box) (list 'D Token) (list 'E 5) (list 'F Euro) (list 'G Token) (list 'H Box Box Box Box* Box*)) (assert-enabled net 'c 'd) (fire-transition! (=t-lookup net 'c)) (assert-marking net (list 'A Euro) (list 'C Box Box) (list 'E 5) (list 'F Euro) (list 'G Token) (list 'H Box Box Box Box* Box*)) (assert-enabled net 'a 'd 'e) (fire-transition! (=t-lookup net 'd)) (assert-marking net (list 'A Euro) (list 'C Box) (list 'E 5) (list 'F Euro) (list 'G Token) (list 'H Box Box Box Box* Box*)) (assert-enabled net 'a 'e 'd) (fire-transition! (=t-lookup net 'd)) (assert-marking net (list 'A Euro) (list 'E 5) (list 'F Euro) (list 'G Token) (list 'H Box Box Box Box* Box*)) (assert-enabled net 'a 'e) (fire-transition! (=t-lookup net 'a)) (assert-marking net (list 'B Token) (list 'D Token) (list 'E 3) (list 'F Euro Euro) (list 'H Box Box Box Box* Box*)) (assert-enabled net 'b 'c) (fire-transition! (=t-lookup net 'b)) (assert-marking net (list 'C Box Box) (list 'D Token) (list 'E 3) (list 'F Euro Euro) (list 'G Token) (list 'H Box Box* Box*)) (assert-enabled net 'c 'd) (fire-transition! (=t-lookup net 'c)) (assert-marking net (list 'A Euro) (list 'C Box Box) (list 'E 3) (list 'F Euro Euro) (list 'G Token) (list 'H Box Box* Box*)) (assert-enabled net 'a 'd 'e) (fire-transition! (=t-lookup net 'a)) (assert-marking net (list 'B Token) (list 'C Box Box) (list 'D Token) (list 'E 1) (list 'F Euro Euro Euro) (list 'H Box Box* Box*)) (assert-enabled net 'b 'c 'd) (fire-transition! (=t-lookup net 'b)) (assert-marking net (list 'C Box* Box Box Box) (list 'D Token) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'c 'd) (fire-transition! (=t-lookup net 'c)) (assert-marking net (list 'A Euro) (list 'C Box* Box Box Box) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'd 'e) (fire-transition! (=t-lookup net 'd)) (assert-marking net (list 'A Euro) (list 'C Box* Box Box) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'd 'e) (fire-transition! (=t-lookup net 'd)) (assert-marking net (list 'A Euro) (list 'C Box* Box) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'd 'e) (fire-transition! (=t-lookup net 'd)) (assert-marking net (list 'A Euro) (list 'C Box*) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'd 'e) (fire-transition! (=t-lookup net 'd)) (assert-marking net (list 'A Euro) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'e) (fire-transition! (=t-lookup net 'e)) (assert-marking net (list 'D Token) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'c) (fire-transition! (=t-lookup net 'c)) (assert-enabled net 'e) (assert-marking net (list 'A Euro) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (fire-transition! (=t-lookup net 'e)) (assert-marking net (list 'D Token) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'c) (fire-transition! (=t-lookup net 'c)) (assert-marking net (list 'A Euro) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*)) (assert-enabled net 'e) (fire-transition! (=t-lookup net 'e)) ; ... (assert-enabled net 'c) (assert-marking net (list 'D Token) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*))) (let ((net (make-cookie-automaton))) (rewrite-delete (=t-lookup net 'e)) (run-petrinet! net) (assert-marking net (list 'A Euro) (list 'E 1) (list 'F Euro Euro Euro) (list 'G Token) (list 'H Box*))) (let ((net (make-cookie-automaton))) (rewrite-delete (=p-lookup net 'A)) (assert-exception petrinets-exception? (run-petrinet! net))) (set! Box* 'Box*)) ; Undo test fixture. (initialise-petrinet-language #t) (run-tests)
false
c76a4931377342146bb5cedb3ab9ef18551118b5
4b480cab3426c89e3e49554d05d1b36aad8aeef4
/chapter-02/ex2.06-Solidone.ss
cae6486d107549baf68ebc9a811b37fe213568ac
[]
no_license
tuestudy/study-sicp
a5dc423719ca30a30ae685e1686534a2c9183b31
a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f
refs/heads/master
2021-01-12T13:37:56.874455
2016-10-04T12:26:45
2016-10-04T12:26:45
69,962,129
0
0
null
null
null
null
UTF-8
Scheme
false
false
569
ss
ex2.06-Solidone.ss
; I just get a hint from D-Gun's wiki. ; from url - http://deisys.upnl.org/wiki/doku.php?id=sicp:exercise_ch2.1 (define zero (lambda (f) (lambda (x) x))) (define (add-1 n) (lambda (f) (lambda (x) (f ((n f) x))))) (define (inc x) (+ x 1)) ;(add-1 zero) (define one (lambda (f) (lambda (x) (f x)))) (define two (lambda (f) (lambda (x) (f (f x))))) (define (add a b) (lambda (f) (lambda (x) ((a f) ((b f) x))))) (define (tonum n) ((n (lambda (x) (+ x 1))) 0)) ; test-case (tonum zero) (tonum (add-1 zero)) (tonum one) (tonum two) (tonum (add one two))
false
12a22f2a8e62eb2929318ad599b911a9364c25a5
51d30de9d65cc3d5079f050de33d574584183039
/prim/environments.scm
be972be147d0c01efe0a13986d970f62f26dbc31
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
langmartin/ykk
30feb00265d603ef765b5c664d2f759be34b7b89
dd6e441dddd5b6363ee9adbbdd0f346c1522ffcf
refs/heads/master
2016-09-05T20:01:19.353224
2009-12-10T16:25:55
2009-12-10T16:25:55
408,478
0
1
null
null
null
null
UTF-8
Scheme
false
false
4,528
scm
environments.scm
;;;; An implementation of first-class, functionally updatable ;;;; environments. ;;;; ;;;; Environments are a mapping of names (see names.scm) to bindings ;;;; (see bindings.scm). Operations on environments include: name ;;;; lookup, adding names, removing names, and casting bindings. ;;; Public ;; Environments are tracked through the dynamic environment (define-fluid ($current-environment #f) current-environment with-current-environment) (define (lookup name) (environment-ref (current-environment) name)) ;; Some basic operations (define (environment-ref env name) (binding-value (%environment-ref env name))) (define (extend-environment env definitions) (map->evolved (lambda (def) ;; def looks like: (NAME VALUE) or (NAME TYPE VALUE) (cond ((not (pair? def)) (error "extend-environment: malformed definition ~S" def)) ((not (null? (cddr def))) (cons (car def) (apply new-binding def))) (else (cons (car def) (apply new-value-binding def))))) env definitions)) (define (forget-bindings env names) (evolve env (delete-names (package-definitions env) names))) (define (cast-bindings env name/type-pairs) (map->evolved (lambda (pair) (cons (car pair) (cast-binding (%environment-ref env (car pair)) (cdr pair)))) env name/type-pairs)) ;;; Internal (define (%environment-ref env name) (carefully env name identity (lambda () (error "undefined variable ~S in ~S" name env)))) ;; FIXME: this should be as careful as CAREFULLY in rts/env.scm (define (carefully env name found not-found) (let ((probe (lookup-name (package-definitions env) name))) (cond ((not probe) (not-found)) ((not (binding? probe)) (error "environment-ref: strange binding ~S in ~S" probe env)) (else (found probe))))) (define (extend-with-native-package env package export?) (extend-environment env (native-package->ykk-definitions package export?))) (define (native-package->ykk-definitions env export?) (let ((defs '())) (for-each-definition (lambda (name binding) (if (export? name binding) (set! defs (cons (list name binding) defs)))) env) defs)) ;;; Package-internal ;; An environment is actually a package (define-record-type rtd/package (really-make-package uid definitions all) package? (uid package-uid) (definitions package-definitions) (all all-packages set-all-packages!)) (define-record-discloser rtd/package (lambda (rec) `(env ,(package-uid rec) ,(list-names (package-definitions rec))))) ;; A package knows about itself and any previous packages. In the S48 ;; implementation, this part is actually a global table. We keep a ;; functionally updatable record inside each package in this ;; implementation. ;; FIXME: ALL-PACKAGES isn't being used. Maybe remove it? (define remember-package cons) (define (empty-package-set) '()) (define (make-package definitions all-packages) (let* ((uuid (uuidgen)) (package (really-make-package uuid definitions #f))) (set-all-packages! package (remember-package package all-packages)) (make-immutable! package))) (define (empty-environment) (make-package (make-name-table) (all-packages (current-environment)))) (define (ground-level-package) (make-package (make-name-table) (empty-package-set))) (define (evolve old definitions) (make-package definitions (all-packages old))) (define (map->evolved proc env lst) (evolve env (define-names (package-definitions env) (map proc lst)))) (set-fluid! $current-environment (ground-level-package)) ;;; Tests (assert (package? (empty-environment))) (let ((test-env (extend-environment (empty-environment) `((a ,:symbol av) (b bv))))) (with-current-environment test-env (lambda () (assert (lookup 'a) => 'av))) (with-current-environment (cast-bindings test-env `((b . ,:symbol))) (lambda () (assert (lookup 'b) => 'bv) (assert (binding-type (%environment-ref (current-environment) 'b)) => :symbol))))
false
484c569c509f850f1461296a44ecffd381a69d4c
2ff77aed2df384e78c210ef28f607c23352e5b8d
/examples/09-opengl/on-create.scm
b338b3857a1f9f3b0396dc4e20d24a592eaf66e3
[ "Apache-2.0" ]
permissive
rafleon/KawaDroid
14d65fb74686c421cab4ca9785266daa321ffacc
5b218826146320f442a55e20171875cb208c7b56
refs/heads/master
2020-12-24T15:58:15.249818
2015-05-12T05:07:51
2015-05-12T05:07:51
33,094,259
18
3
null
null
null
null
UTF-8
Scheme
false
false
1,125
scm
on-create.scm
(require kawa.android.mainact) (define mydir (loaddir *activity*)) (define sa string-append) ;; for compiledexload (load (sa mydir "/cdl.scm")) ;; load the needed wrapper classes for OpenGL (define glsvc (compiledexload "glsvclass" (sa mydir "/GLSurfaceViewClass.scm"))) (define glrc (compiledexload "glrclass" (sa mydir "/GLRenderClass.scm"))) ;; save the loaded classes to global variables so all threads can use them. ((gnu.mapping.Environment:getGlobal):put 'glsvc glsvc) ((gnu.mapping.Environment:getGlobal):put 'glrc glrc) (load (sa mydir "/telnetrepl.scm")) ;; Instantiate some objects and load a blank GLSurfaceView (let* ((act::android.app.Activity *activity*) (glsv::glsvc (glsvc act)) (glr::android.opengl.GLSurfaceView$Renderer (glrc)) ) (glsv:addRenderer glr) (act:setContentView glsv) ) ;; You can edit these files and then re-load them from the telnet REPL. ;; These are interpreted, not compiled into bytecode. ;; Load the renderer lambda to draw a triangle. (load (sa mydir "/myrender.scm")) ;; Load the lambda to respond to touch events. (load (sa mydir "/mytouch.scm"))
false
33c219ed14f44b5ae3ccb2499b6b8c5c1771637a
91fc138a1cbcbeffaf6cf4eb0e3ae188b2ca257f
/Chapter 2 Exercises/2.07.scm
157fd501a76d746d4d0fde614a93a1f717740b4a
[]
no_license
jlollis/sicp-solutions
0bd8089aea5a85c7b34e43a0f34db87e4161bee0
7b03befcfe82e26a7fb28d94bc99292bc484f9dd
refs/heads/master
2022-06-15T23:34:10.541201
2022-06-02T03:32:46
2022-06-02T03:32:46
130,729,626
9
1
null
null
null
null
UTF-8
Scheme
false
false
1,389
scm
2.07.scm
#lang sicp #| 2.1.4 Extended Excercise: Interval Arithmetic (exercises 2.7 - 2.11) Exercise 2.7. Alyssa’s program is incomplete because she has not specified the implementation of the interval abstraction. Here is a definition of the interval constructor: (define (make-interval a b) (cons a b)) Define selectors upper-bound and lower-bound to complete the implementation. |# ; from 2.1.4 ; add intervals (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) ; multiply intervals (define (mul-interval x y) (let ((p1 (* (lower-bound x) (lower-bound y))) (p2 (* (lower-bound x) (upper-bound y))) (p3 (* (upper-bound x) (lower-bound y))) (p4 (* (upper-bound x) (upper-bound y)))) (make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4)))) ; divide intervals (define (div-interval x y) (mul-interval x (make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y))))) ; answer (define (make-interval a b) (cons a b)) (define (lower-bound i) (car i)) (define (upper-bound i) (cdr i)) ; test (define a (make-interval 2 6)) (define b (make-interval 8 16)) ; test (upper-bound a) (lower-bound a) (upper-bound b) (lower-bound b) ; test with given above (add-interval a b) (mul-interval a b) (div-interval a b)
false
321a4fc3d2041fd7f196829fabdaab0eddd88e81
958488bc7f3c2044206e0358e56d7690b6ae696c
/scheme/types/unit-test.scm
c9b8d9d7a9eddf80a0a00a70b2c1c475eef557b4
[]
no_license
possientis/Prog
a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4
d4b3debc37610a88e0dac3ac5914903604fd1d1f
refs/heads/master
2023-08-17T09:15:17.723600
2023-08-11T12:32:59
2023-08-11T12:32:59
40,361,602
3
0
null
2023-03-27T05:53:58
2015-08-07T13:24:19
Coq
UTF-8
Scheme
false
false
1,102
scm
unit-test.scm
(require 'object->string) (load "main.scm") (define (assert-equals left right message) (if (not (equal? left right)) (error "unit-test failure: " (string-append message ": value = " (object->string left) ": expected = " (object->string right))))) (define (unit-test) ; (newline) (display "unit-test: starting test\n") ; true (assert-equals (evaluate #t) #t "true.0") ; false (assert-equals (evaluate #f) #f "false.0") ; if (assert-equals (evaluate '(if #t #f #t)) #f "if.0") (assert-equals (evaluate '(if #t #t #f)) #t "if.1") (assert-equals (evaluate '(if #f #t #f)) #f "if.2") (assert-equals (evaluate '(if #f #f #t)) #t "if.3") ; 0 (assert-equals (evaluate 0) 0 "zero.0") ; succ (assert-equals (evaluate '(succ 0)) 1 "succ.0") ; pred (assert-equals (evaluate '(pred (succ (succ 0)))) 1 "pred.0") ; zero? (assert-equals (evaluate '(zero? 0)) #t "zero?.0") (assert-equals (evaluate '(zero? (succ 0))) #f "zero?.1") (display "unit-test: test complete\n")) (unit-test) (exit 0)
false
e7aa7b888d305c609a3c4e6cbfc46fb46e01ea6d
b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6
/test/concurrentScheme/threads/variations/indexer4.scm
0bb45474664116f47e3e635afd0d1dedb4e18333
[]
no_license
acieroid/scala-am
eff387480d3baaa2f3238a378a6b330212a81042
13ef3befbfc664b77f31f56847c30d60f4ee7dfe
refs/heads/master
2021-01-17T02:21:41.692568
2021-01-15T07:51:20
2021-01-15T07:51:20
28,140,080
32
16
null
2020-04-14T08:53:20
2014-12-17T14:14:02
Scheme
UTF-8
Scheme
false
false
1,133
scm
indexer4.scm
;; Example taken from Dynamic Partial Order Reduction, Figure 1 ;; Expected result: #t (let* ((size 128) (max 4) (table (make-vector size 0)) (thread (lambda (tid) (letrec ((hash (lambda (w) (modulo (* w 7) size))) (process (lambda (m) (if (< m max) (letrec ((w (+ (* 11 (+ m 1)) tid)) (update (lambda (h) (if (cas-vector table h 0 w) #t (update (modulo (+ h 1) size)))))) (update (hash w)) (process (+ m 1))) #t)))) (process 0)))) (t1 (fork (thread 1))) (t2 (fork (thread 2))) (t3 (fork (thread 3))) (t4 (fork (thread 4)))) (join t1) (join t2) (join t3) (join t4) #t)
false
0a0a34dd503fc5f0e174a66640ef9abcb4ea7364
0bb7631745a274104b084f6684671c3ee9a7b804
/tests/unit-tests/04-list/second.scm
ca59a1a5e274277b3a36f412b91e309607551bc0
[ "Apache-2.0", "LGPL-2.1-only", "LicenseRef-scancode-free-unknown", "GPL-3.0-or-later", "LicenseRef-scancode-autoconf-simple-exception" ]
permissive
feeley/gambit
f87fd33034403713ad8f6a16d3ef0290c57a77d5
7438e002c7a41a5b1de7f51e3254168b7d13e8ba
refs/heads/master
2023-03-17T06:19:15.652170
2022-09-05T14:31:53
2022-09-05T14:31:53
220,799,690
0
1
Apache-2.0
2019-11-10T15:09:28
2019-11-10T14:14:16
null
UTF-8
Scheme
false
false
1,098
scm
second.scm
(include "#.scm") (define bool #f) (define z0 (list)) (define z1 (list 100)) (define z2 (list 100 101)) (define z3 (list 100 101 102)) (define z4 (list 100 101 102 103)) (define z5 (list 100 101 102 103 104)) (define z6 (list 100 101 102 103 104 105)) (define z7 (list 100 101 102 103 104 105 106)) (define z8 (list 100 101 102 103 104 105 106 107)) (define z9 (list 100 101 102 103 104 105 106 107 108)) (define z10 (list 100 101 102 103 104 105 106 107 108 109)) (check-tail-exn type-exception? (lambda () (second z0))) (check-tail-exn type-exception? (lambda () (second z1))) (check-equal? (second z2) 101 ) (check-equal? (second z3) 101 ) (check-equal? (second z4) 101 ) (check-equal? (second z5) 101 ) (check-equal? (second z6) 101 ) (check-equal? (second z7) 101 ) (check-equal? (second z8) 101 ) (check-equal? (second z9) 101 ) (check-equal? (second z10) 101 ) (check-tail-exn type-exception? (lambda () (second bool))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (second))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (second z10 z10)))
false
f9c1c3b03beff5c2aaf4cc7f8531e4fe3c646771
74d2f4ec77852839450ab8563971a5e0f615c019
/chapter_02/chapter_2_3_4.scm
c4e82d188267c066aaab237adb1eac3460cb78be
[]
no_license
wangoasis/sicp
b56960a0c3202ce987f176507b1043ed632ed6b3
07eaf8d46f7b8eae5a46d338a4608d8e993d4568
refs/heads/master
2021-01-21T13:03:11.520829
2016-04-22T13:52:15
2016-04-22T13:52:15
53,835,426
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,583
scm
chapter_2_3_4.scm
( define ( make-leaf symbol weight ) ( list 'leaf symbol weight ) ) ( define ( leaf? object ) ( eq? ( car object ) 'leaf ) ) ( define ( symbol-leaf object ) ( cadr object ) ) ( define ( weight-leaf object ) ( caddr object ) ) ( define ( make-code-tree left right ) ( list left right ( append ( symbol left ) ( symbol right ) ) ( + ( weight left ) ( weight right ) ) ) ) ( define ( left-branch tree ) ( car tree ) ) ( define ( right-branch tree ) ( cadr tree ) ) ( define ( symbol tree ) ( if ( leaf? tree ) ( list ( symbol-leaf tree ) ) ( caddr tree ) ) ) ( define ( weight tree ) ( if ( leaf? tree ) ( weight-leaf tree ) ( cadddr tree ) ) ) ( define ( decode bits-list tree ) ( define ( decode-1 bits current-branch ) ( if ( null? bits ) '() ( let ( ( next-branch ( choose-branch ( car bits ) current-branch ) ) ) ( if ( leaf? next-branch ) ( cons ( symbol-leaf next-branch ) ( decode-1 ( cdr bits ) tree ) ) ( decode-1 ( cdr bits ) next-branch ) ) ) ) ) ( decode-1 bits-list tree ) ) ( define ( choose-branch bit branch ) ( if ( = bit 0 ) ( left-branch branch ) ( right-branch branch ) ) ) ( define ( adjoin-set x set ) ( cond ( ( null? set ) ( list x ) ) ( ( < ( weight x ) ( weight ( car set ) ) ) ( cons x set ) ) ( else ( cons ( car set ) ( adjoin-set x ( cdr set ) ) ) ) ) ) ( define ( make-leaf-set pairs ) ( if ( null? pairs ) '() ( let ( ( pair ( car pairs ) ) ) ( adjoin-set ( make-leaf ( car pair ) ( cadr pair ) ) ( make-leaf-set ( cdr pairs ) ) ) ) ) ) ( define tree ( list ( list 'A 4 ) ( list 'B 2 ) ( list 'C 1 ) ( list 'D 1 ) ) ) ;;; exercise 2.67 ( define sample-tree ( make-code-tree ( make-leaf 'A 4 ) ( make-code-tree ( make-leaf 'B 2 ) ( make-code-tree ( make-leaf 'D 1 ) ( make-leaf 'C 1 ) ) ) ) ) ( define sample-message (list 0 1 1 0 0 1 0 1 0 1 1 1 0 ) ) ;;; exercise 2.68 ( define ( encode message tree ) ( if ( null? message ) '() ( append ( encode-symbol ( car message ) tree ) ( encode ( cdr message ) tree ) ) ) ) ( define ( encode-symbol letter tree ) ( cond ( ( leaf? tree ) '() ) ( ( symbol-in-tree? letter ( left-branch tree ) ) ( cons 0 ( encode-symbol letter ( left-branch tree ) ) ) ) ( ( symbol-in-tree? letter ( right-branch tree ) ) ( cons 1 ( encode-symbol letter ( right-branch tree ) ) ) ) ( else ( error " not in tree " ) ) ) ) ( define ( symbol-in-tree? letter tree ) ( define ( iter x symbol-list ) ( cond ( ( null? symbol-list ) #f ) ( ( eq? x ( car symbol-list ) ) #t ) ( else ( iter x ( cdr symbol-list ) ) ) ) ) ( iter letter ( symbol tree ) ) ) ( define sample-code ( list 'A 'D 'A 'B 'B 'C 'A ) ) ;;; exercise 2.69 ( define sample-pairs '( ( A 4 ) ( B 2 ) ( C 1 ) ( D 1 ) ) ) ( define ( generate-huffman-tree pairs ) ( successive-merge ( make-leaf-set pairs ) ) ) ( define ( successive-merge leaf-set ) ( define ( iter set res ) ( cond ( ( null? set ) res ) ( else ( iter ( cdr set ) ( make-code-tree ( car set ) res ) ) ) ) ) ( iter ( cddr leaf-set ) ( make-code-tree ( car leaf-set ) ( cadr leaf-set ) ) ) ) ( define main ( generate-huffman-tree sample-pairs ) )
false
c9310105fb8c134fb355d126e908cf13efb8bf45
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/net/mail/mail-message.sls
abd138027831ddc6a6d442725680e6b0e7284385
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,113
sls
mail-message.sls
(library (system net mail mail-message) (export new is? mail-message? dispose alternate-views attachments bcc body-get body-set! body-update! body-encoding-get body-encoding-set! body-encoding-update! cc delivery-notification-options-get delivery-notification-options-set! delivery-notification-options-update! from-get from-set! from-update! headers is-body-html?-get is-body-html?-set! is-body-html?-update! priority-get priority-set! priority-update! reply-to-get reply-to-set! reply-to-update! sender-get sender-set! sender-update! subject-get subject-set! subject-update! subject-encoding-get subject-encoding-set! subject-encoding-update! to) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.Net.Mail.MailMessage a ...))))) (define (is? a) (clr-is System.Net.Mail.MailMessage a)) (define (mail-message? a) (clr-is System.Net.Mail.MailMessage a)) (define-method-port dispose System.Net.Mail.MailMessage Dispose (System.Void)) (define-field-port alternate-views #f #f (property:) System.Net.Mail.MailMessage AlternateViews System.Net.Mail.AlternateViewCollection) (define-field-port attachments #f #f (property:) System.Net.Mail.MailMessage Attachments System.Net.Mail.AttachmentCollection) (define-field-port bcc #f #f (property:) System.Net.Mail.MailMessage Bcc System.Net.Mail.MailAddressCollection) (define-field-port body-get body-set! body-update! (property:) System.Net.Mail.MailMessage Body System.String) (define-field-port body-encoding-get body-encoding-set! body-encoding-update! (property:) System.Net.Mail.MailMessage BodyEncoding System.Text.Encoding) (define-field-port cc #f #f (property:) System.Net.Mail.MailMessage CC System.Net.Mail.MailAddressCollection) (define-field-port delivery-notification-options-get delivery-notification-options-set! delivery-notification-options-update! (property:) System.Net.Mail.MailMessage DeliveryNotificationOptions System.Net.Mail.DeliveryNotificationOptions) (define-field-port from-get from-set! from-update! (property:) System.Net.Mail.MailMessage From System.Net.Mail.MailAddress) (define-field-port headers #f #f (property:) System.Net.Mail.MailMessage Headers System.Collections.Specialized.NameValueCollection) (define-field-port is-body-html?-get is-body-html?-set! is-body-html?-update! (property:) System.Net.Mail.MailMessage IsBodyHtml System.Boolean) (define-field-port priority-get priority-set! priority-update! (property:) System.Net.Mail.MailMessage Priority System.Net.Mail.MailPriority) (define-field-port reply-to-get reply-to-set! reply-to-update! (property:) System.Net.Mail.MailMessage ReplyTo System.Net.Mail.MailAddress) (define-field-port sender-get sender-set! sender-update! (property:) System.Net.Mail.MailMessage Sender System.Net.Mail.MailAddress) (define-field-port subject-get subject-set! subject-update! (property:) System.Net.Mail.MailMessage Subject System.String) (define-field-port subject-encoding-get subject-encoding-set! subject-encoding-update! (property:) System.Net.Mail.MailMessage SubjectEncoding System.Text.Encoding) (define-field-port to #f #f (property:) System.Net.Mail.MailMessage To System.Net.Mail.MailAddressCollection))
true
c88a9e341328d5148eca8e8aa4115ef4a6becf38
84bd214ba2422524b8d7738fb82dd1b3e2951f73
/chapter_1/exercises/1.10/ackermann.scm
47567e979b0c7906f0da421f692bfdd4dace2f31
[]
no_license
aequanimitas/sicp-redux
e5ef32529fa727de0353da973425a326e152c388
560b2bd40a12df245a8532de5d76b0bd2e033a64
refs/heads/master
2020-04-10T06:49:13.302600
2016-03-15T00:59:24
2016-03-15T00:59:24
21,434,389
1
0
null
null
null
null
UTF-8
Scheme
false
false
452
scm
ackermann.scm
(define (ackermann x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else (ackermann (- x 1) (ackermann x (- y 1)))))) (ackermann 1 10) (ackermann 2 4) (ackermann 3 3) (define (f n) (ackermann 0 n)) (define (g n) (ackermann 1 n)) (define (h n) (ackermann 2 n)) (f 0) (f 1) (f 2) (f 3) (f 4) (f 5) (g 1) (g 2) (g 3) (g 4) (g 5) (h 1) (h 2) (h 3) (h 4) (h 5) ; this is an error
false
f199771b40ab9b95eaaa997b7769deb7a5746682
9b0c653f79bc8d0dc87526f05bdc7c9482a2e277
/2/2-41.ss
923e3c5700f9829b3ec6912550e98ec68ed6a838
[]
no_license
ndNovaDev/sicp-magic
798b0df3e1426feb24333658f2313730ae49fb11
9715a0d0bb1cc2215d3b0bb87c076e8cb30c4286
refs/heads/master
2021-05-18T00:36:57.434247
2020-06-04T13:19:34
2020-06-04T13:19:34
251,026,570
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,174
ss
2-41.ss
(define (dn x) (display x) (newline)) (define nil '()) (define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) (accumulate op initial (cdr sequence))))) (define (enumerate-interval x y) (if (> x y) nil (cons x (enumerate-interval (+ x 1) y)))) (define (flatmap proc seq) (accumulate append nil (map proc seq))) ; *********************** (define (unique-pairs n) (flatmap (lambda (x) (map (lambda (y) (list y x)) (enumerate-interval 1 (- x 1)))) (enumerate-interval 1 n))) (define (unique3 n) (flatmap (lambda (x) (map (lambda (p) (append p (list x))) (unique-pairs (- x 1)))) (enumerate-interval 1 n))) (define (proc n s) (filter (lambda (p) (let ((x (car p)) (y (cadr p)) (z (caddr p))) (= s (+ x y z)))) (unique3 n))) (dn (proc 10 8)) (exit)
false
2ead0aaa86a9bc3243f3032208c2943410654a4d
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/ext/socket/socket_stub.stub
c3b372cefa55b0291a8e9e37bbd83e18f528643f
[ "BSD-3-Clause", "LicenseRef-scancode-other-permissive", "MIT", "BSD-2-Clause" ]
permissive
ktakashi/sagittarius-scheme
0a6d23a9004e8775792ebe27a395366457daba81
285e84f7c48b65d6594ff4fbbe47a1b499c9fec0
refs/heads/master
2023-09-01T23:45:52.702741
2023-08-31T10:36:08
2023-08-31T10:36:08
41,153,733
48
7
NOASSERTION
2022-07-13T18:04:42
2015-08-21T12:07:54
Scheme
UTF-8
Scheme
false
false
10,241
stub
socket_stub.stub
;; -*- scheme -*- #!compatible (decl-code (.include <sagittarius.h>) (.define "LIBSAGITTARIUS_EXT_BODY") (.include <sagittarius/extend.h> "sagittarius-socket.h")) (define-cise-stmt check-string-or-false ((_ name o) `(unless (or (SG_STRINGP ,o) (SG_FALSEP ,o)) (Sg_WrongTypeOfArgumentViolation ',name (SG_MAKE_STRING "string or #f") ,o '())))) (define-type <socket> "SgSocket*") (define-type <addrinfo> "SgAddrinfo*") (define-type <sockaddr> "SgSockaddr*") (define-type <ip-address> "SgIpAddress*") (define-type <socket-info> "SgSocketInfo*") (define-type <fdset> "SgFdSet*") (define-c-proc addrinfo? (o) ::<boolean> :constant SG_ADDRINFOP) (define-c-proc make-addrinfo () Sg_MakeAddrinfo) (define-c-proc get-addrinfo (node service hints::<addrinfo>) (check-string-or-false make-client-socket node) (check-string-or-false make-client-socket service) (result (Sg_GetAddrinfo node service hints))) (define-c-proc sockaddr? (o) ::<boolean> :constant SG_SOCKADDRP) (define-c-proc make-socket (f::<ifixnum> t::<ifixnum> :optional (p::<ifixnum> 0)) Sg_CreateSocket) (define-c-proc socket-setsockopt! (socket::<socket> level::<ifixnum> name::<ifixnum> value) Sg_SocketSetopt) (define-c-proc socket-getsockopt (socket::<socket> level::<ifixnum> name::<ifixnum> size::<ifixnum>) Sg_SocketGetopt) (define-c-proc socket-connect! (socket::<socket> info::<addrinfo> :optional (timeout #f)) Sg_SocketConnect) (define-c-proc socket-bind! (socket::<socket> info::<addrinfo>) Sg_SocketBind) (define-c-proc socket-listen! (socket::<socket> backlog::<ifixnum>) Sg_SocketListen) ;;; error message (define-c-proc socket-error-message (socket::<socket>) :no-side-effect Sg_SocketErrorMessage) (define-c-proc socket-last-error (socket::<socket>) ::<fixnum> :no-side-effect (result (-> socket lastError))) (define-c-proc socket? (o) ::<boolean> :constant SG_SOCKETP) ;; socket ports (define-c-proc socket-port (o::<socket> :optional (close?::<boolean> #t)) Sg_MakeSocketPort) (define-c-proc socket-input-port (o::<socket>) Sg_MakeSocketInputPort) (define-c-proc socket-output-port (o::<socket>) Sg_MakeSocketOutputPort) (define-c-proc shutdown-port (o::<port> how::<ifixnum>) ::<void> (Sg_ShutdownPort o how)) (define-c-proc shutdown-output-port (o::<port>) ::<void> (Sg_ShutdownPort o SHUT_WR)) (define-c-proc shutdown-input-port (o::<port>) ::<void> (Sg_ShutdownPort o SHUT_RD)) (define-c-proc socket-accept (o::<socket>) Sg_SocketAccept) (define-c-proc socket-send (o::<socket> bv::<bytevector> :optional (flags::<ifixnum> 0)) ::<fixnum> (result (Sg_SocketSend (SG_SOCKET o) (SG_BVECTOR_ELEMENTS bv) (SG_BVECTOR_SIZE bv) flags))) (define-c-proc socket-send/range (o::<socket> bv::<bytevector> :optional (start::<fixnum> 0) (len::<fixnum> -1) (flags::<ifixnum> 0)) ::<fixnum> (when (< len 0) (set! len (SG_BVECTOR_SIZE bv))) (when (< start 0) (Sg_AssertionViolation 'socket-send/range (SG_MAKE_STRING "start must be non negative") (SG_LIST4 o bv (SG_MAKE_INT start) (SG_MAKE_INT len)))) (when (< (- (SG_BVECTOR_SIZE bv) start) len) (Sg_AssertionViolation 'socket-send/range (SG_MAKE_STRING "Specified length is too big") (SG_LIST4 o bv (SG_MAKE_INT start) (SG_MAKE_INT len)))) (result (Sg_SocketSend (SG_SOCKET o) (+ (SG_BVECTOR_ELEMENTS bv) start) len flags))) (define-c-proc socket-sendto (o::<socket> bv::<bytevector> addr::<sockaddr> :optional (flags::<ifixnum> 0)) ::<fixnum> (result (Sg_SocketSendTo (SG_SOCKET o) (SG_BVECTOR_ELEMENTS bv) (SG_BVECTOR_SIZE bv) flags addr))) (define-c-proc socket-sendto/range (o::<socket> bv::<bytevector> addr::<sockaddr> :optional (start::<fixnum> 0) (len::<fixnum> -1) (flags::<ifixnum> 0)) ::<fixnum> (when (< len 0) (set! len (SG_BVECTOR_SIZE bv))) (when (< start 0) (Sg_AssertionViolation 'socket-sendto/range (SG_MAKE_STRING "start must be non negative") (SG_LIST4 o bv (SG_MAKE_INT start) (SG_MAKE_INT len)))) (when (< (- (SG_BVECTOR_SIZE bv) start) len) (Sg_AssertionViolation 'socket-sendto/range (SG_MAKE_STRING "Specified length is too big") (SG_LIST4 o bv (SG_MAKE_INT start) (SG_MAKE_INT len)))) (result (Sg_SocketSendTo (SG_SOCKET o) (+ (SG_BVECTOR_ELEMENTS bv) start) len flags addr))) (define-c-proc %socket-recv (o::<socket> len::<fixnum> :optional (flags::<ifixnum> 0)) (let ((data (Sg_MakeByteVector len 0)) (res::long (Sg_SocketReceive (SG_SOCKET o) (SG_BVECTOR_ELEMENTS data) len flags))) (cond ((== len res) (result data)) ((< res 0) ;; most probably socket is non-blocking (result #f)) (else ;; shrink (let ((r (Sg_MakeByteVector res 0))) (Sg_ByteVectorCopyX (SG_BVECTOR data) 0 (SG_BVECTOR r) 0 res) (result r)))))) ;; destructive (define-c-proc %socket-recv! (o::<socket> bv::<bytevector> start::<fixnum> len::<fixnum> :optional (flags::<ifixnum> 0)) ::<fixnum> ;; sanity check (when (or (< start 0) (> len (- (SG_BVECTOR_SIZE bv) start))) (Sg_AssertionViolation 'socket-recv! (SG_MAKE_STRING "out of range") (SG_LIST4 o bv (SG_MAKE_INT start) (SG_MAKE_INT len)))) (result (Sg_SocketReceive (SG_SOCKET o) (+ (SG_BVECTOR_ELEMENTS bv) start) len flags))) (define-c-proc socket-recvfrom (o::<socket> len::<fixnum> addr::<sockaddr> :optional (flags::<ifixnum> 0)) (let ((data (Sg_MakeByteVector len 0)) (res::long (Sg_SocketReceiveFrom (SG_SOCKET o) (SG_BVECTOR_ELEMENTS data) len flags addr))) (cond ((== len res) (result data)) ((< res 0) ;; most probably socket is non-blocking (result #f)) (else ;; shrink (let ((r (Sg_MakeByteVector res 0))) (Sg_ByteVectorCopyX (SG_BVECTOR data) 0 (SG_BVECTOR r) 0 res) (result r)))))) (define-c-proc socket-recvfrom! (o::<socket> bv::<bytevector> start::<fixnum> len::<fixnum> addr::<sockaddr> :optional (flags::<ifixnum> 0)) ::<fixnum> ;; sanity check (when (or (>= start (SG_BVECTOR_SIZE bv)) (> len (- (SG_BVECTOR_SIZE bv) start))) (Sg_AssertionViolation 'socket-recvfrom! (SG_MAKE_STRING "out of range") (SG_LIST4 o bv (SG_MAKE_INT start) (SG_MAKE_INT len)))) (result (Sg_SocketReceiveFrom (SG_SOCKET o) (+ (SG_BVECTOR_ELEMENTS bv) start) len flags addr))) (define-c-proc socket-shutdown (o::<socket> how::<ifixnum>) ::<void> Sg_SocketShutdown) (define-c-proc socket-close (o::<socket>) ::<void> Sg_SocketClose) (define-c-proc socket-closed? (o::<socket>) ::<boolean> (result (not (Sg_SocketOpenP o)))) (define-c-proc socket-fd (o::<socket>) ::<fixnum> :no-side-effect (result (-> o socket))) (define-c-proc socket-node (o::<socket>) :no-side-effect (result (-> o node))) (define-c-proc socket-service (o::<socket>) :no-side-effect (result (-> o service))) (define-c-proc socket-nonblocking! (o::<socket>) ::<boolean> Sg_SocketNonblocking) (define-c-proc socket-blocking! (o::<socket>) ::<boolean> Sg_SocketBlocking) (define-c-proc nonblocking-socket? (o::<socket>) ::<boolean> (result (-> o nonblocking))) (define-c-proc make-fdset () :no-side-effect Sg_MakeFdSet) (define-c-proc fdset? (o) ::<boolean> :constant SG_FDSETP) (define-c-proc sockets->fdset (sockets) :no-side-effect Sg_SocketsToFdSet) (define-c-proc collect-sockets (fdset) :no-side-effect (cond ((SG_FALSEP fdset) (result SG_NIL)) ;; interrupted? ((SG_FDSETP fdset) (result (Sg_CopyList (-> (SG_FDSET fdset) sockets)))) (else (Sg_AssertionViolation 'collect-sockets (SG_MAKE_STRING "<fdset> required") (SG_LIST1 fdset))))) (define-c-proc fdset-sockets (fdset::<fdset>) :no-side-effect (result (Sg_CopyList (-> fdset sockets)))) (define-cise-stmt check-fd-range ((_ fd) (let ((fd_ (gensym))) ;; seems windows socket descriptor is not ordered or so ;; so just let it go. `(.if "!defined(_MSC_VER)" (let ((,fd_ :: int ,fd)) (when (or (< ,fd_ 0) (>= ,fd_ FD_SETSIZE)) (Sg_Error (UC "Socket descriptor value is out of range: (0 <= %d < %d)") ,fd_ FD_SETSIZE))))))) (define-c-proc fdset-set! (fdset::<fdset> socket::<socket> flag::<boolean>) ::<void> (let ((fd::int (cast int (-> socket socket)))) (check-fd-range fd) (cond (flag (FD_SET fd (& (-> fdset fdset))) (set! (-> fdset sockets) (Sg_Cons socket (-> fdset sockets))) (when (< (-> fdset maxfd) fd) (set! (-> fdset maxfd) fd))) (else (FD_CLR fd (& (-> fdset fdset))) (let ((p SG_FALSE) (h (-> fdset sockets))) (for (() (not (SG_NULLP h)) (set! p h h (SG_CDR h))) (when (SG_EQ (SG_CAR h) socket) (if (SG_FALSEP p) (set! (-> fdset sockets) (SG_CDR h)) (SG_SET_CDR p (SG_CDR h))) (break)))) (when (== (-> fdset maxfd) fd) (let ((i::int (- (-> fdset maxfd) 1))) (for (() (>= i 0) (post-- i)) (when (FD_ISSET i (& (-> fdset fdset))) (break))) (set! (-> fdset maxfd) i))))))) (define-c-proc fdset-ref (fdset::<fdset> socket::<socket>) ::<boolean> (setter fdset-set!) (let ((fd::int (cast int (-> socket socket)))) (if (< fd 0) (result FALSE) ;; invalid or closed socket so never be set (begin (check-fd-range fd) (result (FD_ISSET fd (& (-> fdset fdset)))))))) (define-c-proc fdset-clear! (fdset::<fdset>) ::<void> (set! (-> fdset sockets) '()) (FD_ZERO (& (-> fdset fdset)))) (define-c-proc socket-select (reads writes errors timeval) Sg_SocketSelect) (define-c-proc socket-select! (reads writes errors timeval) Sg_SocketSelectX) (define-c-proc socket-peer (o::<socket>) :no-side-effect Sg_SocketPeer) (define-c-proc socket-name (o::<socket>) :no-side-effect Sg_SocketName) (define-c-proc socket-info (o::<socket>) :no-side-effect Sg_SocketInfo) (define-c-proc socket-info? (o) ::<boolean> SG_SOCKET_INFO_P) (define-c-proc ip-address->string (ip::<ip-address>) :no-side-effect Sg_IpAddressToString) ;; constant? (define-c-proc ip-address->bytevector (ip::<ip-address>) :no-side-effect (result (-> ip ip))) (define-c-proc ip-address? (o) ::<boolean> SG_IP_ADDRESS_P)
false
70f98bc3fd8eafb19c7923c102ac5d554766e5c4
d11ad5e19d63d2cf6ca69f12ecae02a9b9871ad3
/Test.ss
1f9a05e09ec2d0f5eb4bfd26a66fe90718d763ab
[ "Apache-2.0" ]
permissive
willfaught/sham1
3e708368a02ce8af204dbf26cc94f01e75ea39a8
371e9a6fd810628f8e9a79868b9f457bfcf8dc29
refs/heads/master
2022-08-28T20:46:09.904927
2022-08-18T22:04:51
2022-08-18T22:04:51
151,862
1
0
null
null
null
null
UTF-8
Scheme
false
false
800
ss
Test.ss
(module Test scheme (require (planet schematics/schemeunit:3:3) (planet schematics/schemeunit:3/text-ui) #;(rename-in (lib "BoundaryTest.ss" "sham") (testSuite boundary)) #;(rename-in (lib "CompilationTest.ss" "sham" "haskell") (testSuite compilation)) (rename-in (lib "ParsingTest.ss" "sham" "haskell") (testSuite parsing)) #;(rename-in (lib "SyntaxCheckingTest.ss" "sham" "haskell") (testSuite syntaxChecking)) (rename-in (lib "TransformationTest.ss" "sham" "haskell") (testSuite transformation)) (rename-in (lib "TypeCheckingTest.ss" "sham" "haskell") (testSuite typeChecking))) (define (runTests) (run-tests (test-suite "All" #;boundary #;compilation parsing #;syntaxChecking transformation typeChecking))))
false
7c1b29b58115c9aa72685ae4624f06ca63088c17
d37f41737effcc07eb2bda1e3c4f54ac02aa7afa
/import-all.ss
ddb857dfe45aaeaa7a7aae12f0d12d1242f07fa8
[]
no_license
plt/planet-server
ea3cae6f59679e98df0cff1639fb4a0b12e821cd
a8074909b4c570b750a47e19d8d27d6c7c27ed92
refs/heads/master
2020-12-24T15:49:51.488474
2016-03-10T03:00:07
2016-03-10T03:00:07
4,863,599
1
0
null
null
null
null
UTF-8
Scheme
false
false
9,765
ss
import-all.ss
(module import-all mzscheme (provide (all-defined)) #| import-all.ss --- initial import of old planet files into the new server. |# (require "db.ss" "package-creation.ss" "configuration.ss") (require (lib "etc.ss") (lib "match.ss") (lib "list.ss")) (startup) (define default-repository-struct (car (get-all-repositories))) ;; ============================================================ ;; import : path -> void ;; does the whole importing deal. relies on accurate information in the info table at the end ;; of this file (define (import path) (import-into-database (path->users path info))) ;; path->users : path (string -> (list string[realname] string[email])) -> (listof user) ;; read in a users record from an old-style planet repository (define (path->users path info-about) (listof-each (directory-list path) (username-path) (where (directory-exists? (build-path path username-path))) (let ([username (path->string username-path)]) (match-let ([`(,realname ,email) (info-about username)]) (make-user username realname email (listof-each (directory-list (build-path path username-path)) (pkg-path) (unless (and (directory-exists? (build-path path username-path pkg-path)) (regexp-match #rx"^[a-zA-Z0-9-]*\\.plt$" (path->string pkg-path))) (error 'path->users "found a weird path: ~e" (build-path path username-path pkg-path))) (let* ([base (build-path path username-path pkg-path)] [all-updates (apply append (listof-each (directory-list base) (maj) (where (number? (string->number (path->string maj)))) (listof-each (directory-list (build-path base maj)) (min) (where (number? (string->number (path->string min)))) (make-update (string->number (path->string maj)) (string->number (path->string min)) (build-path base maj min pkg-path)))))] [sorted-updates (sort all-updates (λ (a b) (or (< (update-maj a) (update-maj b)) (and (= (update-maj a) (update-maj b)) (< (update-min a) (update-min b))))))]) (when (null? sorted-updates) (error 'path->users "something went wrong, because this path has no pkgversions: ~e" base)) (make-package (path->string pkg-path) (update-file (car sorted-updates)) (cdr sorted-updates))))))))) ;; ============================================================ ;; import proceeds as follows: ;; for each user: ;; - create user ;; - for each package owned by user: ;; * create the package ;; * for each package update: ;; # add the update, marking major or minor as appropriate (define (import-into-database users) (parameterize ([SEND-EMAILS? #f]) (do-for-each users (u) (let ([user (create-new-user (user-name u) (user-realname u) (user-email u) (random-password))]) (do-for-each (user-packages u) (p) (create-package user (package-name p) (get-package-bytes p) (list (DEFAULT-REPOSITORY))) (let ([package (get-package (user-name u) (package-name p))]) (unless package (error 'import "something went wrong: added package but then it didn't exist when I looked it up: ~e ~e" (user-name u) (package-name p))) (do-for-each (package-updates p) (update) (update-package user package (backwards-compatible? update) (get-update-bytes update) (list default-repository-struct))))))))) ;; ---------------------------------------- (define-struct user (name ; string realname ; string email ; string packages ; (listof package) )) (define-struct package (name ; string file ; path updates ; listof update )) (define-struct update (maj ; nat min ; nat file ; path )) ;; ---------------------------------------- ;; get-package-bytes : package -> bytes ;; gets the bytes associated with this package (done on demand to avoid loading the whole repository in memory at once) (define (get-package-bytes p) (file->bytes (package-file p))) ;; ---------------------------------------- ;; backwards-compatible? : update -> boolean ;; determines if the given update is marked as backwards-compatible (define (backwards-compatible? u) (not (= (update-min u) 0))) ;; get-update-bytes : update -> bytes ;; gets the bytes corresponding to this update. (define (get-update-bytes u) (file->bytes (update-file u))) ;; ---------------------------------------- ;; file->bytes : path -> bytes ;; reads the entire given file into a byte string (define (file->bytes file) (let ([len (file-size file)]) (with-input-from-file file (λ () (read-bytes len))))) ;; random-password : -> string ;; generates a random password to seed the database (define (random-password) (list->string (build-list 8 (λ (_) (integer->char (random-int-in 32 127)))))) ;; random-int-in : int int -> int ;; delivers a random int in the range [lo,hi] (define (random-int-in lo hi) (+ (random (- hi lo)) lo)) ;; ============================================================ ;; scaffolding (define-syntax do-for-each (syntax-rules () [(do-for-each list-expr (name) body1 body2 ...) (for-each (λ (name) body1 body2 ...) list-expr)])) (define-syntax listof-each (syntax-rules (where) [(listof-each list-expr (name) (where filter-expr) body1 body2 ...) (map (λ (name) body1 body2 ...) (filter (λ (name) filter-expr) list-expr))] [(listof-each list-expr (name) body1 body2 ...) (listof-each list-expr (name) (where #t) body1 body2 ...)])) ;; ============================================================ ;; missing data (define-syntax info-fn (syntax-rules () [(info-fn (e1 e2 ...) ...) (let ([ht (hash-table 'equal (e1 (list e2 ...)) ...)]) (λ (arg) (hash-table-get ht arg (λ () (list "unknown" "[email protected]")))))])) (define info (info-fn ("abromfie" "Aleks Bromfield" "[email protected]") ("ams" "Adam Shaw" "[email protected]") ("cce" "Carl Eastlund" "[email protected]") ("cdutchyn" "Christopher Dutchyn" "[email protected]") ("clements" "John Clements" "[email protected]") ("cobbe" "Richard Cobbe" "[email protected]") ("daedalus" "Ryan Kaulakis" "[email protected]") ("dfisher" "David Fisher" "[email protected]") ("dfriedman" "Dan Friedman" "[email protected]") ("dherman" "Dave Herman" "[email protected]") ("dignatof" "Daniel Ignatoff" "[email protected]") ("divascheme" "DivaScheme" "[email protected]") ("dvanhorn" "David Van Horn" "[email protected]") ("dyoo" "Danny Yoo" "[email protected]") ("evanfarrer" "Evan Farrer" "[email protected]") ("jacobm" "Jacob Matthews" "[email protected]") ("jaymccarthy" "Jay McCarthy" "[email protected]") ("jim" "Jim Bender" "[email protected]") ("kazzmir" "Jon Rafkind" "[email protected]") ("lizorkin" "Dmitry Lizorkin" "[email protected]") ("lshift" "LShift Ltd." "[email protected]") ("mato" "Robert Matovinovic" "[email protected]") ("mburns" "Mike Burns" "[email protected]") ("neil" "Neil Van Dyke" "[email protected]") ("oesterholt" "Hans Oesterholt-Dijkema" "[email protected]") ("pjmatos" "Paulo Jorge Matos" "[email protected]") ("planet" "PLaneT" "[email protected]") ("plt" "PLT Scheme" "[email protected]") ("robby" "Robby Findler" "[email protected]") ("ryanc" "Ryan Culpepper" "[email protected]") ("samth" "Sam Tobin-Hochstadt" "[email protected]") ("schematics" "Schematics" "[email protected]") ("soegaard" "Jens Axel Soegaard" "[email protected]") ("sweeney" "Corey Sweeney" "[email protected]") ("untyped" "Untyped" "[email protected]") ("vyzo" "Dimitris Vyzovitis" "[email protected]") ("williams" "Douglas Williams" "[email protected]") ("wmfarr" "Will M. Farr" "[email protected]") ("zck" "Chongkai Zhu" "[email protected]"))) )
true
927cf2ffcaf7f5f8117622517f6e6d0db0e9bf5f
7aeb920de21547a1d9c714b029bbf3a9e7df449e
/scheme/data-structures/variable-width-integer.scm
7211a2fcd062283b0584e14b3dcb50319022c588
[ "BSD-2-Clause" ]
permissive
ft/chip-remote
f8ac5a2d7597d24f44ac287836be3422a32283d4
2a64df611214f7e3eb55d4ead76e270351158cdb
refs/heads/master
2023-04-30T08:38:16.483240
2023-01-05T04:01:44
2023-01-05T04:01:44
117,028,633
2
1
null
null
null
null
UTF-8
Scheme
false
false
5,363
scm
variable-width-integer.scm
;; Copyright (c) 2022 chip-remote workers, All rights reserved. ;; ;; Terms for redistribution and use can be found in LICENCE. (define-module (data-structures variable-width-integer) #:use-module (ice-9 match) #:use-module (ice-9 optargs) #:use-module (rnrs bytevectors) #:use-module (chip-remote bit-operations) #:use-module (chip-remote codecs) #:use-module (chip-remote semantics) #:use-module (chip-remote utilities) #:export (varint-decode varint-encode varint-length varint-min-chunks varint-bits->chunks varint-last-octet?)) (define *value-bits-per-octet* 7) (define *continuation-mask* #x80) (define *value-mask* #x7f) (define (varint-last-octet? o) (zero? (logand o *continuation-mask*))) (define (varint-length bv offset) (let loop ((n 0)) (if (varint-last-octet? (bytevector-u8-ref bv (+ offset n))) (1+ n) (loop (1+ n))))) (define* (varint-min-chunks n s #:key width) (if width (if (zero? n) 1 (let* ((encoded (s:encode s width n)) (idx (inexact->exact (floor (1+ (log2 encoded)))))) (varint-bits->chunks idx))) (let ((select (if (negative? n) car cdr)) (compare (if (negative? n) >= <=)) (lower1 (car (s:range s 1)))) (when (and (negative? n) (zero? lower1)) (throw 'invalid-integer-type n 'unsigned-semantics)) (let loop ((width *value-bits-per-octet*) (chunks 1)) (let ((limit (select (s:range s width)))) (if (compare n limit) chunks (loop (+ *value-bits-per-octet* width) (1+ chunks)))))))) (define (varint-bits->chunks bits) (inexact->exact (ceiling (/ bits (exact->inexact *value-bits-per-octet*))))) (define (varint-extract bv offset octets) (let loop ((n (1- octets)) (acc 0)) (if (negative? n) acc (let ((v (logand *value-mask* (u8vector-ref bv (+ offset n)))) (pos (* *value-bits-per-octet* n))) (loop (1- n) (logior acc (ash v pos))))))) (define* (varint-encode value #:key return-used? buffer width (offset 0) (semantics unsigned-integer)) (when (and width (not (s:in-range? semantics width value))) (throw 'value-out-of-range value)) (let* ((min-octets (varint-min-chunks value semantics #:width width)) (octets (if width (min min-octets (varint-bits->chunks width)) min-octets)) (bits (or width (* *value-bits-per-octet* octets))) (bv (or buffer (make-u8vector octets 0))) (last (1- octets)) (encoded (s:encode semantics bits value))) (let loop ((i 0)) (if (= i octets) (if return-used? (cons octets bv) bv) (let* ((chunk (bit-extract-width encoded (* i *value-bits-per-octet*) *value-bits-per-octet*)) (octet (if (= i last) chunk (logior *continuation-mask* chunk)))) (u8vector-set! bv (+ i offset) octet) (loop (1+ i))))))) (define* (varint-decode bv #:key return-consumed? width (offset 0) (semantics unsigned-integer)) (let* ((octets (varint-length bv offset)) (bits (or width (* *value-bits-per-octet* octets))) (value (varint-extract bv offset octets)) (return-value (s:decode semantics bits value))) (if return-consumed? (cons octets return-value) return-value))) (define-syntax generate-shorthands (lambda (x) (define (make-base-name s w) (symbol-append 'varint: (match (syntax->datum s) ('unsigned-integer 'uint) ('twos-complement 'int) ('zig-zag 'sint)) (string->symbol (number->string (syntax->datum w))))) (syntax-case x () ((op (sems ...) (widths ...)) #'(begin (op sems (widths ...)) ...)) ((op sem (widths ...)) #'(begin (op sem widths) ...)) ((op s w) (let ((base (make-base-name #'s #'w))) (with-syntax ((enc (datum->syntax #'op (symbol-append base '-encode))) (dec (datum->syntax #'op (symbol-append base '-decode)))) #'(begin (define*-public (dec bv #:key return-consumed? (offset 0)) (varint-decode bv #:width w #:semantics s #:return-consumed? return-consumed? #:offset offset)) (define*-public (enc n #:key return-used? buffer (offset 0)) (varint-encode n #:width w #:semantics s #:return-used? return-used? #:buffer buffer #:offset offset))))))))) (generate-shorthands (unsigned-integer twos-complement zig-zag) (32 64 128 256 512))
true
2e9dfb4135c1a147b6c610fede2ab7ed2b5129f5
ecfd9ed1908bdc4b099f034b121f6e1fff7d7e22
/monads/monad.ss
b1eb3e6dcaf523428ebc7c0ab31c1ecdb210ac4d
[ "MIT" ]
permissive
sKabYY/palestra
36d36fc3a03e69b411cba0bc2336c43b3550841c
06587df3c4d51961d928bd8dd64810c9da56abf4
refs/heads/master
2021-12-14T04:45:20.661697
2021-11-25T08:29:30
2021-11-25T08:29:30
12,856,067
6
3
null
null
null
null
UTF-8
Scheme
false
false
253
ss
monad.ss
(define-syntax do/m (syntax-rules (<-) [(_ bind e) e] [(_ bind (v <- e0) e e* ...) (bind e0 (lambda (v) (do/m bind e e* ...)))] [(_ bind e0 e e* ...) (bind e0 (lambda (_) (do/m bind e e* ...)))]))
true
8f9fc510a09edc6480c88fa13ff37a97d22cfc79
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
/packages/slib/defmacex.scm
2b2cf889950f1cb517e5020a8ba6980040eb5c09
[ "MIT" ]
permissive
evilbinary/scheme-lib
a6d42c7c4f37e684c123bff574816544132cb957
690352c118748413f9730838b001a03be9a6f18e
refs/heads/master
2022-06-22T06:16:56.203827
2022-06-16T05:54:54
2022-06-16T05:54:54
76,329,726
609
71
MIT
2022-06-16T05:54:55
2016-12-13T06:27:36
Scheme
UTF-8
Scheme
false
false
3,111
scm
defmacex.scm
;;;"defmacex.scm" defmacro:expand* for any Scheme dialect. ;;;Copyright 1993-1994 Dorai Sitaram and Aubrey Jaffer. ; ;Permission to copy this software, to modify it, to redistribute it, ;to distribute modified versions, and to use it for any purpose is ;granted, subject to the following restrictions and understandings. ; ;1. Any copy made of this software must include this copyright notice ;in full. ; ;2. I have made no warranty or representation that the operation of ;this software will be error-free, and I am under no obligation to ;provide any services, by way of maintenance, update, or otherwise. ; ;3. In conjunction with products arising from the use of this ;material, there shall be no use of my name in any advertising, ;promotional, or sales literature without prior written consent in ;each case. ;;;expand thoroughly, not just topmost expression. While expanding ;;;subexpressions, the primitive forms quote, lambda, set!, let/*/rec, ;;;cond, case, do, quasiquote: need to be destructured properly. (if, ;;;and, or, begin: don't need special treatment.) (define (defmacro:iqq e depth) (letrec ((map1 (lambda (f x) (if (pair? x) (cons (f (car x)) (map1 f (cdr x))) x))) (iqq (lambda (e depth) (if (pair? e) (case (car e) ((quasiquote) (list (car e) (iqq (cadr e) (+ 1 depth)))) ((unquote unquote-splicing) (list (car e) (if (= 1 depth) (defmacro:expand* (cadr e)) (iqq (cadr e) (+ -1 depth))))) (else (map1 (lambda (e) (iqq e depth)) e))) e)))) (iqq e depth))) ;@ (define (defmacro:expand* e) (if (pair? e) (let* ((c (macroexpand e))) (if (not (eq? e c)) (defmacro:expand* c) (case (car e) ((quote) e) ((quasiquote) (defmacro:iqq e 0)) ((lambda define set!) (cons (car e) (cons (cadr e) (map defmacro:expand* (cddr e))))) ((let) (let ((b (cadr e))) (if (symbol? b) ;named let `(let ,b ,(map (lambda (vv) `(,(car vv) ,(defmacro:expand* (cadr vv)))) (caddr e)) ,@(map defmacro:expand* (cdddr e))) `(let ,(map (lambda (vv) `(,(car vv) ,(defmacro:expand* (cadr vv)))) b) ,@(map defmacro:expand* (cddr e)))))) ((let* letrec) `(,(car e) ,(map (lambda (vv) `(,(car vv) ,(defmacro:expand* (cadr vv)))) (cadr e)) ,@(map defmacro:expand* (cddr e)))) ((cond) `(cond ,@(map (lambda (c) (map defmacro:expand* c)) (cdr e)))) ((case) `(case ,(defmacro:expand* (cadr e)) ,@(map (lambda (c) `(,(car c) ,@(map defmacro:expand* (cdr c)))) (cddr e)))) ((do) `(do ,(map (lambda (initsteps) `(,(car initsteps) ,@(map defmacro:expand* (cdr initsteps)))) (cadr e)) ,(map defmacro:expand* (caddr e)) ,@(map defmacro:expand* (cdddr e)))) ((defmacro) (cons (car e) (cons (cadr e) (cons (caddr e) (map defmacro:expand* (cdddr e)))))) (else (map defmacro:expand* e))))) e))
false
10525ebdd22f3009a879f47276543d3eeb2ed9e8
917429e3eb6bcf2db8c71197f88b979d998b1b7e
/progs/general/kernwyk-wc.scm
3a2d98861b3ccc0e8e375e94b44a7b67beda531c
[]
no_license
mario-goulart/chicken-benchmarks
554ca8421631211a891cc497f84dfe62b8f9c8e5
ea00fe51ec33496de7c9b07fa0ec481fe59989fa
refs/heads/master
2021-11-20T21:40:55.198252
2021-10-09T18:52:48
2021-10-09T18:52:48
4,427,587
1
5
null
2019-01-27T07:59:38
2012-05-24T01:59:23
Scheme
UTF-8
Scheme
false
false
616
scm
kernwyk-wc.scm
;;; WC -- One of the Kernighan and Van Wyk benchmarks. ;;; Rewritten by Will Clinger into more idiomatic (and correct!) Scheme. (define (wcport port) (define (loop nl nw nc inword?) (let ((x (read-char port))) (cond ((eof-object? x) (list nl nw nc)) ((char=? x #\space) (loop nl nw (+ nc 1) #f)) ((char=? x #\newline) (loop (+ nl 1) nw (+ nc 1) #f)) (else (loop nl (if inword? nw (+ nw 1)) (+ nc 1) #t))))) (loop 0 0 0 #f)) (define (go x) (call-with-input-file x wcport)) (time (go "inputs/fp-numbers.data"))
false
cd717bf5fc15a48093c497fefb0b8310fe0d27c2
2ba385986ceea8f2e72b9ad70467214b05b6f09a
/orly-tests.scm
195d4a0031787a9501fdc6e980f47af7000b4561
[]
no_license
outworlder/Orly-
5e7b97d34b3721f85bdc02b7fcbc851e4e11a646
42f046ab3be23aa2a169a0c8a9e5bfd948f705e2
refs/heads/master
2021-01-17T05:53:36.208430
2012-03-01T23:36:34
2012-03-01T23:36:34
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,148
scm
orly-tests.scm
(use test) (use sql-de-lite) (use aql) (use coops) (use orly) (orly-database-url "orly-test.db") (orly-debug #t) (if (file-exists? (orly-database-url)) (delete-file (orly-database-url))) (define database-fixtures '("CREATE TABLE test1 ( id INTEGER, col2 TEXT, col3 TEXT );" "CREATE TABLE test_parent ( id INTEGER, col2 TEXT, col3 TEXT );" "CREATE TABLE test_child ( id INTEGER, parent_id TEXT, col3 TEXT );" "insert into test1 (id, col2, col3) values (1, \"col2\", \"col3\");" "insert into test1 (id, col2, col3) values (2,\"col22\", \"col23\");")) (define-model <test1> "test1" (id col2 col3)) (define-model <test-parent> "test_parent" (id col2 col3)) (has-many <test-parent> <test-child> children foreign-key: parent_id) (define-model <test-child> "test_child" (id parent_id col3)) (belongs-to <test-child> <test-parent> parent foreign-key: parent_id) (for-each (lambda (stmt) (call-with-database (orly-database-url) (lambda (database) (exec (sql database stmt))))) database-fixtures) ;;; TODO: Execute SQL here. (test-group "Queries" (test "Should be able to query a record by id" (make <test1> 'id 1 'col2 "col2" 'col3 "col3") (find-by-id <test1> 1)) (test "Should return an empty list if a record is not found" '() (find-by-id <test1> 99999)) (test "Should return a list of all rows in the database" 2 (length (find-all <test1>))) (test "Should be able to find by ID and a condition" (make <test1> 'id 1 'col2 "col2" 'col3 "col3") (find-by-id <test1> 1 conditions: `(where (= 'col2 "'col2'")))) (test "Should be able to find all records with a condition" (list (make <test1> 'id 1 'col2 "col2" 'col3 "col3")) (find-all <test1> conditions: `(where (= 'col2 "col2"))))) ;(test-group "Relationships") (delete-file (orly-database-url))
false
0b3a0c75022e0e52f720f1f9d8a95df5362f18c2
ac2a3544b88444eabf12b68a9bce08941cd62581
/gsc/tests/08-flprim/flsquare.scm
7d0fea8254f6c705bd220c1d2ac31ec01b830e45
[ "Apache-2.0", "LGPL-2.1-only" ]
permissive
tomelam/gambit
2fd664cf6ea68859d4549fdda62d31a25b2d6c6f
d60fdeb136b2ed89b75da5bfa8011aa334b29020
refs/heads/master
2020-11-27T06:39:26.718179
2019-12-15T16:56:31
2019-12-15T16:56:31
229,341,552
1
0
Apache-2.0
2019-12-20T21:52:26
2019-12-20T21:52:26
null
UTF-8
Scheme
false
false
756
scm
flsquare.scm
(declare (extended-bindings) (not constant-fold) (not safe)) (define (test val expected) (println (if (##fleqv? val expected) "same" "diff"))) (test (##flsquare 0.0) 0.0) (test (##flsquare -0.0) 0.0) (test (##flsquare 11.0) 121.0) (test (##flsquare -11.0) 121.0) (test (##flsquare 23170.0) 536848900.0) (test (##flsquare -23170.0) 536848900.0) (test (##flsquare 23171.0) 536895241.0) (test (##flsquare -23171.0) 536895241.0) (test (##flsquare 0.3) 0.09) (test (##flsquare 11.3) 127.69000000000001) (test (##flsquare -11.3) 127.69000000000001) (test (##flsquare 23170.3) 536862802.09) (test (##flsquare -23170.3) 536862802.09) (test (##flsquare 23171.3) 536909143.6899999) (test (##flsquare -23171.3) 536909143.6899999)
false
24a5a71f10ecb321163292cf9af4f43bdb4087cd
16807220b95bf9a559b97ec0de16665ff31823cb
/peacock/peck.scm
3cd2ecd6fff8365bbe4fe3898c3a735296c9eaab
[ "BSD-3-Clause" ]
permissive
cuauv/software
7263df296e01710cb414d340d8807d773c3d8e23
5ad4d52d603f81a7f254f365d9b0fe636d03a260
refs/heads/master
2021-12-22T07:54:02.002091
2021-11-18T01:26:12
2021-11-18T02:37:55
46,245,987
76
34
null
2016-08-03T05:31:00
2015-11-16T02:02:36
C++
UTF-8
Scheme
false
false
4,459
scm
peck.scm
(use srfi-13) (use posix files) (use args matchable) (define cuauv-software (get-environment-variable "CUAUV_SOFTWARE")) (if (not cuauv-software) (with-output-to-port (current-error-port) (lambda () (print "CUAUV_SOFTWARE must be set to the root of the software repository, with a trailing slash.") (exit 1)))) (define peacock-path (string-append cuauv-software "peacock/")) (define new-template-path (string-append peacock-path "peacock-template.scm")) (if (not (file-exists? new-template-path)) (abort (format "Could not find new template file at '~A'." new-template-path))) (define editor (get-environment-variable "EDITOR")) (if (not editor) (set! editor "nano")) ; Temporarily disable #warning directives until CHICKEN stops using some ; deprecated defines that cause confusing output on compile. (define csc-options '("-C" "-Wno-cpp")) (define (has-updown?) (receive (in out pid err) (process* "which" '("updown")) (receive (pid normal code) (process-wait pid) (and normal (= code 0))))) (define (ensure-scm-suffix path) (if (not (string-suffix? ".scm" path)) (string-append path ".scm") path)) (define opts (list (args:make-option (n no-updown) #:none "Disable using Updown to collect output lines.") (args:make-option (r updown-reset-length) #:optional "Updown reset length (see updown --help). Defaults to 5.") (args:make-option (h help) #:none "Display this text." (usage)))) (define (usage) (with-output-to-port (current-error-port) (lambda () (print "Usage: " (car (argv)) " <command> [options...] [files...]") (print "Defined commands: " (string-join (map (lambda (x) (symbol->string (caar x))) commands) ", ") ".") (newline) (print (args:usage opts)))) (exit 1)) (define (command-usage command short #!optional long) (with-output-to-port (current-error-port) (lambda () (print "Usage: " (car (argv)) " " command " " short) (if long (print long)) (exit 1)))) (define (run bin args) (process-execute bin args)) (define commands `(((interpret i) ,(lambda (options operands) (define (run-usage #!optional long) (command-usage "run" "<file>" long)) (if (null? operands) (run-usage)) (define file (ensure-scm-suffix (car operands))) (if (not (file-exists? file)) (run-usage (format "Could not find the file '~A'." file))) (when (and (has-updown?) (not (assq 'no-updown options))) (define updown-reset-length (or (alist-ref 'updown-reset-length options) "5")) (define updown-args (list (string-append "--reset-length=" updown-reset-length) "-xNOTE")) (run "updown" (append updown-args (list "--" "csi" "-I" peacock-path "-s" file)))) (run "csi" (list "-I" peacock-path "-s" file)))) ((compile c) ,(lambda (options operands) (define (run-usage #!optional long) (command-usage "compile" "<file>" long)) (if (null? operands) (run-usage)) (define file (ensure-scm-suffix (car operands))) (if (not (file-exists? file)) (run-usage (format "Could not find the file '~A.'" file))) (run "csc" (append csc-options (list "-I" peacock-path file))))) ((new n) ,(lambda (options operands) (define (new-usage #!optional long) (command-usage "new" "<path>" long)) (if (null? operands) (new-usage)) (define path (ensure-scm-suffix (car operands))) (if (file-exists? path) (new-usage (format "A file already exists at path '~A'." file))) (file-copy new-template-path path) (run editor (list path)))) )) (define (command-ref command) (let loop ((rest commands)) (if (null? rest) #f (match (car rest) (((names ...) proc) (if (member command names) proc (loop (cdr rest)))))))) (set-signal-handler! signal/int (lambda (sig) (exit 1))) (receive (options operands) (args:parse (command-line-arguments) opts) (if (null? operands) (usage)) (let ((c (command-ref (string->symbol (car operands))))) (if (not c) (usage)) (c options (cdr operands)))) ; vim: set lispwords+=args\:make-option,set-signal-handler! :
false
33d45c2e53fceae1670c39c34bbaabec28a7a1d0
b43e36967e36167adcb4cc94f2f8adfb7281dbf1
/sicp/ch2/exercises/2.12.scm
73fb7055621c1b9aaa295994f4793351244f4dbb
[]
no_license
ktosiu/snippets
79c58416117fa646ae06a8fd590193c9dd89f414
08e0655361695ed90e1b901d75f184c52bb72f35
refs/heads/master
2021-01-17T08:13:34.067768
2016-01-29T15:42:14
2016-01-29T15:42:14
53,054,819
1
0
null
2016-03-03T14:06:53
2016-03-03T14:06:53
null
UTF-8
Scheme
false
false
161
scm
2.12.scm
(define (make-center-percent center percent) (cons center percent)) (define (percent interval) (cdr interval)) (define (center interval) (car interval))
false
291ed77ee5ef40594f460443f74e0e0f3bdd8bdc
d7be097df2ebadb550543843a165220f5019e97f
/util.ss
c1b19c0a0a10a584ec476f8c91cc75aa8b3f433e
[]
no_license
cpw666/Scheme-Interpreter-PLC
78a187c8a8627d43578ad68b7b933c84e6a6f59b
28aec90d96d4d23cc65246ead68b778eec892c46
refs/heads/master
2021-06-01T14:39:12.135779
2016-05-21T20:07:46
2016-05-21T20:07:46
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
708
ss
util.ss
; find the last element of a pair or list -- both (last-elem '(1 2 3 4)) ; and (last-elem '(1 2 3 . 4)) return 4. ; Instead of throwing an exception when given '() as input, returns '() (define (last-elem pr) (cond ((not (pair? pr)) pr) ((null? (cdr pr)) (car pr)) (else (last-elem (cdr pr))) ) ) ; get all but the last element of a pair or list ; (e.g. (all-but-last-elem '(1 2 3)) and (all-but-last-elem '(1 2 . 3)) ; both evaluate to '(1 2) (define (all-but-last-elem pr) (cond ((not (pair? pr)) '()) ((null? (cdr pr)) '()) (else (cons (car pr) (all-but-last-elem (cdr pr)))) ) ) (define (concat-symbols x y) (string->symbol (string-append (symbol->string x) (symbol->string y))) )
false
cfce3a39cf42bda61ee0e24d8cd5c458bc5b7bee
ece1c4300b543df96cd22f63f55c09143989549c
/Chapter5/Exercise5.39.scm
02cf03341ba1f318e4b72aff9147945ac03df287
[]
no_license
candlc/SICP
e23a38359bdb9f43d30715345fca4cb83a545267
1c6cbf5ecf6397eaeb990738a938d48c193af1bb
refs/heads/master
2022-03-04T02:55:33.594888
2019-11-04T09:11:34
2019-11-04T09:11:34
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,043
scm
Exercise5.39.scm
;Exercise 5.39: Write a procedure lexical-address-lookup that implements the new lookup operation. It should take two arguments—a lexical address and a run-time environment—and return the value of the variable stored at the specified lexical address. Lexical-address-lookup should signal an error if the value of the variable is the symbol *unassigned*.331 Also write a procedure lexical-address-set! that implements the operation that changes the value of the variable at a specified lexical address. (load "/Users/soulomoon/git/SICP/material/allcode/ch5-eceval-support.scm") ; implement list-set! get-lexical-frame get-lexical-value as helper function (define (list-set! lst pos value) (define (iter l n) (cond ((null? l) (error "list-set!: displacement number overflow: " pos)) ((= 0 n) (set-car! l value)) (else (iter (cdr l) (- n 1))))) (iter lst pos)) (define (get-lexical-frame n e) (cond ((eq? e the-empty-environment) (error "getframe: frame-number overflow")) ((= n 0) (first-frame e)) (else (get-lexical-frame (- n 1) (enclosing-environment e))))) (define (get-lexical-value n frame) (list-ref (frame-values frame) n)) (define (lexical-address-lookup l-address r-env) (let* ((frame-number (car l-address)) (displacement-number (cdr l-address)) (frame (get-lexical-frame frame-number r-env)) (val (get-lexical-value displacement-number frame))) (if (equal? "*unassigned*" val) (error "lexical-address-lookup *unassigned*:" l-address) val))) (define (lexical-address-set! l-address r-env value) (let* ((frame-number (car l-address)) (displacement-number (cdr l-address)) (frame (get-lexical-frame frame-number r-env))) (list-set! (frame-values frame) displacement-number value))) ;;;;;;;test;;;;;;;;; ;(define avariables ; '(a b c d e)) ;(define avalues ; '(1 2 3 4 5)) ;(define initial-env ; (extend-environment avariables avalues the-empty-environment)) ; ;(define a avariables) ;(set! avariables avalues) ;(set! avalues a) ; ;(define new-env ; (extend-environment avariables avalues initial-env)) ; ;(define (test n) ; (for-each ; (lambda (x) (display x) (newline )) ; (list ; (lexical-address-lookup (cons n n) new-env) ; (lexical-address-lookup (cons n 0) new-env) ; (lexical-address-lookup (cons 0 n) new-env) ; (lexical-address-lookup (cons 0 0) new-env)))) ;(define (test2 n) ; (for-each ; (lambda (x) (display x) (newline )) ; (list ; (lexical-address-set! (cons n n) new-env "new") ; (lexical-address-set! (cons n 0) new-env "new") ; (lexical-address-set! (cons 0 n) new-env "new") ; (lexical-address-set! (cons 0 0) new-env "new")))) ;(test 1) ;(test2 1) ;(test 1) ; ;(lexical-address-set! (cons 0 100) new-env "new") ;Welcome to DrRacket, version 6.8 [3m]. ;Language: SICP (PLaneT 1.18); memory limit: 128 MB. ;2 ;1 ;b ;a ;#<void> ;#<void> ;#<void> ;#<void> ;new ;new ;new ;new ;. . list-set!: displacement number overflow: 100 ;>
false
13b63eddbd1247a9241378d1d2d1796ef5f206c2
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/sitelib/srfi/%3a193/command-line.scm
7c542cb3fc260f45be959ce95953a50adeba7323
[ "BSD-3-Clause", "LicenseRef-scancode-other-permissive", "MIT", "BSD-2-Clause" ]
permissive
ktakashi/sagittarius-scheme
0a6d23a9004e8775792ebe27a395366457daba81
285e84f7c48b65d6594ff4fbbe47a1b499c9fec0
refs/heads/master
2023-09-01T23:45:52.702741
2023-08-31T10:36:08
2023-08-31T10:36:08
41,153,733
48
7
NOASSERTION
2022-07-13T18:04:42
2015-08-21T12:07:54
Scheme
UTF-8
Scheme
false
false
2,274
scm
command-line.scm
;;; -*- mode: scheme; coding: utf-8 -*- ;;; ;;; srfi/%3a193/command-line.scm - SRFI 193 Command line ;;; ;;; Copyright (c) 2021 Takashi Kato <[email protected]> ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; 1. Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; 2. Redistributions in binary form must reproduce the above copyright ;;; notice, this list of conditions and the following disclaimer in the ;;; documentation and/or other materials provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; #!nounbound (library (srfi :193 command-line) (export command-line command-name command-args script-file script-directory) (import (rnrs) (sagittarius) (util file)) (define (command-name) (let ((file (car (command-line)))) (and (not (zero? (string-length file))) (let-values (((dir base ext) (decompose-path file))) (string-append base "." ext))))) (define (command-args) (cdr (command-line))) (define (script-file) (let ((file (car (command-line)))) (and (not (zero? (string-length file))) (absolute-path file)))) (define (script-directory) (let ((path (script-file))) (and path (let-values (((dir base ext) (decompose-path path))) dir)))) )
false
79b513c5bc15557fd99e056d8635f133d7c81ab8
35f859a6933537955f878e97455cd45b312aa042
/ext/test.scm
0a9b362b7eda10aa5705c0202d5cf46674bc0730
[]
no_license
podhmo/gauche-gl-processing
ebbbe2631830cb7d0e62b5e5aa0275bb176c7084
d57b9c055d2dfe199df5652e1afb0cfd1713257f
refs/heads/master
2021-01-23T08:38:44.547876
2010-10-13T08:40:19
2010-10-13T08:40:19
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
127
scm
test.scm
(use gauche.test) (use ext.perlinnoise) (test-start "ext.perlinnoise") (test-module (find-module 'ext.perlinnoise)) (test-end)
false
9dfd832d7c20bd2b2004b9f055111e61fe54abd6
8a0660bd8d588f94aa429050bb8d32c9cd4290d5
/test/tests/rfc/cmac.scm
590e872da59223fa2aee90c0c4a329b987d1e361
[ "BSD-2-Clause" ]
permissive
david135/sagittarius-scheme
dbec76f6b227f79713169985fc16ce763c889472
2fbd9d153c82e2aa342bfddd59ed54d43c5a7506
refs/heads/master
2016-09-02T02:44:31.668025
2013-12-21T07:24:08
2013-12-21T07:24:08
32,497,456
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,917
scm
cmac.scm
(import (rnrs) (rfc cmac) (crypto) (math) (sagittarius object) (srfi :64)) ;; test vector from RFC 4493 (define K (generate-secret-key AES (integer->bytevector #x2b7e151628aed2a6abf7158809cf4f3c))) (define aes-cipher (cipher AES K)) (define aes-mac (hash-algorithm CMAC :cipher aes-cipher)) (test-begin "CMAC") (test-assert "CMAS?" (hash-algorithm? aes-mac)) ;; we can't test K1 and K2 (test-equal "AES-128(key, 0)" #x7df76b0c1ab899b33e42f047b91b546f (bytevector->integer (encrypt aes-cipher (make-bytevector 16 0)) 0 16)) (test-equal "Example 1 len = 0" (integer->bytevector #xbb1d6929e95937287fa37d129b756746) (hash aes-mac #vu8())) (test-equal "Example 2 len = 16" (integer->bytevector #x070a16b46b4d4144f79bdd9dd04a287c) (hash aes-mac (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a) (endianness big) 4))) (test-equal "Example 3 len = 40" (integer->bytevector #xdfa66747de9ae63030ca32611497c827) (hash aes-mac (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a #xae2d8a57 #x1e03ac9c #x9eb76fac #x45af8e51 #x30c81c46 #xa35ce411) (endianness big) 4))) (test-equal "Example 4 len = 64" (integer->bytevector #x51f0bebf7e3b9d92fc49741779363cfe) (hash aes-mac (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a #xae2d8a57 #x1e03ac9c #x9eb76fac #x45af8e51 #x30c81c46 #xa35ce411 #xe5fbc119 #x1a0a52ef #xf69f2445 #xdf4f9b17 #xad2b417b #xe66c3710) (endianness big) 4))) (test-equal "splited MAC" (integer->bytevector #x51f0bebf7e3b9d92fc49741779363cfe) (begin (hash-init! aes-mac) (hash-process! aes-mac (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a #xae2d8a57 #x1e03ac9c #x9eb76fac #x45af8e51) (endianness big) 4)) (hash-process! aes-mac (uint-list->bytevector '(#x30c81c46 #xa35ce411 #xe5fbc119 #x1a0a52ef #xf69f2445 #xdf4f9b17 #xad2b417b #xe66c3710) (endianness big) 4)) (let ((out (make-bytevector 16 0))) (hash-done! aes-mac out) out))) (test-equal "splited non block size" (integer->bytevector #x51f0bebf7e3b9d92fc49741779363cfe) (begin (hash-init! aes-mac) (hash-process! aes-mac (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a #xae2d8a57 #x1e03ac9c #x9eb76fac) (endianness big) 4)) (hash-process! aes-mac (uint-list->bytevector '(#x45af8e51 #x30c81c46 #xa35ce411 #xe5fbc119 #x1a0a52ef #xf69f2445 #xdf4f9b17 #xad2b417b #xe66c3710) (endianness big) 4)) (let ((out (make-bytevector 16 0))) (hash-done! aes-mac out) out))) ;; AES_CMAC_96 (define aes-mac-96 (hash-algorithm CMAC :cipher aes-cipher :size (/ 96 8))) ;; from RFC 4494 (test-equal "Test Case 1 len = 0" (integer->bytevector #xbb1d6929e95937287fa37d12) (hash aes-mac-96 #vu8())) (test-equal "Test Case 2 len = 16" (integer->bytevector #x070a16b46b4d4144f79bdd9d) (hash aes-mac-96 (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a) (endianness big) 4))) (test-equal "Test Case 3 len = 40" (integer->bytevector #xdfa66747de9ae63030ca3261) (hash aes-mac-96 (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a #xae2d8a57 #x1e03ac9c #x9eb76fac #x45af8e51 #x30c81c46 #xa35ce411) (endianness big) 4))) (test-equal "Test Case 4 len = 64" (integer->bytevector #x51f0bebf7e3b9d92fc497417) (hash aes-mac-96 (uint-list->bytevector '(#x6bc1bee2 #x2e409f96 #xe93d7e11 #x7393172a #xae2d8a57 #x1e03ac9c #x9eb76fac #x45af8e51 #x30c81c46 #xa35ce411 #xe5fbc119 #x1a0a52ef #xf69f2445 #xdf4f9b17 #xad2b417b #xe66c3710) (endianness big) 4))) (test-end)
false
6629c21a90fe06f60b7d6afdda9b07651201a628
d9cb7af1bdc28925fd749260d5d643925185b084
/2e/1.39.scm
bb17a90dee77e81aa0bab6a933ad78402fbe03a0
[]
no_license
akerber47/sicp
19e0629df360e40fd2ea9ba34bf7bd92be562c3e
9e3d72b3923777e2a66091d4d3f3bfa96f1536e0
refs/heads/master
2021-07-16T19:36:31.635537
2020-07-19T21:10:54
2020-07-19T21:10:54
14,405,303
0
0
null
null
null
null
UTF-8
Scheme
false
false
399
scm
1.39.scm
(define (cont-frac n d k) (define (cont-frac-starting-at i n d k) (if (> i k) 0 (/ (n i) (+ (d i) (cont-frac-starting-at (+ i 1) n d k))))) (cont-frac-starting-at 1 n d k)) (define (tan-cf (x k)) (cont-frac (lambda (i) (if (= i 1) x (- (* x x)))) (lambda (i) (- (* 2 i) 1)) k))
false
38f432ee02d6de1b9e46d76aef3d37229706a51f
5add38e6841ff4ec253b32140178c425b319ef09
/%3a0/cond-expand.guile.sls
4c5ce6f19416d244d24551116dace42c033d2802
[ "X11-distribute-modifications-variant" ]
permissive
arcfide/chez-srfi
8ca82bfed96ee1b7f102a4dcac96719de56ff53b
e056421dcf75d30e8638c8ce9bc6b23a54679a93
refs/heads/master
2023-03-09T00:46:09.220953
2023-02-22T06:18:26
2023-02-22T06:18:26
3,235,886
106
42
NOASSERTION
2023-02-22T06:18:27
2012-01-21T20:21:20
Scheme
UTF-8
Scheme
false
false
85
sls
cond-expand.guile.sls
(library (srfi srfi-0) (export cond-expand) (import (only (guile) cond-expand)))
false
b30585575cde6a4329ae263773f3d39a6c433d62
961ccc58c2ed4ed1d84a78614bedf0d57a2f2174
/scheme/mandelbrot.scm
76b7dca16f1b0e373a4b0dab76f98851bfe3dff4
[]
no_license
huangjs/mostly-lisp-code
96483b566b8fa72ab0b73bf0e21f48cdb80dab0d
9fe862dbb64f2a28be62bb1bd996238de018f549
refs/heads/master
2021-01-10T10:11:50.121705
2015-11-01T08:53:22
2015-11-01T08:53:22
45,328,850
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,937
scm
mandelbrot.scm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Use the Bigloo Mandelbrot benchmark as follows: ;; ;; bigloo -Obench mandelbrot.scm ;; time ./a.out 400 ;; ;; Important note: the code only works in -Obench mode. ;; Do not be worried: it is legal Scheme/Bigloo code. ;; However, the 'multiple-value-bind' construct won't work ;; in ordinary mode, e.g: 'bigloo mandelbrot'. The latter ;; will raise a runtime error. Although the developers of ;, Bigloo told me they will change that in one of the next ;; Bigloo releases so as to have 'multiple-value-bind' ;; constructs also in debugging mode. ;; ;; Second note: At least on my Mac OSX Macintosh ibook ;; my Bigloo version is within 2 times the C code ;; (for C codes consult language shootout-pages): ;; ;; C code: real: 0m0.8s, user: 0m0.12s, sys: 0m0.05s ;; ;; Bigloo code: real: 0m0.9s, user: 0m0.24s, sys: 0m0.05s ;; ;; ;; Third note: Bigloo has some basic methods for handling ;; bit operations, e.g: (bit-or (bit-lsh byte-acc 1) 0) ;; ;; Fourth note: the code utilizes Bigloo its wonderful ;; built in support of operators meant for dealing with ;; numbers, e.g. (+fl x y) will typically boost things ;; a little bit because the compiler knows in advance ;; with which types he will have to cope with. ;; ;; Fifth note: As a Scheme programmer not used to Bigloo ;; don't become distracted by my type information in my code. ;; A proper syntax highlightning (e.g. in Bee) will ;; reveal the genuine Scheme code. ;; ;; Suggestions and complaints are welcome. Do not hesitate. ;; ;; (C) 2005 here is my name, <and here my email-adress@edu.>, ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (module mandelbrot (main main)) (define *cflags* "-Wall -O3 -fomit-frame-pointer -mfpmath=sse -mtune=core2 -lm") (define (main argv) (mandelbrot (string->number (car (cdr argv))))) (define (mandelbrot::bool w::int) (let* ((iter::int 50) (limit::double 2.0) (h::int w)) (print "P4 ") (print w " " h) (let >loop-y< ((y::int 0) (bit-num::ubyte 0) (byte-acc::ubyte 0)) (cond ((>=fx y h) #t) (else (let >loop-x< ((x::int 0) (bit-num::ubyte bit-num) (byte-acc::ubyte byte-acc)) (cond ((>=fx x w) (>loop-y< (+fx y 1) bit-num byte-acc)) (else (let* ((cr::double (-fl (*fl 2.0 (/fl (fixnum->flonum x) (fixnum->flonum w))) 1.5)) (ci::double (-fl (*fl 2.0 (/fl (fixnum->flonum y) (fixnum->flonum h))) 1.0))) (let >loop-i< ((i::int 0) (zr::double 0.0) (zi::double 0.0)) (cond ((or (>=fx i iter) (>fl (+fl (*fl zr zr) (*fl zi zi)) (*fl limit limit))) (multiple-value-bind (bit-num-new byte-acc-new) (putc zr zi limit bit-num byte-acc w x) (>loop-x< (+fx x 1) bit-num-new byte-acc-new))) (else (let* ((tr::double (+fl (-fl (*fl zr zr) (*fl zi zi)) cr)) (ti::double (+fl (*fl 2.0 (*fl zr zi)) ci))) (>loop-i< (+fx i 1) tr ti)))))))))))))) (define (putc::obj zr::double zi::double limit::double bit-num::int byte-acc::int w::int x::int) (let* ((byte-acc-new::int (if (>fl (+fl (*fl zr zr) (*fl zi zi)) (*fl limit limit)) (bit-or (bit-lsh byte-acc 1) 0) (bit-or (bit-lsh byte-acc 1) 1))) (bit-num-new::int (+fx bit-num 1))) (if (=fx bit-num-new 8) (begin (display (integer->char byte-acc-new)) (values 0 0)) (begin (if (=fx x (-fx w 1)) (begin (display (integer->char (bit-lsh byte-acc-new (-fx (modulo w 8) 8)))) (values 0 0)) (begin (values bit-num-new byte-acc-new)))))))
false
748656078ccc7b9fa30db7ad5ff5994fd8d8019b
710e486f87b70e57cc3c2a411d12c30644544b75
/show/terminal-width.sld
05f87d16411b3fa3ea912dc3b323dfe8dbc08120
[ "BSD-3-Clause", "MIT", "LicenseRef-scancode-unknown-license-reference", "BlueOak-1.0.0" ]
permissive
ar-nelson/schemepunk
6236a3200343257a9ce15a6e3f4bda1dd450c729
249bf057b256bbb9212f60345a84d84615c61893
refs/heads/master
2021-05-18T07:47:36.721609
2021-04-24T17:05:48
2021-04-24T17:05:48
251,185,680
92
7
NOASSERTION
2021-05-12T14:07:38
2020-03-30T02:53:33
Scheme
UTF-8
Scheme
false
false
1,233
sld
terminal-width.sld
(define-library (schemepunk show terminal-width) (export get-terminal-width) (import (scheme base)) (cond-expand ((and chicken unix) (import (ioctl)) (begin (define (get-terminal-width) (guard (e (#t 80)) (cadr (ioctl-winsize)))))) (gauche (import (only (text console) call-with-console make-default-console query-screen-size)) (begin (define (get-terminal-width) (guard (e (#t 80)) (let-values (((_ w) (call-with-console (make-default-console) query-screen-size))) w))))) (chibi (import (rename (chibi stty) (get-terminal-width %get-terminal-width))) (begin (define (get-terminal-width) (%get-terminal-width (current-output-port))))) (gerbil (import (std misc process) (scheme read)) (begin (define (get-terminal-width) (or (guard (e (#t #f)) (read (open-input-string (run-process (list "tput" "cols"))))) 80)))) (else (begin (define (get-terminal-width) 80)))))
false
5e3ef20896432f0d30913512ff6a416f9c16b9eb
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/test/tests/binary/pack.scm
17fe58531f01409b92a116e0970dcf292ea8199b
[ "BSD-3-Clause", "LicenseRef-scancode-other-permissive", "MIT", "BSD-2-Clause" ]
permissive
ktakashi/sagittarius-scheme
0a6d23a9004e8775792ebe27a395366457daba81
285e84f7c48b65d6594ff4fbbe47a1b499c9fec0
refs/heads/master
2023-09-01T23:45:52.702741
2023-08-31T10:36:08
2023-08-31T10:36:08
41,153,733
48
7
NOASSERTION
2022-07-13T18:04:42
2015-08-21T12:07:54
Scheme
UTF-8
Scheme
false
false
3,677
scm
pack.scm
(import (rnrs) (rnrs eval) (srfi :64) (binary pack)) (test-begin "Binary pack tests") (define-syntax check (syntax-rules (=>) ((_ expr => expect) (test-equal (format "~s" 'expr) expect expr)))) (define (check-pack expect fmt . values) (let () (check (apply pack fmt values) => expect) (check (eval `(pack ,fmt ,@values) (environment '(rnrs) '(binary pack))) => expect) (check (call-with-values (lambda () (unpack fmt expect)) list) => values) (check (eval `(call-with-values (lambda () (unpack ,fmt ',expect)) list) (environment '(rnrs) '(binary pack))) => values) #f)) ;; unpack tests from industria (check (unpack "!C" '#vu8(1 2 3 4 6 0) 5) => 0) (check (unpack "!S" '#vu8(1 2 3 4 0 0) 4) => 0) (check (let ((bv (make-bytevector 4 0))) (pack! "!S" bv 2 #xffee) bv) => '#vu8(0 0 #xff #xee)) (check (let-values ((x (get-unpack (open-bytevector-input-port #vu8(4 3 2 1 2 1 1 #xff #xff)) "<LSC"))) x) => '(#x01020304 #x0102 #x01)) (check (apply get-unpack (open-bytevector-input-port #vu8(#xff)) "c" '()) => -1) (check (unpack "C" #vu8(0 1) 1) => 1) (check (let ((offset 1)) (unpack "C" #vu8(0 1) offset)) => 1) (check (let ((offset 1)) (unpack "!uxxS" #vu8(5 5 5 0 1) offset)) => 1) (check (let-values ((x (unpack "4C" #vu8(1 2 3 4)))) x) => '(1 2 3 4)) (check (let-values ((x (unpack (car '("4C")) #vu8(1 2 3 4)))) x) => '(1 2 3 4)) ;; pack tests from industria (check (pack "!SS" 1 2) => #vu8(0 1 0 2)) (check (let ((bv (make-bytevector 6 #xff)) (offset 1)) (pack! "!SS" bv offset 1 2)) => #vu8(#xff 0 0 1 0 2)) (check (let ((bv (make-bytevector 9 #xff))) (pack! "<ucQ" bv (+ 0) 1 2)) => #vu8(1 2 0 0 0 0 0 0 0)) (check (map pack '("C" "!S" "!xxC") '(1 1 1)) => '(#vu8(1) #vu8(0 1) #vu8(0 0 1))) (check (pack "4C" 1 2 3 4) => (pack "CCCC" 1 2 3 4)) (check (pack (car '("4C")) 1 2 3 4) => #vu8(1 2 3 4)) ;; explicitly native endianness (check (pack (car '("=l")) 1) => (if (eq? (endianness little) (native-endianness)) #vu8(1 0 0 0) #vu8(0 0 0 1))) (check (let ((zero 0) (bv (make-bytevector 8 1))) (pack! "!L" bv (+ zero 2) #xFFFFFFFF)) => #vu8(1 1 0 0 255 255 255 255)) ;; some indefinite length test (check (let-values ((r (unpack "*C" #vu8(1 2 3 4)))) r) => '(1 2 3 4)) (check (pack "*C" 1 2 3 4) => (pack "CCCC" 1 2 3 4)) (check (pack (car '("*C")) 1 2 3 4) => #vu8(1 2 3 4)) (check (pack "!2s!*l" 1 2 3 4) => #vu8(0 1 0 2 0 0 0 3 0 0 0 4)) (check (pack "2s!*l" 1 2 3 4) => (cond-expand (little-endian #vu8(1 0 2 0 0 0 0 3 0 0 0 4)) (big-endian #vu8(0 1 0 2 0 0 0 3 0 0 0 4)))) (check-pack '#vu8() "") (check-pack '#vu8(0) "x") (check-pack '#vu8(0 0 0) "3x") (check-pack '#vu8() "0x") (check-pack '#vu8() "!0x") (check-pack '#vu8(#xff) "c" -1) (check-pack '#vu8(0 #xff) "xC" 255) (check-pack '#vu8(0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 3) "!SLQ" 1 2 3) (check-pack '#vu8(0 0 0 0 0 0 0 1 0 0 0 2 0 3) "!QLS" 1 2 3) (check-pack '#vu8(0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 3) "!SQL" 1 2 3) (check-pack '#vu8(0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 3) ">SQL" 1 2 3) (check-pack '#vu8(1 0 0 0 0 0 0 0 2 0 0 0 3 0) "<QLS" 1 2 3) (check-pack '#vu8(4 1 0) "u!C S" 4 #x100) (check-pack '#vu8(4 0 1 0) "u!CaS" 4 #x100) (check-pack '#vu8(4 0 0 1 0) "u!C L" 4 #x100) (check-pack '#vu8(4 0 0 0 0 0 0 1 0) "u!C Q" 4 #x100) (test-end)
true
6069b8961a1f7b67ced756dd76ea12d156317f46
354ae3428451a81e5a6e07d282edb9bd79ff0e3f
/tests/examples/long.ss
4934818dce0536315fbf7bbd1eb1785ded9ba7b3
[]
no_license
jeapostrophe/datalog
385a478dc18a904a35cbe36ebc7b1a7ec0a26478
a5d59e455b49d091f3c5348e4c1f0071a1bc0134
refs/heads/master
2021-01-18T13:42:51.827415
2013-10-31T01:32:07
2013-10-31T01:32:07
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
377
ss
long.ss
#lang planet jaymccarthy/datalog abcdefghi(z123456789, z1234567890123456789, z123456789012345678901234567890123456789, z1234567890123456789012345678901234567890123456789012345678901234567890123456789). this_is_a_long_identifier_and_tests_the_scanners_concat_when_read_with_a_small_buffer. this_is_a_long_identifier_and_tests_the_scanners_concat_when_read_with_a_small_buffer?
false
1cbd13281be43985cb4ac41a3ebbf4d67c2b89ec
a0c856484b0cafd1d7c428fb271a820dd19be577
/lab10/tree.ss
c372ea3f9fa3e5a348df6e9188d342ac9481dcbc
[]
no_license
ctreatma/scheme_exercises
b13ba7743dfd28af894eb54429297bad67c14ffa
94b4e8886b2500a7b645e6dc795c0d239bf2a3bb
refs/heads/master
2020-05-19T07:30:58.538798
2012-12-03T23:12:22
2012-12-03T23:12:22
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
759
ss
tree.ss
; tree.ss ;; define tree datatype using define-struct ;; this is an n-ary tree in which only leaves have numerical ;; it is isomorphic to a list of numbers (module tree mzscheme (define-struct tree ()) ; parent type (never instantiated) (define-struct (interior-node tree) (children)) ; children is a list of trees (define-struct (leaf-node tree) (value)) ; value is a number ; build-tree converts a list of numbers into a tree (define build-tree (lambda (l) (if (number? l) (make-leaf-node l) (make-interior-node (map build-tree l))))) ; sample tree (define tree1 (build-tree '((1 (2 (3 4)) 5) 6 (7 (8 9))))) (provide (all-defined)) )
false
f86d0975a6bf4316532cf3b5c31dfacc8edac41d
e75694971a8d65a860e49d099aba868e1b7ec664
/b2.scm
cbe6faee17e81fb776de4dc2295e723398db7aec
[]
no_license
telnet23/sicp
d29088e1bdef7ede3cf5805559e0edb3b0ef54fe
a85fa7f17c7485163c9484ed5709d6ec64e87aaa
refs/heads/master
2023-02-20T09:20:38.216645
2019-04-30T20:15:12
2019-04-30T20:15:12
331,790,140
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,023
scm
b2.scm
"problem 1." (define (piecewise x) (if (and (>= x -2) (<= x 2)) (- 4 (* x x)) (- (* x x) 4))) "problem 2. (a)" (define (odd-sum n) (if (= n 0) 0 (+ (- (* 2 n) 1) (odd-sum (- n 1))))) "problem 2. (b)" (odd-sum 1) (odd-sum 2) (odd-sum 3) (odd-sum 4) (odd-sum 5) (odd-sum 6) (odd-sum 7) "problem 2. (c)" (define (sum-from-to a b) (if (= a b) a (+ b (sum-from-to a (- b 1))))) "problem 3." (define (apery k) (if (= k 0) 0 (+ (expt k -3) (apery (- k 1))))) "problem 4." (define (k-product k) (if (= k 1) 1 (* (k-product (- k 1)) (- 1 (expt k -2))))) "problem 5. (a)" (define (babylonian x k) (if (= k 0) (/ x 2) (/ (+ (babylonian x (- k 1)) (/ x (babylonian x (- k 1)))) 2))) "problem 5. (b)" (define (first-value-k-or-higher x tol k) (if (<= (abs (- (expt (babylonian x k) 2) x)) tol) k (first-value-k-or-higher x tol (+ k 1)))) (define (terms-needed x tol) (first-value-k-or-higher x tol 1)) "problem 5. (c)" (define (x S n) (if (= n 0) (/ S 2) (- (+ (x S (- n 1)) (/ (- S (expt (x S (- n 1)) 2)) (* 2 (x S (- n 1))))) (/ (expt (/ (- S (expt (x S (- n 1)) 2)) (* 2 (x S (- n 1)))) 2) (* 2 (+ (x S (- n 1)) (/ (- S (expt (x S (- n 1)) 2)) (* 2 (x S (- n 1)))))))))) (define (bakhshali S k) (x S k)) "problem 5. (d)" (define (first-value-k-or-higher-b x tol k) (if (<= (abs (- (expt (bakhshali x k) 2) x)) tol) k (first-value-k-or-higher-b x tol (+ k 1)))) (define (terms-needed-b x tol) (first-value-k-or-higher-b x tol 1)) "problem 6." (define (factorial n) (if (= n 0) 1 (* n (factorial (- n 1))))) (define (new-sin-term x k) (* (expt -1 k) (/ (expt x (+ (* 2 k) 1)) (factorial (+ (* 2 k) 1))))) (define (new-sin x n) (if (= n 0) (new-sin-term x n) (+ (new-sin-term x n) (new-sin x (- n 1)))))
false
c7b5fb81611fb262d0830a7c6cda3b4535287196
8ad2bcf76a6bda64f509da5f0844e0285f19d385
/dnd/src/attribute.ss
4be8d26f8819bbd5496ebcfe17fb644d69c79ca6
[]
no_license
jeapostrophe/exp
c5efae0ea7068bb5c8f225df6de45e6c4fa566bd
764265be4bcd98686c46ca173d45ee58dcca7f48
refs/heads/master
2021-11-19T00:23:11.973881
2021-08-29T12:56:11
2021-08-29T12:56:11
618,042
39
5
null
null
null
null
UTF-8
Scheme
false
false
1,162
ss
attribute.ss
#lang scheme (define (attribute-modifier val) (floor (/ (- val 10) 2))) (define attribute-set<%> (interface ())) (define attribute-set/c (object-contract (field str exact-nonnegative-integer?) (field con exact-nonnegative-integer?) (field dex exact-nonnegative-integer?) (field int exact-nonnegative-integer?) (field wis exact-nonnegative-integer?) (field cha exact-nonnegative-integer?))) (define attribute-set% (class* object% (attribute-set<%>) (init-field str con dex int wis cha) (super-new))) (define-syntax default-as (syntax-rules () [(_ min a2 a3 a4 a5 a6) (new attribute-set% [min 8] [a2 10] [a3 10] [a4 10] [a5 10] [a6 10])])) (define default-attribute-set/str (default-as str con dex int wis cha)) (define default-attribute-set/con (default-as con str dex int wis cha)) (define default-attribute-set/dex (default-as dex str con int wis cha)) (define default-attribute-set/int (default-as int str con dex wis cha)) (define default-attribute-set/wis (default-as wis str con dex int cha)) (define default-attribute-set/cha (default-as cha str con dex int wis))
true
69ee39c3774003bf0fc0d54d9119c98a4e33c80a
09e309c8c7dd86d201f965a12f4f174fd2bf8cf5
/scheme/coroutine.scm
d16a4cc820d201b18e47f70f537684a7ce7df741
[]
no_license
googol-lab/lang
f21076846b2364ee08875530ab7a6680de61f55c
38cae455f85464a7f918d1a5a481a577ed5549fe
refs/heads/master
2020-03-29T13:32:29.159544
2010-05-24T03:09:54
2010-05-24T03:09:54
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
875
scm
coroutine.scm
(use util.queue) (define *tasks* (make-queue)) (define-syntax define-coroutine (syntax-rules () [(_ (routine yield) body ...) (define (routine) (call/cc (lambda (return) (define (yield) (call/cc (lambda (cont) (enqueue! *tasks* cont) (return)))) body ...)) ((dequeue! *tasks*)))])) (define (coroutine-init! . rs) (set! *tasks* (make-queue)) (for-each (lambda (r) (enqueue! *tasks* r)) rs)) (define-coroutine (three yield) (let lp () (print 'one) (yield) (print 'two) (yield) (print 'three) (yield) (lp))) (define-coroutine (五 つぎ) (let ループ () (print 'いち) (つぎ) (print 'に) (つぎ) (print 'さん) (つぎ) (print 'よん) (つぎ) (print 'ご) (つぎ) (ループ)))
true
8f3640ddc429d40098739f545c22de02f5c3100c
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/io/kevent-file-data.sls
c1e927841a83be19f19fd4654e35011c201711e7
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,118
sls
kevent-file-data.sls
(library (system io kevent-file-data) (export new is? kevent-file-data? fsi-get fsi-set! fsi-update! last-access-time-get last-access-time-set! last-access-time-update! last-write-time-get last-write-time-set! last-write-time-update!) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.IO.KeventFileData a ...))))) (define (is? a) (clr-is System.IO.KeventFileData a)) (define (kevent-file-data? a) (clr-is System.IO.KeventFileData a)) (define-field-port fsi-get fsi-set! fsi-update! () System.IO.KeventFileData fsi System.IO.FileSystemInfo) (define-field-port last-access-time-get last-access-time-set! last-access-time-update! () System.IO.KeventFileData LastAccessTime System.DateTime) (define-field-port last-write-time-get last-write-time-set! last-write-time-update! () System.IO.KeventFileData LastWriteTime System.DateTime))
true
93b681c1e43c1d921e6298e0c21042f3fe428783
961ccc58c2ed4ed1d84a78614bedf0d57a2f2174
/scheme/examples/eval.scm
03dc935c8bba8e092e24bdc492770bffbbc85b25
[]
no_license
huangjs/mostly-lisp-code
96483b566b8fa72ab0b73bf0e21f48cdb80dab0d
9fe862dbb64f2a28be62bb1bd996238de018f549
refs/heads/master
2021-01-10T10:11:50.121705
2015-11-01T08:53:22
2015-11-01T08:53:22
45,328,850
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,503
scm
eval.scm
;:*======================= ;:* car and cdr should be named. ;:* this is just an demonstration ;;; NOTE: the style is UGLY. (define eval (lambda (exp env) (cond ;;; special form ((number? exp) exp) ;;; 3 -> 3 ((symbol? exp) (lookup exp env)) ;;; x -> 3 ((eq? (car exp) 'quote) (cadr exp)) ;;; 'foo => (quote foo) -> foo ((eq? (car exp) 'lambda) (list 'closure (cdr exp) env)) ;;; lambda (x) (body) => (closure ((x) (body)) env) ((eq? (car exp) 'cond) (evalcond (cdr exp) env)) ;;; (cond ((p1 e1)) ((p2 e2))) ;;; end of special form (else (apply (eval (car exp) env) (evallist (cdr exp) env)))))) (define apply (lambda (proc args) (cond ((primitive? proc) (apply-primop proc args)) ((eq? (car proc) 'closure) (eval (cadadr proc) (bind (caadr proc) args (caddr proc)))) (else (error "some sort of error."))))) (define evallist (lambda (l env) (cond ((eq? l nil) nil) (else (cons (eval (car l) env) (evallist (cdr l) env)))))) (define evalcond (lambda (clauses env) (cond ((eq? clauses nil) nil) ((eq? (caar clauses) 'else) (eval (cadar clauses) env)) ((false? (eval (caar clauses) env)) (evalcond (cdr clauses) env)) (else ;;; when hit true clause (eval (cadar clauses) env))))) (define bind (lambda (vars vals env) (cond ((pair-up vars vals) env)))) (define pair-up (lambda (vars vals) (cond ((eq? vars nil) (cond ((eq? vals nil) nil) (else (error "Too many arguments.")))) ((eq? vals '()) (error "Too few arguments.")) (else (cons (cons (car vars) (car vals)) (pair-up (cdr vars) (cdr vals))))))) (define lookup (lambda (sym env) (cond ((eq? env nil) (error "Unbounded variable.")) (else ((lambda (vcell) (cond ((eq? vcell nil) (lookup sym (cdr env))) (else cdr vcell))) (assq sym (car env))))))) (define assq (lambda (sym alist) (cond ((eq? alist nil) nil) ((eq? sym (caar alist)) (car alist)) (else (assq sym (cdr alist))))))
false
a4898b373ab26fb30ca06cbb917a9469481bf911
c706efb647b6a679174ff3757cf25da2f9762eb9
/srfi/43/test.scm
7ad97680d131f4ae0927ce8893bc8898165aebde
[]
no_license
antoine-doucet/libs
0cd502ad5e8c48755692e972a14575ac66db1115
2c7e944bb7bdbbea30b409210fcda6b5aa66bf01
refs/heads/master
2020-12-03T17:34:48.034350
2020-01-10T23:23:29
2020-01-10T23:23:29
231,410,718
0
0
null
2020-01-02T15:40:56
2020-01-02T15:40:55
null
UTF-8
Scheme
false
false
21,709
scm
test.scm
;;; File: "test.scm" ;;; Copyright (c) 2018-2020 by Antoine Doucet, All Rights Reserved. ;;; Copyright (c) 2018-2020 by Marc Feeley, All Rights Reserved. ;;;============================================================================ ;;; SRFI 43, Vector library. (import (srfi 43)) (import (_test)) ;;;============================================================================ ;;; Constructors ;;;============================================================================ ;;; ;;;---------------------------------------------------------------------------- ;;; make-vector ;;; primitive R5Rs ##make-vector (check-equal? (make-vector 4) #(0 0 0 0)) (check-equal? (make-vector 4 1) #(1 1 1 1)) ;;;---------------------------------------------------------------------------- ;;; vector ;;; primitive R5Rs ##vector (check-equal? (vector 0) #(0)) (check-equal? (vector 0 1 2 3) #(0 1 2 3)) ;;;---------------------------------------------------------------------------- ;;; vector-unfold (check-equal? (vector-unfold (lambda (i x) (values x (+ x 1))) 5 0) #(0 1 2 3 4)) (let ((vec (vector 0 1 2 3 4))) (check-equal? (vector-unfold (lambda (i) (vector-ref vec i)) (vector-length vec)) vec)) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold (lambda () '()) 1))) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold (lambda (x1) '()) 1 2))) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold (lambda (x1) '())))) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold (lambda (x1 x2 x3) (values 1 2 3)) 1 2 ))) (check-tail-exn type-exception? (lambda () (vector-unfold 0 1 2))) ;;;---------------------------------------------------------------------------- ;;; vector-unfold-right (check-equal? (vector-unfold-right (lambda (i x) (values x (+ x 1))) 5 0) #(4 3 2 1 0)) (let ((vec #(1 2 3 4 5))) (check-equal? (vector-unfold-right (lambda (i x) (values (vector-ref vec x) (+ x 1))) (vector-length vec) 0) #(5 4 3 2 1))) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold-right (lambda () '()) 1))) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold-right (lambda (x1) '()) 1 2))) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold-right (lambda (x1) '())))) (check-exn wrong-number-of-arguments-exception? (lambda () (vector-unfold-right (lambda (x1 x2 x3) (values 1 2 3)) 1 2 ))) (check-tail-exn type-exception? (lambda () (vector-unfold 0 1 2))) ;;;---------------------------------------------------------------------------- ;;; vector-copy (let ((vec #(0 1 2 3 4))) (check-equal? (vector-copy vec) vec) (check-equal? vec #(0 1 2 3 4))) (let ((vec #(0 1 2 3 4 5))) (check-equal? (vector-copy vec 3) #(3 4 5)) (check-equal? vec #(0 1 2 3 4 5))) (let ((vec #(0 1 2 3 4 5))) (check-equal? (vector-copy vec 3 10 6) #(3 4 5 6 6 6 6))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-copy))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-copy 0 1 2 3 4))) (check-tail-exn type-exception? (lambda () (vector-copy 0))) ;;;---------------------------------------------------------------------------- ;;; vector-reverse-copy (let ((vec #(5 4 3 2 1))) (check-equal? (vector-reverse-copy vec 2 5) #(1 2 3)) (check-equal? vec #(5 4 3 2 1))) (let ((vec #(3 2 1))) (check-equal? (vector-reverse-copy vec ) #(1 2 3))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-reverse-copy))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-reverse-copy 0 1 2 3))) (check-tail-exn type-exception? (lambda () (vector-reverse-copy 0))) ;;;---------------------------------------------------------------------------- ;;; vector-append ;;; primitive R5Rs ##vector-append ;;;---------------------------------------------------------------------------- ;;; vector-concatenate ;;; primitive ##append-vectors ;;;============================================================================ ;;; Predicates ;;;============================================================================ ;;; ;;;---------------------------------------------------------------------------- ;;; vector? ;;; primitive R5Rs ##vector? ;;;---------------------------------------------------------------------------- ;;; vector-empty? (check-true (vector-empty? #())) (check-false (vector-empty? #(0))) (check-false (vector-empty? #(#()))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-empty?))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-empty? 0 1))) (check-tail-exn type-exception? (lambda () (vector-empty? 0))) ;;;---------------------------------------------------------------------------- ;;; vector= (check-true (vector= equal? #() #())) (let ((vec #())) (check-true (vector= eq? vec vec))) (check-true (vector= (lambda (a b) #t) #(1 2 3) #(4 5 6))) (check-false (vector= eq? #(0 1 2 3) #())) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector= 0 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector= 0 1 2 3))) (check-tail-exn type-exception? (lambda () (vector= 0 #() #()))) (check-tail-exn type-exception? (lambda () (vector= eq? 0 #()))) (check-tail-exn type-exception? (lambda () (vector= eq? #() 0))) ;;;============================================================================ ;;; Selectors ;;;============================================================================ ;;; ;;;---------------------------------------------------------------------------- ;;; vector-ref ;;; primitive R5Rs ##vector-ref ;;;---------------------------------------------------------------------------- ;;; vector-length ;;; primitive R5Rs ##vector-length ;;;============================================================================ ;;; Iteration ;;;============================================================================ ;;; ;;;---------------------------------------------------------------------------- ;;; vector-fold (let ((vec #(0 1 2 3))) (check-equal? (vector-fold (lambda (index tail elt) (cons elt tail)) '() vec) '(3 2 1 0)) (check-equal? vec #(0 1 2 3))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-fold 0))) (check-tail-exn type-exception? (lambda () (vector-fold 0 1 #() #()))) (check-tail-exn type-exception? (lambda () (vector-fold (lambda (x1 x2) '()) 1 0 #()))) (check-exn type-exception? (lambda () (vector-fold (lambda (x1 x2) '()) 1 #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-fold-right (check-equal? (vector-fold-right (lambda (index tail elt) (cons elt tail)) '() #(0 1 2 3)) '(0 1 2 3)) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-fold-right 0))) (check-tail-exn type-exception? (lambda () (vector-fold-right 0 1 #() #()))) (check-tail-exn type-exception? (lambda () (vector-fold-right (lambda (x1 x2) '()) 1 0 #()))) (check-exn type-exception? (lambda () (vector-fold-right (lambda (x1 x2) '()) 1 #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-map (let ((vec #(0 1 2 3 4))) (check-equal? (vector-map (lambda (i x) (* x x)) vec) #(0 1 4 9 16)) (check-equal? vec #(0 1 2 3 4))) (let ((vec #(1 2 3 4 5))) (check-equal? (vector-map (lambda (i x) (- x i)) vec ) #(1 1 1 1 1)) (check-equal? vec #(1 2 3 4 5))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-map 0))) (check-tail-exn type-exception? (lambda () (vector-map 0 #()))) (check-tail-exn type-exception? (lambda () (vector-map (lambda (x1 x2) '()) 0))) (check-exn type-exception? (lambda () (vector-map (lambda (x1 x2) '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-map! (check-equal? (vector-map (lambda (i x) (* x x)) #(0 1 2 3 4)) #(0 1 4 9 16)) (check-equal? (vector-map (lambda (i x) (- x i)) #(1 2 3 4 5) ) #(1 1 1 1 1)) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-map 0))) (check-tail-exn type-exception? (lambda () (vector-map 0 #()))) (check-tail-exn type-exception? (lambda () (vector-map (lambda (i x) '()) 0))) (check-exn type-exception? (lambda () (vector-map (lambda (i x) '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-for-each (let ((vec #(0 1 2 3))) (vector-for-each (lambda (i x) (vector-set! vec i (* x x))) vec) (check-equal? vec #(0 1 4 9))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-for-each 0))) (check-tail-exn type-exception? (lambda () (vector-for-each 0 #()))) (check-tail-exn type-exception? (lambda () (vector-for-each (lambda () '()) 0))) (check-exn type-exception? (lambda () (vector-for-each (lambda () '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-count (check-equal? (vector-count (lambda (i elt) (even? elt)) #(1 2 3 4)) 2) (check-equal? (vector-count (lambda (i x y) (< x y)) '#(0 1 2 3 4) '#(1 2 3 4 4 4)) 4) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-count 0))) (check-tail-exn type-exception? (lambda () (vector-count 0 #()))) (check-tail-exn type-exception? (lambda () (vector-count (lambda () '()) 0))) (check-exn type-exception? (lambda () (vector-count (lambda () '()) #() 0))) ;;;============================================================================ ;;; Searching ;;;============================================================================ ;;; ;;;---------------------------------------------------------------------------- ;;; vector-index (check-equal? (vector-index even? #(1 2 3 4)) 1) (check-equal? (vector-index < #(1 2 3 4) #(2 2 2 2)) 0) (check-false (vector-index = #(1 1 1) #(2 2 2 2 2))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-index 0))) (check-tail-exn type-exception? (lambda () (vector-index 0 #()))) (check-tail-exn type-exception? (lambda () (vector-index (lambda () '()) 0))) (check-exn type-exception? (lambda () (vector-index (lambda () '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-index-right (check-equal? (vector-index-right even? #(1 2 3 4)) 3) (check-equal? (vector-index-right <= #(1 2 3 4) #(2 2 2 2)) 1) (check-false (vector-index-right = #(1 1 1) #(2 2 2 2 2))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-index-right 0))) (check-tail-exn type-exception? (lambda () (vector-index-right 0 #()))) (check-tail-exn type-exception? (lambda () (vector-index-right (lambda () '()) 0))) (check-exn type-exception? (lambda () (vector-index-right (lambda () '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-skip (check-equal? (vector-skip number? #(0 1 2 a b 1 2 3)) 3) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-skip 0))) (check-tail-exn type-exception? (lambda () (vector-skip 0 #()))) (check-tail-exn type-exception? (lambda () (vector-skip (lambda () '()) 0))) (check-exn type-exception? (lambda () (vector-skip (lambda () '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-skip-right (check-equal? (vector-skip-right number? #(0 1 2 a b 0 1 2)) 4) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-skip-right 0))) (check-tail-exn type-exception? (lambda () (vector-skip-right 0 #()))) (check-tail-exn type-exception? (lambda () (vector-skip-right (lambda () '()) 0))) (check-exn type-exception? (lambda () (vector-skip-right (lambda () '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-binary-search (let ((comp? (lambda (x1 x2) (cond ((< x1 x2) -1) ((= x1 x2) 0) (else 1))))) (check-equal? (vector-binary-search #(1 2 3 4) 2 comp?) 1)) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-binary-search 0 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-binary-search 0 1 2 3 4 5))) (check-tail-exn type-exception? (lambda () (vector-binary-search 0 0 (lambda () '())))) (check-tail-exn type-exception? (lambda () (vector-binary-search #() 0 0))) ;;;---------------------------------------------------------------------------- ;;; vector-any (check-true (vector-any = #(0 0 0 0) #(1 0 1) #(2 0 2 0))) (check-false (vector-any = #(0 0 0) #(1 1 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-any 0))) (check-tail-exn type-exception? (lambda () (vector-any 0 #() #()))) (check-tail-exn type-exception? (lambda () (vector-any (lambda () '()) 0 #()))) (check-exn type-exception? (lambda () (vector-any (lambda () '()) #() 0))) ;;;---------------------------------------------------------------------------- ;;; vector-every (check-false (vector-every = #(0 0 0 0) #(1 0 1) #(2 0 2 0))) (check-true (vector-every = #(1 1 1) #(1 1 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-every 0))) (check-tail-exn type-exception? (lambda () (vector-every 0 #() #()))) (check-tail-exn type-exception? (lambda () (vector-every (lambda () '()) 0 #()))) (check-exn type-exception? (lambda () (vector-every (lambda () '()) #() 0))) ;;;============================================================================ ;;; Mutators ;;;============================================================================ ;;; ;;;---------------------------------------------------------------------------- ;;; vector-set! ;;; primitive R5Rs ##vector-set! ;;;---------------------------------------------------------------------------- ;;; vector-swap! (let ((vec #(0 1 2 3 4))) (vector-swap! vec 0 1) (check-equal? vec #(1 0 2 3 4))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-swap! 0 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-swap! 0 1 2 3))) (check-tail-exn type-exception? (lambda () (vector-swap! 0 0 1))) ;;;---------------------------------------------------------------------------- ;;; vector-fill! (let ((vec #(0 0 0 0))) (vector-fill! vec 1 0 2) (check-equal? vec #(1 1 0 0))) (let ((vec #(0 0 0 0))) (vector-fill! vec 1) (check-equal? vec #(1 1 1 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-fill! 0))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-fill! 0 1 2 3 4))) (check-tail-exn type-exception? (lambda () (vector-fill! 0 1))) ;;;---------------------------------------------------------------------------- ;;; vector-reverse! (let ((vec #(0 1 2 3 4))) (vector-reverse! vec) (check-equal? vec #(4 3 2 1 0))) (let ((vec #(0 1 2 3 4))) (vector-reverse! vec 0 3) (check-equal? vec #(2 1 0 3 4))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-reverse!))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-reverse! 0 1 2 3))) (check-tail-exn type-exception? (lambda () (vector-reverse! 0))) ;;;---------------------------------------------------------------------------- ;;; vector-copy! (let ((vec1 #(0 1 2 3 4)) (vec2 #(5 6 7 8 9))) (vector-copy! vec2 0 vec1) (check-equal? vec2 vec1)) (let ((vec1 #(0 1 2 3 4)) (vec2 #(5 6 7 8 9))) (vector-copy! vec2 2 vec1 0 2 ) (check-equal? vec2 #(5 6 0 1 9))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-copy! 0 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-copy! 0 1 2 3 4 5))) (check-tail-exn type-exception? (lambda () (vector-copy! 0 1 #()))) (check-tail-exn type-exception? (lambda () (vector-copy! #() 1 0))) ;;;---------------------------------------------------------------------------- ;;; vector-reverse-copy! (let ((vec1 #(0 1 2 3 4)) (vec2 #(5 6 7 8 9))) (vector-reverse-copy! vec2 0 vec1) (check-equal? vec2 #(4 3 2 1 0))) (let ((vec1 #(0 1 2 3 4)) (vec2 #(5 6 7 8 9))) (vector-reverse-copy! vec2 2 vec1 0 2 ) (check-equal? vec2 #(5 6 1 0 9))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-reverse-copy! 0 1))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (vector-reverse-copy! 0 1 2 3 4 5))) (check-tail-exn type-exception? (lambda () (vector-reverse-copy! 0 1 #()))) (check-tail-exn type-exception? (lambda () (vector-reverse-copy! #() 1 0))) ;;;============================================================================ ;;; Conversion ;;;============================================================================ ;;; ;;;---------------------------------------------------------------------------- ;;; vector->list ;;; primitive R5Rs ##vector->list ;;;---------------------------------------------------------------------------- ;;; reverse-vector->list (check-equal? (reverse-vector->list #(0 1 2 3 4)) '(4 3 2 1 0)) (check-equal? (reverse-vector->list #(0 1 2 3 4) 1 3) '(2 1)) (check-equal? (reverse-vector->list #()) '()) (check-equal? (reverse-vector->list #(0)) '(0)) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (reverse-vector->list))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (reverse-vector->list 0 1 2 3))) (check-tail-exn type-exception? (lambda () (reverse-vector->list 0))) (check-tail-exn type-exception? (lambda () (reverse-vector->list 0))) ;;;---------------------------------------------------------------------------- ;;; list->vector ;;; primitive R5Rs ##list->vector (check-equal? (list->vector '(0 1 2 3)) #(0 1 2 3)) ;;;---------------------------------------------------------------------------- ;;; reverse-list->vector (check-equal? (reverse-list->vector '(0 1 2)) #(2 1 0)) (check-equal? (reverse-list->vector '()) #()) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (reverse-list->vector))) (check-tail-exn wrong-number-of-arguments-exception? (lambda () (reverse-list->vector 0 1 2 3))) ;;;============================================================================
false
8785c10c8137ced082ff4440f6b608fc514b7730
f87e36a1ba00008d7e957c8595c86b5550af05b9
/ch4/ex4.75.scm
bf66be3d51ac8b80cf30aefbf80800a4c6325e37
[]
no_license
kouheiszk/sicp
1b528898f825c0716acce6bdb36d378dcb04afec
eeb2f7d7634284faa7158c373a848b84084cc8cb
refs/heads/master
2020-04-16T07:00:43.135389
2014-06-16T11:57:43
2014-06-16T11:57:43
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,514
scm
ex4.75.scm
;;; ex4.75 (load "../global.scm") (load "./common4.4.4.scm") (load "./ch4-query.scm") (initialize-data-base microshaft-data-base) (initialize-data-base empty-data-base) ;; 質問言語にuniqueという新しい特殊形式を実装せよ. ;; uniqueは指定した質問を満足する項目がデータベースに唯一つある時に成功する. ;; 例えば ;; (unique (job ?x (computer wizard))) ;; は, Benは唯一人の計算機達人[computer wizard]なので, 一項目ストリーム ;; (unique (job (Bitdiddle Ben) (computer wizard))) ;; を印字する. ;; また ;; (unique (job ?x (computer programmer))) ;; は, 一人を超える計算機プログラマがいるので, 空ストリームを印字する. ;; 更に ;; (and (job ?x ?j) (unique (job ?anyone ?j))) ;; は, 一人だけが担当している仕事すべての担当者をリストする. ;; ;; uniqueの実装には二つの部分がある. ;; 第一はこの特殊形式を扱う手続きを書くこと, 第二はqevalにその手続きに振り分けさせることである. ;; qevalは振分けをデータ主導で行うので第二の部分は容易である. ;; この手続きをuniquely-assertedと呼ぶなら, なすべきことは ;; ;; (put 'unique 'qeval uniquely-asserted) ;; で, そうするとqevalはそのtype(car)が記号unique のすべての質問をこの手続きに振り分ける. ;; ;; 本当の問題は, 手続きuniquely-assertedを書くことである. ;; これは入力としてunique質問のcontents (cdr)をフレームのストリームと共にとる. ;; ストリームの各フレームについて, qevalを使い, 与えられた質問を満足するフレームへのすべての拡張ストリームを見つける. ;; そこの唯一個の項目を持つものでないストリームは除去する. ;; 残りのストリームは戻され, unique質問の結果である, 一つの大きなストリームに蓄積する. ;; これはnot特殊形式の実装に類似している. ;; ;; この実装を, 唯一人を監督する人すべてをリストする質問を形成してテストせよ. (define (uniquely-query exps) (car exps)) (define (stream-unique? s) (and (not (stream-null? s)) (stream-null? (stream-cdr s)))) (define (uniquely-asserted operands frame-stream) (stream-flatmap (lambda (frame) (let ((result (qeval (uniquely-query operands) (singleton-stream frame)))) (if (stream-unique? result) result the-empty-stream))) frame-stream)) (query-driver-loop) ;;; Query input: (unique (job ?x (computer wizard))) ;> ;;; Query results: ;> (unique (job (Bitdiddle Ben) (computer wizard))) ;> ;;; Query input: (and (supervisor ?x ?s) (unique (supervisor ?anyone ?x))) ;> ;;; Query results: ;> (and (supervisor (Cratchet Robert) (Scrooge Eben)) (unique (supervisor (Cratchet Robert) (Scrooge Eben)))) ;> (and (supervisor (Reasoner Louis) (Hacker Alyssa P)) (unique (supervisor (Reasoner Louis) (Hacker Alyssa P)))) ;> ;;; Query input: #q ;; 監督関係 ;; ;; (supervisor (Hacker Alyssa P) (Bitdiddle Ben)) ;; (supervisor (Fect Cy D) (Bitdiddle Ben)) ;; (supervisor (Tweakit Lem E) (Bitdiddle Ben)) ;; (supervisor (Reasoner Louis) (Hacker Alyssa P)) ;* ;; (supervisor (Bitdiddle Ben) (Warbucks Oliver)) ;; (supervisor (Scrooge Eben) (Warbucks Oliver)) ;; (supervisor (Cratchet Robert) (Scrooge Eben)) ;* ;; (supervisor (Aull DeWitt) (Warbucks Oliver))
false
f925558eb59697226e94da2a3f2f808527badafa
4bd59493b25febc53ac9e62c259383fba410ec0e
/Scripts/Task/day-of-the-week/scheme/day-of-the-week.ss
15dea1001f4ec68fde51ec18665312bef9d301cc
[]
no_license
stefanos1316/Rosetta-Code-Research
160a64ea4be0b5dcce79b961793acb60c3e9696b
de36e40041021ba47eabd84ecd1796cf01607514
refs/heads/master
2021-03-24T10:18:49.444120
2017-08-28T11:21:42
2017-08-28T11:21:42
88,520,573
5
1
null
null
null
null
UTF-8
Scheme
false
false
550
ss
day-of-the-week.ss
(define (day-of-week year month day) (if (< month 3) (begin (set! month (+ month 12)) (set! year (- year 1)))) (+ 1 (remainder (+ 5 day (quotient (* (+ 1 month) 13) 5) year (quotient year 4) (* (quotient year 100) 6) (quotient year 400)) 7))) (define (task) (let loop ((y 2121) (v '())) (if (< y 2008) v (loop (- y 1) (if (= 7 (day-of-week y 12 25)) (cons y v) v))))) (task) ; (2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)
false
d188c6e3c95cc94860ba26ac2198199be06581f7
1034eb1aad8254191d3a929a511094907e6ad7d3
/interfaces.scm
2e1e32ca167fb703d3b4676ddfd27424f4395ef2
[]
no_license
esovm/soosy
b383e113c0765759db0e9e1462f901d40ce0d410
c40d237f4cb02e93ecf0e8bd3dc33f4ef45a5c54
refs/heads/master
2021-05-28T14:02:31.210874
2009-04-04T16:28:24
2009-04-04T16:28:24
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,040
scm
interfaces.scm
;;; -*- Mode: Scheme; scheme48-package: (config) -*- (define-interface soosy-macros/interface (export (define-class :syntax) (define-method :syntax) (with-instance-variables :syntax) (==> :syntax) (usual==> :syntax) )) (define-interface soosy-objects/interface (export make-class make-object class object object-class object-variables object-methods object-method object-variable set-object-variable! send send-usual class? object? object-of-class? base-class? subclass? class-name class-superclass class-subclasses class-methods class-method-define class-variables)) (define-interface soosy-helpers/interface (compound-interface soosy-objects/interface (export *all-classes* add-class! false? name->class with-instance-variables*))) (define-interface soosy/interface (compound-interface soosy-macros/interface soosy-objects/interface))
false
23480443ba382ae8f0f70b01926cd047779c50b4
d6910224fa09f702ff00eda6d83ba0631dd36e13
/4-21.scm
6cd61f250d91e84b46b83eca5493875f7fa76f07
[]
no_license
jeffgyf/sicp_homework
786dd9f5eed315018279d79ad8a1c73662d9f4ce
f2564b06e19362af78206b51cd963ff34787a8e8
refs/heads/master
2020-04-12T14:17:03.342146
2019-05-06T05:54:27
2019-05-06T05:54:27
162,547,609
1
0
null
null
null
null
UTF-8
Scheme
false
false
3,523
scm
4-21.scm
;3.54 (define factorials (cons-stream 1 (mul-streams factorials integers))) ;3.55 (define (partial-sums s) (cons-stream (stream-car s) (add-streams (partial-sums s) (stream-cdr s)))) ;3.56 (define (merge-streams s1 s2) (cond ((stream-null? s1) s2) ((stream-null? s2) s1) (else (let ((s1car (stream-car s1)) (s2car (stream-car s2))) (cond ((< s1car s2car) (cons-stream s1car (merge-streams (stream-cdr s1) s2))) ((> s1car s2car) (cons-stream s2car (merge-streams s1 (stream-cdr s2)))) (else (cons-stream s1car (merge-streams (stream-cdr s1) (stream-cdr s2))))))))) ;E3.59 (define S (cons-stream 1 (merge-streams (scale-stream S 2) (merge-streams (scale-stream S 3) (scale-stream S 5))))) (define (integrate-series s) (div-streams s integers)) (define exp-series (cons-stream 1 (integrate-series exp-series))) (define cosine-series (cons-stream 1 (integrate-series sine-series))) (define sine-series (cons-stream 0 (integrate-series (scale-stream cosine-series -1)))) ;E3.60 (define (mul-series s1 s2) (let ((scar1 (stream-car s1)) (scar2 (stream-car s2))) (cons-stream (* scar1 scar2) (add-streams (add-streams (scale-stream (stream-cdr s1) scar2) (scale-stream (stream-cdr s2) scar1)) (cons-stream 0 (mul-series (stream-cdr s1) (stream-cdr s2))))))) (add-streams (mul-series sine-series sine-series) (mul-series cosine-series cosine-series)) ;E3.61 (define (invert-unit-series s) (cons-stream 1 (scale-stream (mul-series (stream-cdr s) (invert-unit-series s)) -1))) ;E3.62 (define (div-series s1 s2) (cond ((= 0 (stream-car s2)) (error "div-series" "divide by 0")) (else (mul-series s1 (scale-stream (invert-unit-series (scale-stream s2 (/ 1(stream-car s2)))) (stream-car s2)))))) (define tan-series (div-series sine-series cosine-series)) ;E3.64 (define (sqrt-stream x) (define guesses (cons-stream 1.0 (stream-map (lambda (guess) (sqrt-improve guess x)) guesses))) guesses) (define (sqrt-improve guess x) (/ (+ guess (/ x guess)) 2)) (define (stream-limit s tolerance) (let ((s1 (stream-car s)) (s2 (stream-car (stream-cdr s)))) (cond ((< (abs (- s1 s2)) tolerance) s2) (else (stream-limit (stream-cdr s) tolerance))))) (define (sqrt x tolerance) (stream-limit (sqrt-stream x) tolerance)) (define ln2-series ((lambda () (define (series n) (cons-stream (/ 1 n) (scale-stream (series (+ n 1)) -1))) (series 1)))) (define ln2 (partial-sums ln2-series)) (define (euler-transform s) (let ((s0 (stream-ref s 0)) ; S n-1 (s1 (stream-ref s 1)) ; S n (s2 (stream-ref s 2))) ; S n+1 (cons-stream (- s2 (/ (square (- s2 s1)) (+ s0 (* -2 s1) s2))) (euler-transform (stream-cdr s))))) (define (square n) (* n n))
false
5c0b4d4a2aff3f1d13c85a9ee76e3b99dafca9e7
fe0de995a95bcf09cd447349269dc0e550851b5a
/tests/0009-lambda-2.program.scm
da5e8da0cbd326efd56ddfd235c41d7ce2b7b110
[ "MIT" ]
permissive
mugcake/ruse-scheme
4974021858be5b7f2421212ec2eeafd34c53bce8
dd480e17edd9a233fd2bc4e8b41ff45d13fcc328
refs/heads/master
2022-02-12T04:31:55.031607
2019-08-01T21:44:14
2019-08-01T21:44:14
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
105
scm
0009-lambda-2.program.scm
(import (tests)) (let ((abc 42) (def 101)) ((lambda (x) (add x -1)) (add abc (times def 100))))
false
08633fb566d3eeec5947eee025129feab8e0f2ee
5bf673b5bd8de5c1a943b739b9c2e0426da85d7c
/tests/redir.scm
dba8497c680fb577b3ca0d6b7f6a66258db7e209
[ "BSD-2-Clause" ]
permissive
mario-goulart/awful
dfe44157865d5b9b94004efc30ddb1dc4bf0e441
739f7b4c6b808db3d4c05bf43aa095dd6543252e
refs/heads/master
2023-04-14T08:34:19.377592
2023-04-10T09:17:29
2023-04-10T09:17:29
4,197,893
68
5
NOASSERTION
2023-02-12T09:18:16
2012-05-02T00:02:50
Scheme
UTF-8
Scheme
false
false
749
scm
redir.scm
#!/usr/bin/awful (cond-expand (chicken-4 (use irregex) (use awful)) (chicken-5 (import (chicken irregex)) (import awful)) (else (error "Unsupported CHICKEN version."))) ;; / -> /foo (define-page (main-page-path) (cut redirect-to "/foo")) ;; /bar.* -> /foo (define-page (irregex "/bar.*") (lambda (_) (redirect-to "/foo"))) (define-page "/foo" (lambda () "foo")) ;; A chain of redirections. Access http://localhost:8080/a and you ;; should be redirected to /d through /b and /c (define-page "/a" (cut redirect-to "/b")) (define-page "/b" (cut redirect-to "/c")) (define-page "/c" (cut redirect-to "/d")) (define-page "/d" (lambda () "D")) (define-page "/chicken" (cut redirect-to "http://www.call-cc.org"))
false
0858ea41de4e275c0ce7514ae2c9468c5f541b4a
3132831399eacc4bd1ae519aac18a1342dec7282
/Homeworks/4th/02.scm
c083620f074eeddd3344c7591c58332507b55e64
[]
no_license
TsHristov/Functional-Programming-FMI-2017
ba3f1d46ed276f0fa4da7e6c396e4f50c1291e0d
58176d53d507c6df70465e1fcfbcd2c67f8af0aa
refs/heads/master
2021-09-05T18:49:14.471004
2018-01-30T11:08:00
2018-01-30T11:08:00
105,808,452
6
0
null
null
null
null
UTF-8
Scheme
false
false
563
scm
02.scm
(define root-tree car) (define left-tree cadr) (define right-tree caddr) (define empty-tree? null?) (define (leaf? tree) (and (not (empty-tree? (root-tree tree))) (empty-tree? (left-tree tree)) (empty-tree? (right-tree tree)))) ;; reduce-tree: (define (reduce-tree proc null-value tree) (cond ((empty-tree? tree) null-value) ((leaf? tree) (root-tree tree)) (else (proc (reduce-tree proc null-value (left-tree tree)) (reduce-tree proc null-value (right-tree tree)))))) ;; sum-leaves: (define (sum-leaves tree) (reduce-tree + 0 tree))
false
43558c665c57df9001af1a6922ed741a1dfba572
4890b89d4e190ad152c26f5f1565d1157c0972e7
/Compiler/remove-let.ss
0c50ce6681a35a41a0b5df4c42a6366a67aa96d9
[]
no_license
haskellstudio/p-423-Compiler
e2791bae1b966cd1650575e39eef10b4c7205ca1
36be558647ecd5786b02df42865d0ffa2a57fa2f
refs/heads/master
2021-01-25T13:11:49.825526
2017-11-09T03:48:00
2017-11-09T03:48:00
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,431
ss
remove-let.ss
(library (Compiler remove-let) (export remove-let) (import (chezscheme) (Framework match) (Framework helpers)) (define-who remove-let (define binops '(mref + - * logand logor sra)) (define relops '(< > <= >= =)) (define Body (lambda (body) (match body [(locals ,uvar* ,(Tail -> tail)) `(locals ,uvar* ,tail)] [,x (error who "invalid Body ~s" x)]))) (define Value (lambda (val) (match val [(let ([,set-var* ,(Value -> val*)] ...) ,(Value -> val)) (make-begin `((set! ,set-var* ,val*) ... ,val))] [(if ,(Pred -> test) ,(Value -> conseq) ,(Value -> altern)) `(if ,test ,conseq ,altern)] [(begin ,(Effect -> eff*) ... ,(Value -> val)) (make-begin `(,eff* ... ,val))] [(,binop ,(Value -> val1) ,(Value -> val2)) (guard (memq binop binops)) `(,binop ,val1 ,val2)] [(alloc ,(Value -> val)) `(alloc ,val)] [(,(Value -> val) ,(Value -> val*) ...) `(,val ,val* ...)] [,x x]))) (define Effect (lambda (ef) (match ef [(nop) '(nop)] [(let ([,set-var* ,(Value -> values*)] ...) ,(Effect -> effect)) (make-begin `((set! ,set-var* ,values*) ... ,effect))] [(if ,(Pred -> test) ,(Effect -> conseq) ,(Effect -> altern)) `(if ,test ,conseq ,altern)] [(begin ,(Effect -> eff*) ... ,(Effect -> eff)) (make-begin `(,eff* ... ,eff))] [(mset! ,(Value -> val1) ,(Value -> val2) ,(Value -> val3)) `(mset! ,val1 ,val2 ,val3)] [(,(Value -> val) ,(Value -> val*) ...) `(,val ,val* ...)] [,ef (error who "invalid Effect ~s" ef)]))) (define Pred (lambda (pr) (match pr [(true) '(true)] [(false) '(false)] [(let ([,set-var* ,(Value -> values*)] ...) ,(Pred -> pred)) (make-begin `((set! ,set-var* ,values*) ... ,pred))] [(if ,(Pred -> test) ,(Pred -> conseq) ,(Pred -> altern)) `(if ,test ,conseq ,altern)] [(begin ,(Effect -> effect*) ... ,(Pred -> pred)) (make-begin `(,effect* ... ,pred))] [(,relop ,(Value -> val1) ,(Value -> val2)) (guard (memq relop relops)) `(,relop ,val1 ,val2)] [,pr (error who "invalid Pred ~s" pr)]))) (define Tail (lambda (tail) (match tail [(let ([,set-var* ,(Value -> values*)] ...) ,(Tail -> new-tail)) (make-begin `((set! ,set-var* ,values*) ... ,new-tail))] [(if ,(Pred -> test) ,(Tail -> conseq) ,(Tail -> altern)) `(if ,test ,conseq ,altern)] [(begin ,(Effect -> effect*) ... ,(Tail -> new-tail)) (make-begin `(,effect* ... ,new-tail))] [(,binop ,(Value -> val1) ,(Value -> val2)) (guard (memq binop binops)) `(,binop ,val1 ,val2)] [(alloc ,(Value -> val)) `(alloc ,val)] [(,(Value -> val) ,(Value -> val*) ...) `(,val ,val* ...)] [,x x]))) (lambda (x) (match x [(letrec ([,label* (lambda (,uvar* ...) ,(Body -> body*))] ...) ,(Body -> body)) `(letrec ([,label* (lambda (,uvar* ...) ,body*)] ...) ,body)] [,x (error who "invalid Program ~s" x)]))))
false
0d119c789c41a2395d9b569d5eab6332a7495083
c872e91f18e48b8571293d27469284199a4877fc
/interpreter.ss
f14b881af90f242b3ab0307628fb0dc32519f54e
[]
no_license
lamberce/Programming-Language-Concepts-GitHub
95afc0d0237a57c78a1d0aae1085ef4af3479256
585b78bbf6e3d4c8006badb9b376c6fa88d62ce4
refs/heads/master
2021-01-10T20:36:52.841958
2015-01-18T18:53:29
2015-01-18T18:53:29
29,436,770
0
0
null
null
null
null
UTF-8
Scheme
false
false
10,992
ss
interpreter.ss
;;<program> <graphic> <form>* ;;<form> <graphic> <definition> | <expression> ;;<definition> <graphic> <variable definition> | (begin <definition>*) ;;<variable definition> <graphic> (define <variable> <expression>) ;;<expression> <graphic> <constant> ;; | <variable> ;; | (quote <datum>) ;; | (lambda <formals> <expression> <expression>*) ;; | (if <expression> <expression> <expression>) ;; | (set! <variable> <expression>) ;; | <application> ;;<constant> <graphic> <boolean> | <number> | <character> | <string> ;;<formals> <graphic> <variable> ;; | (<variable>*) ;; | (<variable> <variable>* . <variable>) ;;<application> <graphic> (<expression> <expression>*) (define def? (lambda (ls) (or (symbol? ls) (list-of symbol? ls)))) (define-datatype procedure procedure? [primitive (id symbol?)] [closure-record (parameter def?) (body expression?) (env list?)]) (define-datatype continuation continuation? (halt-cont) (rep-cont) (cons-cont (v scheme-value?) (cont continuation?)) (proc-cont (cont continuation?)) (eval-exps-cont (exps (list-of expression?)) (env scheme-value?) (cont continuation?)) (if-cont (true-exp expression?) (false-exp expression?) (cont continuation?) (env list?)) (if-true-cont (true-exp expression?) (cont continuation?) (env list?)) (map-cont (proc scheme-value?) (ls list?) (cont continuation?)) ;;(cons-cont ;;(a scheme-value?) ;;(cont continuation?)) (applyh-cont (proc scheme-value?) (ls list?) (cont continuation?)) (call/cc-cont (cont continuation?))) (define apply-cont (lambda (cont val) (cases continuation cont [halt-cont () val] [eval-exps-cont (exps env cont) (eval-exps exps (cons-cont val cont) env)] [cons-cont (v cont) (apply-cont cont (cons v val))] [proc-cont (cont) (apply-proc val cont)] [if-cont (if-true-exp if-false-exp next-cont env) (if val (eval-expression if-true-exp next-cont env) (eval-expression if-false-exp next-cont env))] [if-true-cont (if-true-exp next-cont env) (if val (eval-expression if-true-exp next-cont env))] [map-cont (proc ls cont) (map-helper proc ls cont)] ;;[cons-cont (a cont) ;; (apply-cont cont (cons val a))] [applyh-cont (proc ls cont) (apply-cont cont (apply-helper proc (list (cdar ls)) (apply-primitive-proc proc (list val (caar ls))) cont))] [call/cc-cont (cont) (cases procedure val [closure-record (parameter body env) (eval-expression body cont (extend-env parameter (list (acontinuation cont)) env))] [else (eopl:error 'apply-primitive-proc "Not a procedure ~s" val)])] [rep-cont () val]))) (define *prim-proc-names* '(+ - * / add1 sub1 zero? not = < > <= >= cons car cdr caar cddr cadr cdar caaar caadr cadar cdaar caddr cdadr cddar cdddr list null? eq? equal? atom? length list->vector list? pair? procedure? vector->list vector make-vector vector-ref vector? number? symbol? set-car! set-cdr! vector-set! list map apply assq assv append exit)) (define reset-global-env (lambda () (set! global-env (extend-env *prim-proc-names* (map primitive *prim-proc-names*) (empty-env))))) (define global-env (extend-env *prim-proc-names* (map primitive *prim-proc-names*) (empty-env))) (define eval-one-exp (lambda (exp) (top-level-eval (parse-expression exp)))) (define rep (lambda () (display ">> ") (let ([input (read)]) (if (equal? input '(exit)) (printf "Bye...~%") (let* ([parse-tree (parse-expression input)] [response (top-level-eval parse-tree)]) (pretty-print response) (rep)))))) (define top-level-eval (lambda (form) (eval-expression form (halt-cont) (extend-env '(a b) '(3 4) global-env)))) (define eval-expression (lambda (exp cont env) (cases expression exp [var-exp (id) (apply-cont cont (apply-env env id))] [val-exp (val) (apply-cont cont val)] [num-exp (val) (apply-cont cont val)] [lambda-exp (ids body) (apply-cont cont (closure-record ids body env))] [lambda-spec-exp (id body) (apply-cont cont (closure-record (list id) body env))] [if-exp (test-exp true-exp false-exp) (eval-expression test-exp (if-cont true-exp false-exp cont env) env)] [if-true-exp (conditional if-true) (eval-expression conditional (if-true-cont if-true cont env) env)] [let-exp (definitions body) (syntax-expand exp env)] [named-let-exp (name definitions body) '#f] [letrec-exp (definitions body) '#f] [let*-exp (definitions body) (syntax-expand exp env)] [set!-exp (id value) (let ([id id] [body (eval-expression value env)] [env env]) (if (not (null? env)) (if (member id (caar env)) (change-env env id body) (set! global-env (list (cons (cons id (caar global-env)) (list->vector (cons body (vector->list (cdar global-env)))))))) (set! global-env (list (cons (cons id (caar global-env)) (list->vector (cons body (vector->list (cdar global-env)))))))))] [define-exp (id value) (let ([id id] [body (eval-expression value env)] [env env]) (begin (if (not (null? env)) (if (member id (caar env)) (change-env env id body) (set! global-env (list (cons (cons id (caar global-env)) (list->vector (cons body (vector->list (cdar global-env)))))))) (set! global-env (list (cons (cons id (caar global-env)) (list->vector (cons body (vector->list (cdar global-env)))))))) (if (procedure? value) (cases procedure value [primitive (id)] [closure-record (id2 body2 env2) (set! global-env (list (cons (cons id (caar global-env)) (list->vector (cons (make-closure id2 body2 global-env) (vector->list (cdar global-env)))))))] ))))] [begin-exp (body) (eval-begin body cont env)] [cond-exp (conditionals bodies) (syntax-expand exp env)] [and-exp (bodies) (syntax-expand exp env)] [or-exp (bodies) (syntax-expand exp env)] [case-exp (obj conditionals bodies) (syntax-expand exp env)] [while-exp (test-exp body) (if (eval-expression test-exp env) (begin (eval-expression body env) (eval-expression (while-exp test-exp body) env)))] [call/cc-exp (receiver) (eval-expression receiver (call/cc-cont cont) env)] [app-exp (exps) (eval-exps exps (proc-cont cont) env)]))) (define eval-exps (lambda (exps cont env) (if (null? exps) (apply-cont cont '()) (eval-expression (car exps) (eval-exps-cont (cdr exps) env cont) env)))) (define eval-begin (lambda (ls cont env) (if (= (length ls) 1) (eval-expression (car ls) cont env) (begin (eval-expression (car ls) cont env) (eval-begin (cdr ls) cont env))))) (define make-closure (lambda (id body) (closure-record id body))) (define apply-proc (lambda (proc cont) (if (procedure? (car proc)) (cases procedure (car proc) [closure-record (id body env) (eval-expression body cont (extend-env id (cdr proc) env))] [acontinuation (cont) (apply-cont cont (cadr args))] [primitive (id) (apply-primitive-proc id (cdr proc) cont)]) proc))) (define apply-primitive-proc (lambda (id args cont) (case id [(+) (apply-cont cont (apply + args))] [(-) (apply-cont cont (apply - args))] [(*) (apply-cont cont (apply * args))] [(/) (apply-cont cont (apply / args))] [(add1) (apply-cont cont (+ (car args) 1))] [(sub1) (apply-cont cont (- (car args) 1))] [(exit) (if (null? args) (apply-cont (halt-cont) (void)) (apply-cont (rep-cont) (car args)))] [(zero?) (apply-cont cont (zero? (car args)))] [(not) (apply-cont cont (not (car args)))] [(=) (apply-cont cont (= (car args) (cadr args)))] [(<=) (apply-cont cont (<= (car args) (cadr args)))] [(>=) (apply-cont cont (>= (car args) (cadr args)))] [(>) (apply-cont cont (> (car args) (cadr args)))] [(<) (apply-cont cont (< (car args) (cadr args)))] [(null?) (apply-cont cont (null? (car args)))] [(eq?) (apply-cont cont (eq? (car args) (cadr args)))] [(equal?) (apply-cont cont (equal? (car args) (cadr args)))] [(atom?) (apply-cont cont (atom? (car args)))] [(length) (apply-cont cont (length (car args)))] [(list->vector) (apply-cont cont (list->vector (car args)))] [(list) (apply-cont cont args)] [(list?) (apply-cont cont (list? (car args)))] [(pair?) (apply-cont cont (pair? (car args)))] [(procedure?) (apply-cont cont (procedure? (car args)))] [(vector->list) (apply-cont cont (vector->list (car args)))] [(vector) (apply-cont cont (list->vector args))] [(make-vector) (apply-cont cont (make-vector (car args)))] [(vector-ref) (apply-cont cont (vector-ref (car args) (cadr args)))] [(vector?) (apply-cont cont (vector? (car args)))] [(number?) (apply-cont cont (number? (car args)))] [(symbol?) (apply-cont cont (symbol? (car args)))] [(set-car!) (apply-cont cont (set-car! (car args) (cadr args)))] [(set-cdr!) (apply-cont cont (set-cdr! (car args) (cadr args)))] [(vector-set!) (apply-cont cont (vector-set! (car args) (cadr args) (caddr args)))] [(cons) (apply-cont cont (cons (car args) (cadr args)))] [(car) (apply-cont cont (car (car args)))] [(cdr) (apply-cont cont (cdr (car args)))] [(caar) (apply-cont cont (caar (car args)))] [(cadr) (apply-cont cont (cadr (car args)))] [(cdar) (apply-cont cont (cdar (car args)))] [(cddr) (apply-cont cont (cddr (car args)))] [(caaar) (apply-cont cont (caaar (car args)))] [(caadr) (apply-cont cont (caadr (car args)))] [(cadar) (apply-cont cont (cadar (car args)))] [(cdaar) (apply-cont cont (cdaar (car args)))] [(caddr) (apply-cont cont (caddr (car args)))] [(cdadr) (apply-cont cont (cdadr (car args)))] [(cddar) (apply-cont cont (cddar (car args)))] [(cdddr) (apply-cont cont (cdddr (car args)))] [(map) (apply-cont (map-cont (cadar args) (cdr args) (halt-cont)) '())] [(apply) (apply-cont (map-cont (cadar args) (list (cdar (cdr args))) (caar (cdr args)) (halt-cont)))] [(assq) (apply-cont cont (assq (cadar args) (cdr args)))] [(assv) (apply-cont cont (assv (cadar args) (cdr args)))] [(append) (apply-cont cont (append (car args) (cdr args)))] [else (eopl:error 'apply-primitive-proc "Procedure ~s not found" id)]))) (define map-helper (lambda (proc ls cont) (if (null? (car ls)) (apply-cont cont '()) (map-helper proc (list (cdar ls)) (cons-cont (apply-primitive-proc proc (car ls) cont) cont))))) (define apply-helper (lambda (proc ls accu cont) (if (null? (car ls)) (apply-cont cont accu) (applyh-cont proc ls cont))))
false
5a2cb84b71859f936bdd356e1e6285e18518e13a
7e0c613b8a2781aab692a5976b0e8896ac18b4fb
/tests/der.sps
aa4a6a171cfe804ea9dded01ef80fcb5bdf0db4f
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
atomontage/industria
f279fb71cc69032cc4084c1e2f09bfacefe2fc6c
f13b067ce3b8b82f09c5670a45dfde29da29c5fb
refs/heads/master
2021-01-22T12:13:08.369334
2019-05-26T18:07:25
2019-05-26T18:07:25
24,039,099
0
0
null
null
null
null
UTF-8
Scheme
false
false
13,938
sps
der.sps
#!/usr/bin/env scheme-script ;; -*- mode: scheme; coding: utf-8 -*- !# ;; Copyright © 2010, 2018 Göran Weinholt <[email protected]> ;; Permission is hereby granted, free of charge, to any person obtaining a ;; copy of this software and associated documentation files (the "Software"), ;; to deal in the Software without restriction, including without limitation ;; the rights to use, copy, modify, merge, publish, distribute, sublicense, ;; and/or sell copies of the Software, and to permit persons to whom the ;; Software is furnished to do so, subject to the following conditions: ;; The above copyright notice and this permission notice shall be included in ;; all copies or substantial portions of the Software. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ;; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ;; DEALINGS IN THE SOFTWARE. #!r6rs (import (rnrs (6)) (srfi :64 testing) (industria bit-strings) (industria bytevectors) (prefix (industria der) der:)) (test-begin "der-subjectaltname") (define (SubjectAltName) `(sequence-of 1 +inf.0 ,(GeneralName))) (define (GeneralName) `(choice #;(otherName (implicit context 0 ,(OtherName))) (rfc822Name (implicit context 1 ia5-string)) (dNSName (implicit context 2 ia5-string)) #;etc...)) (test-equal '(sequence 0 32 (((prim context 2) 2 17 #vu8(119 119 119 46 119 101 105 110 104 111 108 116 46 115 101)) ((prim context 2) 19 13 #vu8(119 101 105 110 104 111 108 116 46 115 101)))) (der:decode #vu8(48 30 130 15 119 119 119 46 119 101 105 110 104 111 108 116 46 115 101 130 11 119 101 105 110 104 111 108 116 46 115 101))) (test-equal '("www.weinholt.se" "weinholt.se") (der:translate (der:decode #vu8(48 30 130 15 119 119 119 46 119 101 105 110 104 111 108 116 46 115 101 130 11 119 101 105 110 104 111 108 116 46 115 101)) (SubjectAltName))) (test-end) (test-begin "der-encode-boolean") (test-equal #vu8(#x01 #x01 #x00) (der:encode #f '(boolean 0 0 #f))) (test-equal #vu8(#x01 #x01 #xff) (der:encode #f '(boolean 0 0 #t))) (test-equal '(boolean 0 3 #f) (der:decode (der:encode #f '(boolean 0 0 #f)))) (test-equal '(boolean 0 3 #t) (der:decode (der:encode #f '(boolean 0 0 #t)))) (test-end) (test-begin "der-encode-integer") (test-equal #vu8(#x02 #x01 0) (der:encode #f '(integer 0 0 0))) (test-equal #vu8(#x02 #x01 42) (der:encode #f '(integer 0 0 42))) (test-equal #vu8(#x02 #x01 #xd6) (der:encode #f '(integer 0 0 -42))) (test-equal #vu8(#x02 #x01 #x80) (der:encode #f '(integer 0 0 -128))) (do ((i -514 (+ i 1))) ((= i 514)) (test-equal i (der:data-value (der:decode (der:encode #f `(integer 0 0 ,i)))))) (test-end) (test-begin "der-encode-bit-string") (let ((b (integer->bit-string #x0A3B5F291CD 44))) (test-equal #vu8(#x03 #x07 #x04 #x0A #x3B #x5F #x29 #x1C #xD0) (der:encode #f (list 'bit-string 0 0 b))) (let ((x (der:decode #vu8(#x03 #x07 #x04 #x0A #x3B #x5F #x29 #x1C #xD0)))) (test-equal (der:data-type x) 'bit-string) (test-equal (der:data-start-index x) 0) (test-equal (der:data-length x) 9) (test-equal (bit-string->bytevector (der:data-value x)) (bit-string->bytevector b)) (test-equal (bit-string-length (der:data-value x)) (bit-string-length b)))) (let ((b (integer->bit-string 0 0))) (test-equal #vu8(#x03 #x01 #x00) (der:encode #f (list 'bit-string 0 0 b))) (let ((x (der:decode #vu8(#x03 #x01 #x00)))) (test-equal (der:data-type x) 'bit-string) (test-equal (der:data-start-index x) 0) (test-equal (der:data-length x) 3) (test-equal (bit-string->bytevector (der:data-value x)) (bit-string->bytevector b)) (test-equal (bit-string-length (der:data-value x)) (bit-string-length b)))) (test-end) (test-begin "der-encode-octet-string") (test-equal #vu8(#x04 #x00) (der:encode #f '(octet-string 0 0 #vu8()))) (test-equal #vu8(#x04 #x01 1) (der:encode #f '(octet-string 0 0 #vu8(1)))) (test-equal '(octet-string 0 2 #vu8()) (der:decode (der:encode #f '(octet-string 0 0 #vu8())))) (test-equal '(octet-string 0 3 #vu8(1)) (der:decode (der:encode #f '(octet-string 0 0 #vu8(1))))) (test-end) (test-begin "der-encode-null") (test-equal #vu8(#x05 #x00) (der:encode #f '(null 0 0 #f))) (test-equal '(null 0 2 #f) (der:decode (der:encode #f '(null 0 0 #f)))) (test-end) (test-begin "der-encode-utf8-string") (let ((jones #vu8(#x0c #x06 195 165 195 164 195 182))) (test-equal '(utf8-string 0 8 "åäö") (der:decode jones)) (test-equal jones (der:encode #f '(utf8-string 0 0 "åäö")))) (test-end) (test-begin "der-encode-printable-string") (let ((jones #vu8(#x13 #x05 #x4A #x6F #x6E #x65 #x73))) (test-equal '(printable-string 0 7 "Jones") (der:decode jones)) (test-equal jones (der:encode #f '(printable-string 0 0 "Jones")))) (test-end) (test-begin "der-encode-t61-string") (let ((jones #vu8(#x14 #x05 #x4A #x6F #x6E #x65 #x73))) (test-equal '(t61-string 0 7 "Jones") (der:decode jones)) (test-equal jones (der:encode #f '(t61-string 0 0 "Jones")))) (test-end) (test-begin "der-encode-ia5string") (let ((smith #vu8(#x16 #x05 83 109 105 116 104))) (test-equal '(ia5-string 0 7 "Smith") (der:decode smith)) (test-equal #vu8(#x16 #x00) (der:encode #f '(ia5-string 0 0 ""))) (test-equal smith (der:encode #f '(ia5-string 0 0 "Smith"))) (test-equal #vu8(#x16 3 #x30 #x0a #x30) (der:encode #f '(ia5-string 0 0 "0\n0")))) (test-end) (test-begin "der-encode-visible-string") (let ((jones #vu8(#x1A #x05 #x4A #x6F #x6E #x65 #x73))) (test-equal '(visible-string 0 7 "Jones") (der:decode jones)) (test-equal jones (der:encode #f '(visible-string 0 0 "Jones")))) (test-end) (test-begin "der-encode-sequence") (let ((example #vu8(#x30 #x0a #x16 #x05 83 109 105 116 104 #x01 #x01 #xff))) (test-equal '(sequence 0 12 ((ia5-string 2 7 "Smith") (boolean 9 3 #t))) (der:decode example)) (test-equal example (der:encode #f '(sequence 0 0 ((ia5-string 0 0 "Smith") (boolean 0 0 #t)))))) (test-end) (test-begin "der-encode-set") (let ((example #vu8(#x31 #x0a #x16 #x05 83 109 105 116 104 #x01 #x01 #xff))) (test-equal '(set 0 12 ((ia5-string 2 7 "Smith") (boolean 9 3 #t))) (der:decode example)) (test-equal example (der:encode #f '(set 0 0 ((ia5-string 0 0 "Smith") (boolean 0 0 #t)))))) (test-end) (test-begin "der-encode-object-id") (let ((example #vu8(#x06 #x03 #x81 #x34 #x03))) (test-equal '(object-identifier 0 5 (2 100 3)) (der:decode example)) (test-equal example (der:encode #f '(object-identifier 0 0 (2 100 3))))) (do ((x 0 (+ x 1))) ((= x 2)) (do ((y 0 (+ y 1))) ((> y 39)) (do ((z 0 (+ z 1))) ((> z 300)) (test-equal `(,x ,y ,z) (der:data-value (der:decode (der:encode #f `(object-identifier 0 0 (,x ,y ,z))))))))) (test-end) (test-begin "der-encode-relative-object-id") (let ((example #vu8(#x0D #x04 #xC2 #x7B #x03 #x02))) (test-equal '(relative-oid 0 6 (8571 3 2)) (der:decode example)) (test-equal example (der:encode #f '(relative-oid 0 0 (8571 3 2))))) (test-end) (test-begin "der-encode-digest") (define (DigestInfo) '(sequence (digestAlgorithm (sequence (algorithm object-identifier) (parameters ANY (default #f)))) (digest octet-string))) (let ((example #vu8(#x30 #x31 #x30 #x0d #x06 #x09 #x60 #x86 #x48 #x01 ;RFC3447 #x65 #x03 #x04 #x02 #x01 #x05 #x00 #x04 #x20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)) (decoded '(sequence 0 51 ((sequence 2 15 ((object-identifier 4 11 (2 16 840 1 101 3 4 2 1)) (null 15 2 #f))) (octet-string 17 34 #vu8(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)))))) (test-equal decoded (der:decode example)) (test-equal example (der:encode #f decoded)) (test-equal decoded (der:decode (der:encode #f decoded))) (test-equal '((digestAlgorithm (algorithm . (2 16 840 1 101 3 4 2 1)) (parameters . (null 15 2 #f))) (digest . #vu8(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16))) (der:translate decoded (DigestInfo) (lambda (name type value start len) (cons name value))))) (test-end) (test-begin "der-encode-long") (test-equal #vu8(#x1A #b10000001 #b11001001) (subbytevector (der:encode #f `(visible-string 0 0 ,(make-string 201 #\x))) 0 3)) (test-equal #vu8(#x40 0) (der:encode #f `((prim application 0) 0 0 #vu8()))) (test-equal #vu8(#x60 0) (der:encode #f `((cons application 0) 0 0 ()))) (test-equal #vu8(#x5f 31 0) (der:encode #f `((prim application 31) 0 0 #vu8()))) (let ((decoded '((prim application #b110110011) 0 4 #vu8())) (binary #vu8(#x5f #b10000011 #b00110011 0))) (test-equal binary (der:encode #f decoded)) (test-equal decoded (der:decode binary))) (let ((decoded '((cons application #b110110011) 0 4 ())) (binary #vu8(#x7f #b10000011 #b00110011 0))) (test-equal binary (der:encode #f decoded)) (test-equal decoded (der:decode binary))) (test-end) (test-begin "der-encode-long-example") (letrec ((utf8 (lambda (str) (bytevector->u8-list (string->utf8 str))))) (let ((binary (u8-list->bytevector ;from X.690 (07/2002) `(#x60 #x81 #x85 #x61 #x10 #x1A #x04 ,@(utf8 "John") #x1A #x01 ,@(utf8 "P") #x1A #x05 ,@(utf8 "Smith") #xA0 #x0A #x1A #x08 ,@(utf8 "Director") #x42 #x01 #x33 #xA1 #x0A #x43 #x08 ,@(utf8 "19710917") #xA2 #x12 #x61 #x10 #x1A #x04 ,@(utf8 "Mary") #x1A #x01 ,@(utf8 "T") #x1A #x05 ,@(utf8 "Smith") #xA3 #x42 #x31 #x1F #x61 #x11 #x1A #x05 ,@(utf8 "Ralph") #x1A #x01 ,@(utf8 "T") #x1A #x05 ,@(utf8 "Smith") #xA0 #x0A #x43 #x08 ,@(utf8 "19571111") #x31 #x1F #x61 #x11 #x1A #x05 ,@(utf8 "Susan") #x1A #x01 ,@(utf8 "B") #x1A #x05 ,@(utf8 "Jones") #xA0 #x0A #x43 #x08 ,@(utf8 "19590717")))) (decoded `((cons application 0) 0 136 (((cons application 1) 3 18 ((visible-string 5 6 "John") (visible-string 11 3 "P") (visible-string 14 7 "Smith"))) ((cons context 0) 21 12 ((visible-string 23 10 "Director"))) ((prim application 2) 33 3 #vu8(#x33)) ((cons context 1) 36 12 (((prim application 3) 38 10 ,(string->utf8 "19710917")))) ((cons context 2) 48 20 (((cons application 1) 50 18 ((visible-string 52 6 "Mary") (visible-string 58 3 "T") (visible-string 61 7 "Smith"))))) ((cons context 3) 68 68 ((set 70 33 (((cons application 1) 72 19 ((visible-string 74 7 "Ralph") (visible-string 81 3 "T") (visible-string 84 7 "Smith"))) ((cons context 0) 91 12 (((prim application 3) 93 10 ,(string->utf8 "19571111")))))) (set 103 33 (((cons application 1) 105 19 ((visible-string 107 7 "Susan") (visible-string 114 3 "B") (visible-string 117 7 "Jones"))) ((cons context 0) 124 12 (((prim application 3) 126 10 ,(string->utf8 "19590717")))))))))))) (test-equal decoded (der:decode binary)) (test-equal binary (der:encode #f decoded)))) (test-end) (exit (if (zero? (test-runner-fail-count (test-runner-get))) 0 1))
false
41c708995a6f7ba14b558dda292c0696492afe25
e1c580145992634f089af18940508f5c26d2e264
/umcu/packages/datasets.scm
ed279c23c9e3c06def94860b49c9963aabb5236d
[]
no_license
inijman/guix-additions
8542592972e644a4ccd7b36ad4dd9b5631008fb5
b8e0e3f3b9598aade3103e9f491307fa06ece03d
refs/heads/master
2021-07-13T21:35:25.731179
2020-05-28T14:01:04
2020-05-28T14:01:04
142,980,977
0
0
null
2018-07-31T07:49:53
2018-07-31T07:49:53
null
UTF-8
Scheme
false
false
17,856
scm
datasets.scm
;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Roel Janssen <[email protected]> ;;; ;;; This file is not officially part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. (define-module (umcu packages datasets) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix packages) #:use-module (guix utils) #:use-module (guix download) #:use-module (guix build-system trivial) #:use-module (gnu packages) #:use-module (gnu packages base) #:use-module (gnu packages bioinformatics) #:use-module (gnu packages compression) #:use-module (gnu packages java) #:use-module (umcu packages igvtools)) (define-public clinvar (package (name "clinvar-vcf") (version "GRCh38") (source (origin (method url-fetch) (uri (string-append "ftp://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_" version "/clinvar.vcf.gz")) (sha256 (base32 "1ycavyj9s09gjv6cq550v9khyfn6rc1ni3alvx52fqx50kvl0ggv")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/clinvar/GRCh38"))) (mkdir-p output-dir) (copy-file source-file (string-append output-dir "/clinvar.vcf.gz")))))) (home-page "https://www.ncbi.nlm.nih.gov/clinvar/") (synopsis "Public archive of reports of human genetic variation") (description "ClinVar is a freely accessible, public archive of reports of the relationships among human variations and phenotypes, with supporting evidence. ClinVar thus facilitates access to and communication about the relationships asserted between human variation and observed health status, and the history of that interpretation. ClinVar processes submissions reporting variants found in patient samples, assertions made regarding their clinical significance, information about the submitter, and other supporting data. The alleles described in submissions are mapped to reference sequences, and reported according to the HGVS standard. ClinVar then presents the data for interactive users as well as those wishing to use ClinVar in daily workflows and other local applications. ClinVar works in collaboration with interested organizations to meet the needs of the medical genetics community as efficiently and effectively as possible.") (license #f))) (define-public clinvar-grch37 (package (inherit clinvar) (version "GRCh37-20180724") (source (origin (method url-fetch) (uri (string-append "ftp://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh37/clinvar.vcf.gz")) (sha256 (base32 "11gv8y8q50nvk86c7bs09bpi2ch6xn43hpcm0apk4kfkvs2k6iqr")))) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/clinvar/GRCh37"))) (mkdir-p output-dir) (copy-file source-file (string-append output-dir "/clinvar.vcf.gz")))))))) (define-public dbsnp (package (name "dbsnp") (version "human_9606") (source (origin (method url-fetch) (uri (string-append "ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606/" "VCF/00-All.vcf.gz")) (sha256 (base32 "0f2zzi0br0c1dvlx6wfgfm6f7rgp0kb19gb6p0kxzbs3n92viiqa")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let* ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/dbsnp")) (output-file (string-append output-dir "/dbSnp.vcf.gz"))) (mkdir-p output-dir) (copy-file source-file output-file) (symlink output-file (string-append output-dir "/00-All.vcf.gz")))))) (home-page "https://www.ncbi.nlm.nih.gov/projects/SNP/") (synopsis "Short genetic variations") (description "") (license #f))) (define-public 1000genomes-phase1-indels (package (name "1000genomes-phase1-indels") (version "b37") (source (origin (method url-fetch) (uri (string-append "ftp://" "gsapubftp-anonymous@" "ftp.broadinstitute.org/bundle/b37/" "1000G_phase1.indels.b37.vcf.gz")) (sha256 (base32 "173kkmyvyvfa55v2rbpywsrp7159yyl1sx30y243jkxzkjrgc7bc")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let* ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/1000G")) (output-file-uncompressed (string-append output-dir "/1000G_phase1.indels.b37.vcf")) (output-file (string-append output-file-uncompressed ".gz")) (java (string-append (assoc-ref %build-inputs "icedtea") "/bin/java")) (igvtools (string-append (assoc-ref %build-inputs "igvtools") "/share/java/igvtools/igvtools.jar")) (path (string-append (assoc-ref %build-inputs "htslib") "/bin:" (assoc-ref %build-inputs "gzip") "/bin"))) ;; The gunzip command needs to find gzip in PATH. (setenv "PATH" path) (mkdir-p output-dir) (copy-file source-file output-file) ;; To create the index, we need to compress the VCF file with ;; bgzip, instead of the regular gzip. (system* "gunzip" output-file) (system* "bgzip" output-file-uncompressed) ;; Finally, we can index the file using igvtools. (system* java "-jar" igvtools "index" output-file))))) (inputs `(("icedtea" ,icedtea-7) ("igvtools" ,igvtools-bin-2.3.71) ("htslib" ,htslib) ("gzip" ,gzip))) (home-page "http://www.internationalgenome.org/") (synopsis "Initial map of insertions and deletions in the human genome") (description "") (license #f))) (define-public mills-1000G-gold-standard-indels (package (name "1000genomes-mills-gold-standard-indels") (version "b37") (source (origin (method url-fetch) (uri (string-append "ftp://" "gsapubftp-anonymous@" "ftp.broadinstitute.org/bundle/b37/" "Mills_and_1000G_gold_standard.indels.b37.vcf.gz")) (sha256 (base32 "1n9bf6chfr9pxhk0mfiiqy28pmkyb0xpxz0rwvwrw031cw39dc1l")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let* ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/1000G")) (output-file-wo-ext (string-append output-dir "/Mills_and_1000G_gold_standard.indels.b37")) (bcf-output-file (string-append output-file-wo-ext ".bcf")) (output-file-uncompressed (string-append output-file-wo-ext ".vcf")) (output-file (string-append output-file-uncompressed ".gz")) (java (string-append (assoc-ref %build-inputs "icedtea") "/bin/java")) (igvtools (string-append (assoc-ref %build-inputs "igvtools") "/share/java/igvtools/igvtools.jar")) (path (string-append (assoc-ref %build-inputs "htslib") "/bin:" (assoc-ref %build-inputs "gzip") "/bin:" (assoc-ref %build-inputs "bcftools") "/bin:" (assoc-ref %build-inputs "grep") "/bin"))) ;; The gunzip command needs to find gzip in PATH. (setenv "PATH" path) (mkdir-p output-dir) (copy-file source-file output-file) ;; To create the index, we need to compress the VCF file with ;; bgzip, instead of the regular gzip. (system* "gunzip" output-file) (chmod output-file-uncompressed #o644) ;; The "vcf" file seems to be actually a "bcf" file. We can use bcftools to ;; convert it to a VCF file. (rename-file output-file-uncompressed bcf-output-file) (system (string-append "bcftools view " bcf-output-file " | grep -v bcftools_view > " output-file-uncompressed)) (system* "bgzip" output-file-uncompressed) (delete-file bcf-output-file) ;; Finally, we can index the file using igvtools. (system* java "-jar" igvtools "index" output-file))))) (inputs `(("icedtea" ,icedtea-7) ("igvtools" ,igvtools-bin-2.3.71) ("htslib" ,htslib) ("gzip" ,gzip) ("bcftools" ,bcftools) ("grep" ,grep))) (home-page "http://www.internationalgenome.org/") (synopsis "Initial map of insertions and deletions in the human genome") (description "") (license #f))) (define-public dbsnp-138 (package (name "dbsnp") (version "138-b37") (source (origin (method url-fetch) (uri (string-append "ftp://" "gsapubftp-anonymous@" "ftp.broadinstitute.org/bundle/b37/" "dbsnp_138.b37.vcf.gz")) (sha256 (base32 "0c7i6qw6j6chhqni826jr98b4kfjg72mql36wdfydiiv7679zx5n")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let* ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/1000G")) (output-file-uncompressed (string-append output-dir "/dbsnp_138.b37.vcf")) (output-file (string-append output-file-uncompressed ".gz")) (java (string-append (assoc-ref %build-inputs "icedtea") "/bin/java")) (igvtools (string-append (assoc-ref %build-inputs "igvtools") "/share/java/igvtools/igvtools.jar")) (path (string-append (assoc-ref %build-inputs "htslib") "/bin:" (assoc-ref %build-inputs "gzip") "/bin"))) ;; The gunzip command needs to find gzip in PATH. (setenv "PATH" path) (mkdir-p output-dir) (copy-file source-file output-file) ;; To create the index, we need to compress the VCF file with ;; bgzip, instead of the regular gzip. (system* "gunzip" output-file) (system* "bgzip" output-file-uncompressed) ;; Finally, we can index the file using igvtools. (system* java "-jar" igvtools "index" output-file))))) (inputs `(("icedtea" ,icedtea-7) ("igvtools" ,igvtools-bin-2.3.71) ("htslib" ,htslib) ("gzip" ,gzip))) (home-page "") (synopsis "") (description "") (license #f))) (define-public dx-tracks (package (name "dx-tracks") (version "1.2.1") (source (origin (method url-fetch) (uri (string-append "https://github.com/UMCUGenetics/Dx_tracks/releases/" "download/v" version "/v" version ".tar.gz")) (sha256 (base32 "0vcyd888yq6qqal5n9l5g361nzx3wq70zlbn9bhza2qkhfd3n5pp")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((tar (string-append (assoc-ref %build-inputs "tar") "/bin/tar")) (input-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/data/dx-tracks")) (PATH (string-append (assoc-ref %build-inputs "gzip") "/bin"))) (setenv "PATH" PATH) (mkdir-p output-dir) (with-directory-excursion output-dir (system* tar "-xvf" input-file "--strip-components=1")))))) (inputs `(("tar" ,tar) ("gzip" ,gzip))) (home-page "https://github.com/UMCUGenetics/Dx_tracks") (synopsis "") (description "") ;; The files are licensed CC-BY-ND. The NoDerivatives clause makes it ;; non-free, and therefore, the license cannot be added to Guix upstream. (license #f))) (define-public dbnsfp (package (name "dbnsfp") (version "2.9") (source (origin (method url-fetch) (uri (string-append "ftp://dbnsfp:[email protected]/dbNSFPv" version ".zip")) (sha256 (base32 "1bs2jpz8d2a9nkc72hhwynzavylr1srsbdrfmmcqpb4pgzqyzk24")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/dbnsfp")) (unzip (string-append (assoc-ref %build-inputs "unzip") "/bin/unzip")) (gzip (string-append (assoc-ref %build-inputs "gzip") "/bin/gzip"))) (mkdir-p output-dir) (with-directory-excursion output-dir (system* unzip source-file) (for-each (lambda (file) (format #t "Compressing ~s~%" file) (system* gzip file)) (find-files output-dir))))))) (inputs `(("unzip" ,unzip) ("gzip" ,gzip))) (home-page "https://sites.google.com/site/jpopgen/dbNSFP") (synopsis "Database for functional prediction of non-synonymous SNPs") (description " dbNSFP is a database developed for functional prediction and annotation of all potential non-synonymous single-nucleotide variants (nsSNVs) in the human genome.") (license #f))) (define-public giab-na12878-high-confidence-regions (package (name "giab-na12878-high-confidence-regions") (version "NISTv3.2.2") (source (origin (method url-fetch) (uri (string-append "ftp://ftp-trace.ncbi.nlm.nih.gov/giab/ftp/release/" "NA12878_HG001/" version "/NA12878_GIAB_highconf_IllFB" "-IllGATKHC-CG-Ion-Solid_ALLCHROM_v3.2.2_highconf.bed")) (sha256 (base32 "1adj878im498lfplklkir7v2chv1bxamgw3y2a62599wvbhap79q")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/giab"))) (mkdir-p output-dir) (copy-file source-file (string-append output-dir "/NA12878_GIAB_highconf_IllFB" "-IllGATKHC-CG-Ion-Solid_ALLCHROM_v3.2.2" "_highconf.bed")))))) (home-page "http://jimb.stanford.edu/giab") (synopsis "") (description "") (license #f))) (define-public gwascatalog (package (name "gwascatalog") (version "GRCh37") (source (origin (method url-fetch) (uri "http://www.genome.gov/admin/gwascatalog.txt") (sha256 (base32 "137xb3r3w6k8syj6dh6a856fvszcjlylwpzp98m35w5q52vxhdnx")))) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let ((source-file (assoc-ref %build-inputs "source")) (output-dir (string-append %output "/share/gwascatalog"))) (mkdir-p output-dir) (copy-file source-file (string-append output-dir "/gwascatalog.txt")))))) (home-page "http://www.genome.gov/") (synopsis "Extra data sets used by snpEff.") (description "This package contains extra data sets used by snpEff.") (license #f)))
false
9a195873d8966a765c258110816fb26b1535fb33
defeada37d39bca09ef76f66f38683754c0a6aa0
/UnityEngine.UI/unity-engine/ui/grid-layout-group.sls
091b7f5dccafa1d85db42fe6e699b2175aa2bbb2
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,551
sls
grid-layout-group.sls
(library (unity-engine ui grid-layout-group) (export is? grid-layout-group? calculate-layout-input-vertical calculate-layout-input-horizontal set-layout-vertical set-layout-horizontal start-corner-get start-corner-set! start-corner-update! start-axis-get start-axis-set! start-axis-update! cell-size-get cell-size-set! cell-size-update! spacing-get spacing-set! spacing-update! constraint-get constraint-set! constraint-update! constraint-count-get constraint-count-set! constraint-count-update!) (import (ironscheme-clr-port)) (define (is? a) (clr-is UnityEngine.UI.GridLayoutGroup a)) (define (grid-layout-group? a) (clr-is UnityEngine.UI.GridLayoutGroup a)) (define-method-port calculate-layout-input-vertical UnityEngine.UI.GridLayoutGroup CalculateLayoutInputVertical (System.Void)) (define-method-port calculate-layout-input-horizontal UnityEngine.UI.GridLayoutGroup CalculateLayoutInputHorizontal (System.Void)) (define-method-port set-layout-vertical UnityEngine.UI.GridLayoutGroup SetLayoutVertical (System.Void)) (define-method-port set-layout-horizontal UnityEngine.UI.GridLayoutGroup SetLayoutHorizontal (System.Void)) (define-field-port start-corner-get start-corner-set! start-corner-update! (property:) UnityEngine.UI.GridLayoutGroup startCorner UnityEngine.UI.GridLayoutGroup+Corner) (define-field-port start-axis-get start-axis-set! start-axis-update! (property:) UnityEngine.UI.GridLayoutGroup startAxis UnityEngine.UI.GridLayoutGroup+Axis) (define-field-port cell-size-get cell-size-set! cell-size-update! (property:) UnityEngine.UI.GridLayoutGroup cellSize UnityEngine.Vector2) (define-field-port spacing-get spacing-set! spacing-update! (property:) UnityEngine.UI.GridLayoutGroup spacing UnityEngine.Vector2) (define-field-port constraint-get constraint-set! constraint-update! (property:) UnityEngine.UI.GridLayoutGroup constraint UnityEngine.UI.GridLayoutGroup+Constraint) (define-field-port constraint-count-get constraint-count-set! constraint-count-update! (property:) UnityEngine.UI.GridLayoutGroup constraintCount System.Int32))
false
a684e22133e96f50ce0d53a382667c66d4970e1d
ebf028b3a35ae1544bba1a1f9aa635135486ee6c
/tests/lunula/gettext.scm
e22d3924cf3a2ef5721b08d2f0c2874d8563adf0
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
tabe/lunula
b4b666151874271211744cce1346e58e3a56fa79
b7699a850b9c9a64c1d3a52d50ce20050bd17475
refs/heads/master
2021-01-01T20:04:43.571993
2010-05-06T15:39:31
2010-05-06T15:39:31
334,916
2
0
null
null
null
null
UTF-8
Scheme
false
false
940
scm
gettext.scm
#!/usr/bin/env ypsilon #!r6rs (import (rnrs) (lunula gettext) (xunit)) (gettext (abc (en "abc") (ja "abc")) (hello-world (en "Hello, world.") (ja "こんにちは、世界。")) ) (assert-eq? 'en (locale)) (assert-string=? "abc" (__ abc)) (assert-string=? "abc" (___ 'abc)) (assert-string=? "Hello, world." (__ hello-world)) (assert-string=? "Hello, world." (___ 'hello-world)) (assert-string=? "foo" (__ foo)) (assert-string=? "foo" (___ 'foo)) (locale ja) (assert-eq? 'ja (locale)) (assert-string=? "abc" (__ abc)) (assert-string=? "abc" (___ 'abc)) (assert-string=? "こんにちは、世界。" (__ hello-world)) (assert-string=? "こんにちは、世界。" (___ 'hello-world)) (assert-string=? "foo" (__ foo)) (assert-string=? "foo" (___ 'foo)) (assert-equal? '(en "Hello, world.") (localize 'en (list (locale) (__ hello-world)))) (assert-equal? 'ja (locale)) (report)
false
df2d04bd4dd0ef29a05410bbabc05aaa0a02ecf5
18fb2e9f5ce1a5c876d9e0694ed001d8932b2fde
/examples/ttc-2015-fuml-activity-diagrams/parser.scm
1cbc1e07374a97669050618c142075fa67e0cc1e
[ "MIT", "X11" ]
permissive
christoff-buerger/racr
0669a0ba537c6b6d7e4379dbb453c42ff8456d25
b83e18d751bb11f844e8face7a81770819f1a3a9
refs/heads/master
2023-09-04T05:25:04.113295
2023-08-19T22:29:23
2023-08-19T22:29:23
32,183,687
33
10
null
2017-02-13T20:38:03
2015-03-13T22:19:59
Scheme
UTF-8
Scheme
false
false
9,035
scm
parser.scm
; This program and the accompanying materials are made available under the ; terms of the MIT license (X11 license) which accompanies this distribution. ; Author: C. Bürger #!r6rs (library (ttc-2015-fuml-activity-diagrams parser) (export parse-diagram parse-diagram-input) (import (rnrs) (ttc-2015-fuml-activity-diagrams language)) (define (parse-diagram file) ; Parse activity diagram of input file. Not thread save! (with-input-from-file file parse-activity)) (define (parse-diagram-input file) ; Parse list of variables of input file. (with-input-from-file file (lambda () (define (parse-input) (define name (parse-identifier)) (parse-keyword "=") (:Variable name #f (parse-constant))) (parse-list parse-input)))) (define p-char ; Return the next character if it satisfies optional constraints and exists. (lambda constraints (define current-char (peek-char)) (and (not (eof-object? current-char)) (for-all (lambda (f) (f current-char)) constraints) current-char))) (define r-char ; Similar to p-char but additionally increments the parsing position. (lambda constraints (unless (apply p-char constraints) (exception: "Parsing Error (unexpected character)")) (read-char))) (define (char= to-read) ; Construct character filter for p-char and r-char. (lambda (char-read) (char=? char-read to-read))) (define (consume-whitespace) ; Discard whitespace, also new line characters & one line comments. (when (p-char char-whitespace?) (r-char) (consume-whitespace)) (when (p-char (char= #\/)) (r-char) (r-char (char= #\/)) (let loop () (if (p-char (char= #\newline)) (r-char) (begin (r-char) (loop)))) (consume-whitespace))) (define (parse-boolean) ; Parse boolean constants (false/true). (cond ((p-char (char= #\f)) (parse-keyword "false") #f) (else (parse-keyword "true") #t))) (define (parse-integer) ; Read sequence of digits. (define num (let loop ((num (list (r-char char-numeric?)))) (let ((next-char? (p-char))) (if (and next-char? (char-numeric? next-char?)) (loop (cons (r-char) num)) (string->number (apply string (reverse num))))))) (consume-whitespace) num) (define (parse-identifier) ; Parse ordinary identifier, i.e., [a-zA-Z][_a-zA-Z0-9]*. (define id (let loop ((id (list (r-char char-alphabetic?)))) (let ((next-char? (p-char))) (if (and next-char? (or (char=? next-char? #\_) (char-alphabetic? next-char?) (char-numeric? next-char?))) (loop (cons (r-char) id)) (string->symbol (apply string (reverse id))))))) (consume-whitespace) id) (define (parse-constant) ; Parse integer and boolean constants. (if (p-char char-numeric?) (parse-integer) (parse-boolean))) (define (parse-keyword keyword) ; Parse given character sequence and consume trailing whitespace. (string-for-each (lambda (c) (r-char (char= c))) keyword) (consume-whitespace)) (define (parse-list f) ; Parse comma separated list of given parser combinator. (define elem (f)) (cond ((p-char (char= #\,)) (parse-keyword ",") (cons elem (parse-list f))) (else (list elem)))) (define in-table (make-eq-hashtable 3000)) ; Tracks consistency of in-edges between nodes & edges. (define out-table (make-eq-hashtable 3000)) ; Tracks consistency of out-edges. (define (parse-activity) (define name #f) (define Variable* (list)) (define ActivityNode* (list)) (define ActivityEdge* (list)) (hashtable-clear! in-table) (hashtable-clear! out-table) (consume-whitespace) (parse-keyword "activity") (set! name (parse-identifier)) (when (p-char (char= #\()) (parse-keyword "(") (unless (p-char (char= #\))) (set! Variable* (append Variable* (parse-list parse-input-variable)))) (parse-keyword ")")) (parse-keyword "{") (unless (p-char (char= #\n)) (set! Variable* (append Variable* (parse-list parse-local-variable)))) (parse-keyword "nodes") (parse-keyword "{") (unless (p-char (char= #\})) (set! ActivityNode* (parse-list parse-node))) (parse-keyword "}") (parse-keyword "edges") (parse-keyword "{") (unless (p-char (char= #\})) (set! ActivityEdge* (parse-list parse-edge))) (parse-keyword "}") (parse-keyword "}") (when (p-char) (exception: "Parsing Error (expected EOF; unexpected further characters)")) (let ((activity (:Activity name Variable* ActivityNode* ActivityEdge*))) (unless (and (for-all (lambda (n) (define in (hashtable-ref in-table (->name n) #f)) (define out (hashtable-ref out-table (->name n) #f)) (and in out (eq? (->target n) in) (eq? (->source n) out))) (=edges activity)) (for-all (lambda (k) (=e-lookup activity k)) (vector->list (hashtable-keys in-table))) (for-all (lambda (k) (=e-lookup activity k)) (vector->list (hashtable-keys out-table)))) (exception: "Parsing Error (inconsistent edges)")) activity)) (define (parse-input-variable) (define type (parse-type)) (:Variable (parse-identifier) type Undefined)) (define (parse-local-variable) (define type (parse-type)) (define name (parse-identifier)) (parse-keyword "=") (:Variable name type (parse-constant))) (define (parse-type) (cond ((p-char (char= #\b)) (parse-keyword "bool") Boolean) (else (parse-keyword "int") Integer))) (define (parse-node) (define name #f) (define expressions (list)) (define type (cond ((p-char (char= #\i)) (parse-keyword "initial") :InitialNode) ((p-char (char= #\f)) (r-char) (cond ((p-char (char= #\i)) (parse-keyword "inal") :FinalNode) (else (parse-keyword "ork") :ForkNode))) ((p-char (char= #\j)) (parse-keyword "join") :JoinNode) ((p-char (char= #\d)) (parse-keyword "decision") :DecisionNode) ((p-char (char= #\m)) (parse-keyword "merge") :MergeNode) ((p-char (char= #\a)) (parse-keyword "action") :ExecutableNode) (else (exception: "Parsing Error (unknown node type)")))) (set! name (parse-identifier)) (when (and (eq? type :ExecutableNode) (p-char (char= #\c))) (parse-keyword "comp") (parse-keyword "{") (set! expressions (parse-list parse-expression)) (parse-keyword "}")) (consume-edges name) (if (eq? type :ExecutableNode) (type name expressions) (type name))) (define (parse-expression) (define asignee (parse-identifier)) (parse-keyword "=") (if (p-char (char= #\!)) (begin (parse-keyword "!") (:UnaryExpression asignee not (parse-identifier))) (let* ((operand1 (parse-identifier)) (operator (parse-binary-operator))) (:BinaryExpression asignee operator operand1 (parse-identifier))))) (define (parse-binary-operator) (cond ((p-char (char= #\+)) (parse-keyword "+") +) ((p-char (char= #\-)) (parse-keyword "-") -) ((p-char (char= #\<)) (r-char) (if (p-char (char= #\=)) (begin (parse-keyword "=") <=) (begin (consume-whitespace) <))) ((p-char (char= #\=)) (parse-keyword "==") =) ((p-char (char= #\>)) (r-char) (if (p-char (char= #\=)) (begin (parse-keyword "=") >=) (begin (consume-whitespace) >))) ((p-char (char= #\&)) (parse-keyword "&") &&) ((p-char (char= #\|)) (parse-keyword "|") //))) (define (consume-edges node-name) (when (p-char (char= #\i)) (parse-keyword "in") (parse-keyword "(") (for-each (lambda (id) (when (hashtable-ref in-table id #f) (exception: "Parsing Error (inconsistent edges)")) (hashtable-set! in-table id node-name)) (parse-list parse-identifier)) (parse-keyword ")")) (when (p-char (char= #\o)) (parse-keyword "out") (parse-keyword "(") (for-each (lambda (id) (when (hashtable-ref out-table id #f) (exception: "Parsing Error (inconsistent edges)")) (hashtable-set! out-table id node-name)) (parse-list parse-identifier)) (parse-keyword ")"))) (define (parse-edge) (define name #f) (define source #f) (define target #f) (define guard #f) (parse-keyword "flow") (set! name (parse-identifier)) (parse-keyword "from") (set! source (parse-identifier)) (parse-keyword "to") (set! target (parse-identifier)) (when (p-char (char= #\[)) (parse-keyword "[") (set! guard (parse-identifier)) (parse-keyword "]")) (if guard (:ControlFlow name source target guard) (:ActivityEdge name source target))))
false
5a75d6d1a8b9b7a137c86dc2ae7aa90617e77d33
9b2eb10c34176f47f7f490a4ce8412b7dd42cce7
/lib-compat/vicare-r7b/i98.sls
496847c465a5a91bc7b097fe5d881b362a03b7dc
[ "LicenseRef-scancode-public-domain", "CC0-1.0" ]
permissive
okuoku/yuni
8be584a574c0597375f023c70b17a5a689fd6918
1859077a3c855f3a3912a71a5283e08488e76661
refs/heads/master
2023-07-21T11:30:14.824239
2023-06-11T13:16:01
2023-07-18T16:25:22
17,772,480
36
6
CC0-1.0
2020-03-29T08:16:00
2014-03-15T09:53:13
Scheme
UTF-8
Scheme
false
false
143
sls
i98.sls
(library (vicare-r7b i98) (export get-environment-variable get-environment-variables) (import (srfi :98)) )
false
215e56743016e10054e793d916e0265f10cd8384
2bcf33718a53f5a938fd82bd0d484a423ff308d3
/programming/sicp/ch1/ex-1.03.scm
b00bcf5d8187f96e7213432bf13ba13a76d248f6
[]
no_license
prurph/teach-yourself-cs
50e598a0c781d79ff294434db0430f7f2c12ff53
4ce98ebab5a905ea1808b8785949ecb52eee0736
refs/heads/main
2023-08-30T06:28:22.247659
2021-10-17T18:27:26
2021-10-17T18:27:26
345,412,092
0
0
null
null
null
null
UTF-8
Scheme
false
false
594
scm
ex-1.03.scm
;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-10.html#%_thm_1.3 ; Define a procedure that takes three numbers as arguments and returns the sum ; of the squares of the two larger numbers. (define (sum-square-largest-two x y z) (cond ((and (>= y x) (>= z x)) (+ (* y y) (* z z))) ((and (>= x y) (>= z y)) (+ (* x x) (* z z))) (else (+ (* x x) (* y y))))) (= 13 (sum-square-largest-two 1 2 3)) (= 2 (sum-square-largest-two 1 1 1)) (= 8 (sum-square-largest-two 1 2 2)) (= 5 (sum-square-largest-two 1 1 2)) (= 25 (sum-square-largest-two 1 4 3))
false
58cc857dab2fd8de945b89bd574144dc91ca07de
43612e5ed60c14068da312fd9d7081c1b2b7220d
/unit-tests/IFT3065/3/etape3-triangle.scm
422da9f4ea060ed8ae0d770217bd6bf53aed749a
[ "BSD-3-Clause" ]
permissive
bsaleil/lc
b1794065183b8f5fca018d3ece2dffabda6dd9a8
ee7867fd2bdbbe88924300e10b14ea717ee6434b
refs/heads/master
2021-03-19T09:44:18.905063
2019-05-11T01:36:38
2019-05-11T01:36:38
41,703,251
27
1
BSD-3-Clause
2018-08-29T19:13:33
2015-08-31T22:13:05
Scheme
UTF-8
Scheme
false
false
1,899
scm
etape3-triangle.scm
(define (list2vector lst) (list2vector-aux lst 0)) (define (list2vector-aux lst n) (if (pair? lst) (let ((v (list2vector-aux (cdr lst) (+ n 1)))) (vector-set! v n (car lst)) v) (make-vector n))) (define *board* (list2vector '(1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1))) (define *sequence* (list2vector '(0 0 0 0 0 0 0 0 0 0 0 0 0 0))) (define *a* (list2vector '(1 2 4 3 5 6 1 3 6 2 5 4 11 12 13 7 8 4 4 7 11 8 12 13 6 10 15 9 14 13 13 14 15 9 10 6 6))) (define *b* (list2vector '(2 4 7 5 8 9 3 6 10 5 9 8 12 13 14 8 9 5 2 4 7 5 8 9 3 6 10 5 9 8 12 13 14 8 9 5 5))) (define *c* (list2vector '(4 7 11 8 12 13 6 10 15 9 14 13 13 14 15 9 10 6 1 2 4 3 5 6 1 3 6 2 5 4 11 12 13 7 8 4 4))) (define *answer* '()) (define (attempt i depth) (cond ((= depth 14) ;;(set! *answer* (cons (cdr (vector->list *sequence*)) *answer*)) (set! *answer* (cons 999 *answer*)) #t) ((and (= 1 (vector-ref *board* (vector-ref *a* i))) (= 1 (vector-ref *board* (vector-ref *b* i))) (= 0 (vector-ref *board* (vector-ref *c* i)))) (vector-set! *board* (vector-ref *a* i) 0) (vector-set! *board* (vector-ref *b* i) 0) (vector-set! *board* (vector-ref *c* i) 1) (vector-set! *sequence* depth i) (search 0 (+ depth 1)) (vector-set! *board* (vector-ref *a* i) 1) (vector-set! *board* (vector-ref *b* i) 1) (vector-set! *board* (vector-ref *c* i) 0) #f) (else #f))) (define (search j depth) (if (or (= j 36) (attempt j depth)) #f (search (+ j 1) depth))) (define (test i depth) (set! *answer* '()) (attempt i depth) *answer*) (println (length (test 22 1))) ;775
false