forked from gambit/gambit
/
gambit#.scm
1103 lines (1078 loc) · 18.7 KB
/
gambit#.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;============================================================================
;;; File: "gambit#.scm", Time-stamp: <2008-09-27 22:40:33 feeley>
;;; Copyright (c) 2005-2008 by Marc Feeley, All Rights Reserved.
;;;============================================================================
;; Identifiers bound to syntactic forms and procedures defined by Gambit
;; are mapped to the empty namespace (no prefix).
(##include "~~/lib/r5rs#.scm") ;; most identifier bindings are inherited from R5RS
(##namespace ("" ;; these identifier bindings are specific to Gambit
;; special forms
define-record-type
define-structure
define-type
define-type-of-thread
c-define-type
c-declare
c-initialize
c-lambda
c-define
define-macro
;;define-syntax
include
declare
namespace
this-source-file
parameterize
receive
time
cond-expand
define-cond-expand-feature
six.!x
six.&x
six.*x
six.++x
six.+x
six.--x
six.-x
six.arrow
six.call
six.compound
six.cons
six.define-procedure
six.define-variable
six.do-while
six.dot
six.for
six.identifier
six.if
six.index
six.list
six.literal
six.new
six.null
six.prefix
six.procedure
six.procedure-body
six.while
six.x!=y
six.x%=y
six.x%y
six.x&&y
six.x&=y
six.x&y
six.x*=y
six.x*y
six.x++
six.x+=y
six.x+y
|six.x,y|
six.x--
six.x-=y
six.x-y
six.x/=y
six.x/y
six.x:=y
six.x:y
six.x<<=y
six.x<<y
six.x<=y
six.x<y
six.x==y
six.x=y
six.x>=y
six.x>>=y
six.x>>y
six.x>y
six.x?y:z
six.x^=y
six.x^y
|six.x\|=y|
|six.x\|\|y|
|six.x\|y|
six.~x
six.!
six.break
six.case
six.clause
six.continue
six.goto
six.label
six.return
six.switch
six.x:-y
;; procedures (TODO: check consistency with release, remove stuff in r5rs)
;; this code produces the list of procedures
#;
(let ()
(define (keep keep? lst)
(cond ((null? lst) '())
((keep? (car lst)) (cons (car lst) (keep keep? (cdr lst))))
(else (keep keep? (cdr lst)))))
(define (sort-list lst <?)
(define (mergesort lst)
(define (merge lst1 lst2)
(cond ((null? lst1) lst2)
((null? lst2) lst1)
(else
(let ((e1 (car lst1)) (e2 (car lst2)))
(if (<? e1 e2)
(cons e1 (merge (cdr lst1) lst2))
(cons e2 (merge lst1 (cdr lst2))))))))
(define (split lst)
(if (or (null? lst) (null? (cdr lst)))
lst
(cons (car lst) (split (cddr lst)))))
(if (or (null? lst) (null? (cdr lst)))
lst
(let* ((lst1 (mergesort (split lst)))
(lst2 (mergesort (split (cdr lst)))))
(merge lst1 lst2))))
(mergesort lst))
(define (symbol-table->list st)
(apply append
(map (lambda (s)
(let loop ((s s) (lst '()))
(if (symbol? s)
(loop (##vector-ref s 2) (cons s lst))
(reverse lst))))
(vector->list st))))
(define (public-procedure? s)
(if (let ((str (symbol->string s)))
(or (and (>= (string-length str) 2)
(equal? (substring str 0 2) "##"))
(and (>= (string-length str) 1)
(equal? (substring str 0 1) " "))))
#f
(let ((val (##global-var-ref (##make-global-var s))))
(procedure? val))))
(for-each
pp
(sort-list
(keep public-procedure?
(symbol-table->list (##symbol-table)))
(lambda (x y) (string<? (symbol->string x) (symbol->string y))))))
*
+
-
/
<
<=
=
>
>=
abandoned-mutex-exception?
abort
abs
acos
all-bits-set?
angle
any-bits-set?
append
apply
arithmetic-shift
asin
assoc
assq
assv
atan
bit-count
bit-set?
bitwise-and
bitwise-ior
bitwise-merge
bitwise-not
bitwise-xor
boolean?
box
box?
break
caaaar
caaadr
caaar
caadar
caaddr
caadr
caar
cadaar
cadadr
cadar
caddar
cadddr
caddr
cadr
call-with-current-continuation
call-with-input-file
call-with-input-string
call-with-input-u8vector
call-with-input-vector
call-with-output-file
call-with-output-string
call-with-output-u8vector
call-with-output-vector
call-with-values
call/cc
car
cdaaar
cdaadr
cdaar
cdadar
cdaddr
cdadr
cdar
cddaar
cddadr
cddar
cdddar
cddddr
cdddr
cddr
cdr
ceiling
cfun-conversion-exception-arguments
cfun-conversion-exception-code
cfun-conversion-exception-message
cfun-conversion-exception-procedure
cfun-conversion-exception?
char->integer
char-alphabetic?
char-ci<=?
char-ci<?
char-ci=?
char-ci>=?
char-ci>?
char-downcase
char-lower-case?
char-numeric?
char-ready?
char-upcase
char-upper-case?
char-whitespace?
char<=?
char<?
char=?
char>=?
char>?
char?
clear-bit-field
close-input-port
close-output-port
close-port
command-line
compile-file
compile-file-to-c
complex?
condition-variable-broadcast!
condition-variable-name
condition-variable-signal!
condition-variable-specific
condition-variable-specific-set!
condition-variable?
cons
console-port
continuation?
continuation-capture
continuation-graft
continuation-return
copy-bit-field
copy-file
cos
cpu-time
create-directory
create-fifo
create-link
create-symbolic-link
current-directory
current-error-port
current-exception-handler
current-input-port
current-output-port
current-readtable
current-thread
current-time
current-user-interrupt-handler
datum-parsing-exception-kind
datum-parsing-exception-parameters
datum-parsing-exception-readenv
datum-parsing-exception?
deadlock-exception?
default-random-source
defer-user-interrupts
delete-directory
delete-file
denominator
directory-files
display
display-continuation-backtrace
display-continuation-dynamic-environment
display-continuation-environment
display-environment-set!
display-exception
display-exception-in-context
display-procedure-environment
divide-by-zero-exception-arguments
divide-by-zero-exception-procedure
divide-by-zero-exception?
dynamic-wind
eof-object?
eq?
eq?-hash
equal?
equal?-hash
eqv?
eqv?-hash
err-code->string
error
error-exception-message
error-exception-parameters
error-exception?
eval
even?
exact->inexact
exact?
exit
exp
expression-parsing-exception-kind
expression-parsing-exception-parameters
expression-parsing-exception-source
expression-parsing-exception?
expt
extract-bit-field
f32vector
f32vector->list
f32vector-append
f32vector-copy
f32vector-fill!
f32vector-length
f32vector-ref
f32vector-set!
f32vector?
f64vector
f64vector->list
f64vector-append
f64vector-copy
f64vector-fill!
f64vector-length
f64vector-ref
f64vector-set!
f64vector?
file-attributes
file-creation-time
file-device
file-exists?
file-group
file-info
file-info-attributes
file-info-creation-time
file-info-device
file-info-group
file-info-inode
file-info-last-access-time
file-info-last-change-time
file-info-last-modification-time
file-info-mode
file-info-number-of-links
file-info-owner
file-info-size
file-info-type
file-info?
file-inode
file-last-access-time
file-last-change-time
file-last-modification-time
file-mode
file-number-of-links
file-owner
file-size
file-type
finite?
first-bit-set
fixnum->flonum
fixnum-overflow-exception-arguments
fixnum-overflow-exception-procedure
fixnum-overflow-exception?
fixnum?
fl*
fl+
fl-
fl/
fl<
fl<=
fl=
fl>
fl>=
flabs
flacos
flasin
flatan
flceiling
flcos
fldenominator
fleven?
flexp
flexpt
flfinite?
flfloor
flinfinite?
flinteger?
fllog
flmax
flmin
flnan?
flnegative?
flnumerator
flodd?
flonum?
floor
flpositive?
flround
flsin
flsqrt
fltan
fltruncate
flzero?
for-each
force
force-output
foreign-address
foreign-release!
foreign-released?
foreign-tags
foreign?
fx*
fx+
fx-
fx<
fx<=
fx=
fx>
fx>=
fxand
fxarithmetic-shift
fxarithmetic-shift-left
fxarithmetic-shift-right
fxbit-count
fxbit-set?
fxeven?
fxfirst-bit-set
fxif
fxior
fxlength
fxmax
fxmin
fxmodulo
fxnegative?
fxnot
fxodd?
fxpositive?
fxquotient
fxremainder
fxwrap*
fxwrap+
fxwrap-
fxwraparithmetic-shift
fxwraparithmetic-shift-left
fxwraplogical-shift-right
fxwrapquotient
fxxor
fxzero?
gc-report-set!
gcd
generate-proper-tail-calls
gensym
get-output-string
get-output-u8vector
get-output-vector
getenv
group-info
group-info-gid
group-info-members
group-info-name
group-info?
heap-overflow-exception?
host-info
host-info-addresses
host-info-aliases
host-info-name
host-info?
host-name
imag-part
improper-length-list-exception-arg-num
improper-length-list-exception-arguments
improper-length-list-exception-procedure
improper-length-list-exception?
inactive-thread-exception?
inactive-thread-exception-procedure
inactive-thread-exception-arguments
inexact->exact
inexact?
infinite?
initialized-thread-exception-arguments
initialized-thread-exception-procedure
initialized-thread-exception?
input-port-byte-position
input-port-bytes-buffered
input-port-char-position
input-port-characters-buffered
input-port-column
input-port-line
input-port-readtable
input-port-readtable-set!
input-port-timeout-set!
input-port?
integer->char
integer-length
integer-nth-root
integer-sqrt
integer?
interaction-environment
invalid-hash-number-exception-arguments
invalid-hash-number-exception-procedure
invalid-hash-number-exception?
join-timeout-exception-arguments
join-timeout-exception-procedure
join-timeout-exception?
keyword->string
keyword-expected-exception-arguments
keyword-expected-exception-procedure
keyword-expected-exception?
keyword-hash
keyword?
lcm
length
link-flat
link-incremental
list
list->f32vector
list->f64vector
list->s16vector
list->s32vector
list->s64vector
list->s8vector
list->string
list->table
list->u16vector
list->u32vector
list->u64vector
list->u8vector
list->vector
list-ref
list-tail
list?
load
log
magnitude
mailbox-receive-timeout-exception-arguments
mailbox-receive-timeout-exception-procedure
mailbox-receive-timeout-exception?
main
make-condition-variable
make-f32vector
make-f64vector
make-mutex
make-parameter
make-polar
make-random-source
make-rectangular
make-root-thread
make-s16vector
make-s32vector
make-s64vector
make-s8vector
make-string
make-table
make-thread
make-thread-group
make-u16vector
make-u32vector
make-u64vector
make-u8vector
make-uninterned-keyword
make-uninterned-symbol
make-vector
make-will
map
max
member
memq
memv
min
modulo
multiple-c-return-exception?
mutex-lock!
mutex-name
mutex-specific
mutex-specific-set!
mutex-state
mutex-unlock!
mutex?
nan?
negative?
network-info
network-info-aliases
network-info-name
network-info-net
network-info?
newline
no-such-file-or-directory-exception-arguments
no-such-file-or-directory-exception-procedure
no-such-file-or-directory-exception?
noncontinuable-exception-reason
noncontinuable-exception?
nonempty-input-port-character-buffer-exception-arguments
nonempty-input-port-character-buffer-exception-procedure
nonempty-input-port-character-buffer-exception?
nonprocedure-operator-exception-arguments
nonprocedure-operator-exception-code
nonprocedure-operator-exception-operator
nonprocedure-operator-exception-rte
nonprocedure-operator-exception?
not
null-environment
null?
number->string
number-of-arguments-limit-exception-arguments
number-of-arguments-limit-exception-procedure
number-of-arguments-limit-exception?
number?
numerator
object->serial-number
object->string
object->u8vector
odd?
open-directory
open-dummy
open-event-queue
open-file
open-input-file
open-input-string
open-input-u8vector
open-input-vector
open-output-file
open-output-string
open-output-u8vector
open-output-vector
open-process
open-string
open-string-pipe
open-tcp-client
open-tcp-server
open-u8vector
open-u8vector-pipe
open-vector
open-vector-pipe
os-exception-arguments
os-exception-code
os-exception-message
os-exception-procedure
os-exception?
output-port-byte-position
output-port-char-position
output-port-column
output-port-line
output-port-readtable
output-port-readtable-set!
output-port-timeout-set!
output-port-width
output-port?
pair?
path-directory
path-expand
path-extension
path-normalize
path-strip-directory
path-strip-extension
path-strip-trailing-directory-separator
path-strip-volume
path-volume
peek-char
port-settings-set!
port?
positive?
pp
pretty-print
primordial-exception-handler
print
println
procedure?
process-pid
process-status
process-times
protocol-info
protocol-info-aliases
protocol-info-name
protocol-info-number
protocol-info?
quotient
raise
random-integer
random-real
random-source-make-integers
random-source-make-reals
random-source-pseudo-randomize!
random-source-randomize!
random-source-state-ref
random-source-state-set!
random-source?
range-exception-arg-num
range-exception-arguments
range-exception-procedure
range-exception?
rational?
rationalize
read
read-all
read-char
read-line
read-substring
read-subu8vector
read-u8
readtable-case-conversion?
readtable-case-conversion?-set
readtable-eval-allowed?
readtable-eval-allowed?-set
readtable-keywords-allowed?
readtable-keywords-allowed?-set
readtable-max-unescaped-char
readtable-max-unescaped-char-set
readtable-max-write-length
readtable-max-write-length-set
readtable-max-write-level
readtable-max-write-level-set
readtable-sharing-allowed?
readtable-sharing-allowed?-set
readtable-start-syntax
readtable-start-syntax-set
readtable-write-cdr-read-macros?
readtable-write-cdr-read-macros?-set
readtable-write-extended-read-macros?
readtable-write-extended-read-macros?-set
readtable?
real-part
real-time
real?
remainder
rename-file
repl-backtrace-display-environment?
repl-display-dynamic-environment?
repl-input-port
repl-output-port
repl-result-history-max-length-set!
repl-result-history-ref
replace-bit-field
reverse
round
s16vector
s16vector->list
s16vector-append
s16vector-copy
s16vector-fill!
s16vector-length
s16vector-ref
s16vector-set!
s16vector?
s32vector
s32vector->list
s32vector-append
s32vector-copy
s32vector-fill!
s32vector-length
s32vector-ref
s32vector-set!
s32vector?
s64vector
s64vector->list
s64vector-append
s64vector-copy
s64vector-fill!
s64vector-length
s64vector-ref
s64vector-set!
s64vector?
s8vector
s8vector->list
s8vector-append
s8vector-copy
s8vector-fill!
s8vector-length
s8vector-ref
s8vector-set!
s8vector?
scheduler-exception-reason
scheduler-exception?
scheme-report-environment
seconds->time
serial-number->object
service-info
service-info-aliases
service-info-name
service-info-port
service-info-protocol
service-info?
set-box!
set-car!
set-cdr!
setenv
sfun-conversion-exception-arguments
sfun-conversion-exception-code
sfun-conversion-exception-message
sfun-conversion-exception-procedure
sfun-conversion-exception?
shell-command
shell-command-blocking
sin
six.make-array
socket-info-address
socket-info-family
socket-info-port-number
socket-info?
sqrt
stack-overflow-exception?
started-thread-exception-arguments
started-thread-exception-procedure
started-thread-exception?
step
step-level-set!
string
string->keyword
string->list
string->number
string->symbol
string-append
string-ci<=?
string-ci<?
string-ci=?
string-ci=?-hash
string-ci>=?
string-ci>?
string-copy
string-fill!
string-length
string-ref
string-set!
string<=?
string<?
string=?
string=?-hash
string>=?
string>?
string?
subf32vector
subf64vector
subs16vector
subs32vector
subs64vector
subs8vector
substring
subu16vector
subu32vector
subu64vector
subu8vector
subvector
symbol->string
symbol-hash
symbol?
system-stamp
system-type
system-type-string
system-version
system-version-string
table->list
table-copy
table-for-each
table-length
table-merge
table-merge!
table-ref
table-search
table-set!
table?
tan
tcp-client-peer-socket-info
tcp-client-self-socket-info
tcp-server-socket-info
tcp-service-register!
tcp-service-unregister!
terminated-thread-exception-arguments
terminated-thread-exception-procedure
terminated-thread-exception?
test-bit-field?
thread-base-priority
thread-base-priority-set!
thread-group->thread-group-list
thread-group->thread-group-vector
thread-group->thread-list
thread-group->thread-vector
thread-group-name
thread-group-parent
thread-group-resume!
thread-group-suspend!
thread-group-terminate!
thread-group?
thread-init!
thread-interrupt!
thread-join!
thread-mailbox-extract-and-rewind
thread-mailbox-next
thread-mailbox-rewind
thread-name
thread-priority-boost
thread-priority-boost-set!
thread-quantum
thread-quantum-set!
thread-receive
thread-resume!
thread-send
thread-sleep!
thread-specific
thread-specific-set!
thread-start!
thread-state
thread-state-abnormally-terminated-reason
thread-state-abnormally-terminated?
thread-state-active-timeout
thread-state-active-waiting-for
thread-state-active?
thread-state-initialized?
thread-state-normally-terminated-result
thread-state-normally-terminated?
thread-state-uninitialized?
thread-suspend!
thread-terminate!
thread-thread-group
thread-yield!
thread?
time->seconds
time?
timeout->time
top
touch
trace
transcript-off
transcript-on
truncate
tty-history
tty-history-max-length-set!
tty-history-set!
tty-mode-set!
tty-paren-balance-duration-set!
tty-text-attributes-set!
tty-type-set!
tty?
type-exception-arg-num
type-exception-arguments
type-exception-procedure
type-exception-type-id
type-exception?
u16vector
u16vector->list
u16vector-append
u16vector-copy
u16vector-fill!
u16vector-length
u16vector-ref
u16vector-set!
u16vector?
u32vector
u32vector->list
u32vector-append