-
Notifications
You must be signed in to change notification settings - Fork 7
/
write.scm
694 lines (642 loc) · 22.2 KB
/
write.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
(provide 'write.scm)
;;; -------------------------------- pretty-print --------------------------------
(define pretty-print
(let ((*pretty-print-length* 100)
(*pretty-print-spacing* 2)
(*pretty-print-float-format* "~,4F")
(*pretty-print-left-margin* 0)
(any? (lambda (f sequence) ; this and every? ought to be built-in!
(call-with-exit
(lambda (return)
(for-each (lambda (arg) (if (not (f arg)) (return #f))) sequence)
#t)))))
(define pretty-print-1
(let ((newlines 0))
(define (spaces port n)
(set! newlines (+ newlines 1))
(format port "~%~NC" (+ n *pretty-print-left-margin*) #\space))
(define (stacked-list port lst col)
(do ((p lst (cdr p))
(added 0 0))
((not (pair? p)))
(let ((obj (car p)))
(if (not (eq? p lst))
(spaces port col))
(let ((len (length (object->string obj))))
(if (and (keyword? obj)
(pair? (cdr p)))
(begin
(write obj port)
(write-char #\space port)
(set! added (+ 1 len))
(set! p (cdr p))
(set! obj (car p)))) ; pair? cdr p above
(cond ((or (hash-table? obj)
(let? obj))
(pretty-print-1 obj port col))
((and (pair? obj)
(pair? (cdr obj))
(null? (cddr obj))
(> len (/ *pretty-print-length* 2)))
(if (eq? (car obj) 'quote)
(write-char #\' port)
(begin
(write-char #\( port)
(pretty-print-1 (car obj) port col)
(spaces port (+ col 1))))
(pretty-print-1 (cadr obj) port (+ col 1))
(if (not (eq? (car obj) 'quote))
(write-char #\) port)))
(else
(pretty-print-1 obj port (+ col added))))))))
(define (stacked-split-list port lst col)
(if (not (pair? lst))
(write lst port)
(do ((p lst (cdr p)))
((not (pair? p)))
(if (not (eq? p lst)) (spaces port col))
(if (pair? (car p))
(begin
(format port "(~S " (caar p))
(if (and (pair? (cdar p))
(symbol? (caar p)))
(pretty-print-1 (cadar p) port (+ col (length (symbol->string (caar p))) 2))
(write (cdar p) port))
(write-char #\) port))
(write (car p) port))))) ; pretty-print? (it's always a symbol)
(define (messy-number z)
(if (real? z)
(if (or (nan? z)
(infinite? z))
(object->string z)
(if (= z pi)
(copy "pi")
(format #f *pretty-print-float-format* z)))
(format #f "~A~A~Ai"
(messy-number (real-part z))
(if (negative? (imag-part z)) "-" "+")
(messy-number (abs (imag-part z))))))
(define (any-keyword? lst)
(and (pair? lst)
(or (keyword? (car lst))
(any-keyword? (cdr lst)))))
(let ((writers
(let ((h (make-hash-table)))
;; -------- quote
(define (w-quote obj port column)
(if (not (pair? (cdr obj))) ; (quote) or (quote . 1)
(write obj port)
(begin
(write-char #\' port)
(pretty-print-1 (cadr obj) port column))))
(hash-table-set! h 'quote w-quote)
;; -------- define
(define (w-define obj port column)
(if (not (pair? (cdr obj)))
(write obj port)
(begin
(format port "(~A ~A " (car obj) (cadr obj))
(if (pair? (cadr obj))
(begin
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cddr obj) (+ column *pretty-print-spacing*)))
(if (pair? (cddr obj))
(let ((str (object->string (caddr obj))))
(if (> (length str) 60)
(begin
(spaces port (+ column *pretty-print-spacing*))
(pretty-print-1 (caddr obj) port (+ column *pretty-print-spacing*)))
(write (caddr obj) port)))
(write (cddr obj) port)))
(write-char #\) port))))
(hash-table-set! h 'define w-define)
;; -------- if
(define (w-if obj port column)
(let ((objstr (object->string obj))
(ifcol (+ column 4)))
(if (< (length objstr) 40)
(display objstr port)
(begin
(format port "(if ")
(pretty-print-1 (cadr obj) port ifcol)
(when (pair? (cddr obj)) ; might be a messed-up if
(spaces port ifcol)
(pretty-print-1 (caddr obj) port ifcol)
(when (pair? (cdddr obj))
(spaces port ifcol)
(pretty-print-1 (cadddr obj) port ifcol)))
(write-char #\) port)))))
(hash-table-set! h 'if w-if)
;; -------- when unless
(define (w-when obj port column)
(let ((objstr (object->string obj)))
(if (< (length objstr) 40)
(display objstr port)
(begin
(format port "(~A " (car obj))
(pretty-print-1 (cadr obj) port (+ column (if (eq? (car obj) 'when) 6 8)))
(spaces port (+ column *pretty-print-spacing*))
(when (pair? (cddr obj))
(stacked-list port (cddr obj) (+ column *pretty-print-spacing*)))
(write-char #\) port)))))
(hash-table-set! h 'when w-when)
(hash-table-set! h 'unless w-when)
;; -------- let let* letrec letrec*
(define (w-let obj port column)
(if (not (and (pair? (cdr obj))
(pair? (cddr obj))))
(write obj port)
(begin
(let ((head-len (length (symbol->string (car obj)))))
(if (symbol? (cadr obj))
(begin
(format port "(~A ~A (" (car obj) (cadr obj))
(if (pair? (cddr obj))
(if (pair? (caddr obj)) ; (let x () ...)
(stacked-split-list port (caddr obj) (+ column head-len (length (symbol->string (cadr obj))) 4))
(if (not (null? (caddr obj)))
(write (caddr obj) port))) ; () is already being written
(if (not (null? (cddr obj)))
(format port " . ~S" (cddr obj)))))
(begin
(format port "(~A (" (car obj))
(if (pair? (cadr obj))
(stacked-split-list port (cadr obj) (+ column head-len 3))))))
(write-char #\) port)
(spaces port (+ column *pretty-print-spacing*))
(if (pair? ((if (symbol? (cadr obj)) cdddr cddr) obj))
(stacked-list port ((if (symbol? (cadr obj)) cdddr cddr) obj) (+ column *pretty-print-spacing*)))
(write-char #\) port))))
(for-each
(lambda (f)
(hash-table-set! h f w-let))
'(let let* letrec letrec*))
;; -------- set!
(define (w-set obj port column)
(let ((str (object->string obj)))
(if (<= (length str) 60)
(display str port)
(let ((settee (object->string (cadr obj))))
(format port "(set! ~A" settee)
(if (pair? (cddr obj))
(if (> (length settee) 20)
(begin
(spaces port (+ column 6))
(pretty-print-1 (caddr obj) port (+ column 6)))
(begin
(write-char #\space port)
(pretty-print-1 (caddr obj) port (+ column 7 (length settee))))))
(write-char #\) port)))))
(hash-table-set! h 'set! w-set)
;; -------- cond
(define (w-cond obj port column)
(format port "(cond ")
(do ((lst (cdr obj) (cdr lst)))
((not (pair? lst)))
(if (not (eq? lst (cdr obj)))
(spaces port (+ column 6)))
(if (not (pair? (car lst)))
(write (car lst) port)
(let ((has=> (and (pair? (cdar lst))
(eq? (cadar lst) '=>))))
(let ((extras (and (pair? (cdar lst))
(pair? (cddar lst))
(or (not has=>)
(pair? (cdddar lst)))))
(too-long (> (length (object->string (cdar lst))) 50)))
(write-char #\( port)
(let ((oldlines newlines))
(pretty-print-1 (caar lst) port (+ column 7))
(if (or extras
(not (= oldlines newlines))
too-long)
(spaces port (+ column 7))
(if (and (pair? (cdar lst))
(or (not has=>)
(= oldlines newlines)))
(write-char #\space port)))
(if (and (pair? (cdar lst))
(not extras)
(not too-long))
(begin
(write (cadar lst) port)
(when (and has=>
(pair? (cddar lst)))
(write-char #\space port)
(write (caddar lst) port)))
(if (not (null? (cdar lst)))
(stacked-list port (cdar lst) (+ column 7)))))
(write-char #\) port)))))
(write-char #\) port))
(hash-table-set! h 'cond w-cond)
;; -------- and or
(define (w-and obj port column)
(if (> (length (object->string obj)) 40)
(begin
(format port "(~A " (car obj))
(stacked-list port (cdr obj) (+ column *pretty-print-spacing* (length (symbol->string (car obj)))))
(write-char #\) port))
(write obj port)))
(hash-table-set! h 'and w-and)
(hash-table-set! h 'or w-and)
;; -------- case
(define (w-case obj port column)
(if (not (and (pair? (cdr obj))
(pair? (cddr obj))))
(write obj port)
(begin
(format port "(case ~A" (cadr obj)) ; send out the selector
(for-each
(lambda (lst)
(spaces port (+ column *pretty-print-spacing*))
(if (not (pair? lst))
(write lst port)
(begin
(write-char #\( port)
(if (not (pair? (car lst)))
(write (car lst) port)
(let ((len (length (car lst))))
(if (< len 6)
(write (car lst) port)
(let ((p (car lst)))
(write-char #\( port)
(do ((i 0 (+ i 6)))
((>= i len))
(do ((j 0 (+ j 1)))
((or (= j 6) (null? p)) (if (pair? p) (spaces port (+ column 4))))
(write (car p) port)
(set! p (cdr p))
(if (pair? p)
(write-char #\space port))))
(write-char #\) port)))))
(if (not (null? (cdr lst)))
(if (and (pair? (cdr lst))
(or (and (null? (cddr lst))
(< (length (object->string (cadr lst))) 60))
(and (eq? (cadr lst) '=>)
(null? (cdddr lst))
(< (length (object->string (caddr lst))) 60))))
(begin
(write-char #\space port)
(write (cadr lst) port)
(if (and (eq? (cadr lst) '=>)
(pair? (cddr lst)))
(begin
(write-char #\space port)
(write (caddr lst) port))))
(begin
(spaces port (+ column 3))
(stacked-list port (cdr lst) (+ column 3)))))
(write-char #\) port))))
(cddr obj))
(write-char #\) port))))
(hash-table-set! h 'case w-case)
;; -------- map for-each
(define (w-map obj port column)
(let* ((objstr (object->string obj))
(strlen (length objstr)))
(if (< (+ column strlen) *pretty-print-length*)
(display objstr port)
(begin
(format port "(~A" (car obj))
(if (pair? (cdr obj))
(begin
(write-char #\space port)
(stacked-list port (cdr obj) (+ column *pretty-print-spacing*))))
(write-char #\) port)))))
(hash-table-set! h 'map w-map)
(hash-table-set! h 'for-each w-map)
;; -------- do
(define (w-do obj port column)
(if (not (pair? (cdr obj)))
(write obj port)
(begin
(format port "(do ")
(if (list? (cadr obj))
(write-char #\( port)
(display (cadr obj) port))
(if (pair? (cadr obj))
(stacked-list port (cadr obj) (+ column 5)))
(if (list? (cadr obj))
(write-char #\) port))
(when (pair? (cddr obj))
(spaces port (+ column 4))
(let ((end (caddr obj)))
(if (< (length (object->string end)) (- *pretty-print-length* column))
(write end port)
(begin
(write-char #\( port)
(pretty-print-1 (car end) port (+ column 4))
(spaces port (+ column 5))
(stacked-list port (cdr end) (+ column 5))
(write-char #\) port))))
(when (pair? (cdddr obj))
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cdddr obj) (+ column *pretty-print-spacing*))))
(write-char #\) port))))
(hash-table-set! h 'do w-do)
;; -------- begin etc
(define (w-begin obj port column)
(format port "(~A" (car obj))
(if (pair? (cdr obj))
(begin
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cdr obj) (+ column *pretty-print-spacing*))))
(write-char #\) port))
(for-each
(lambda (f)
(hash-table-set! h f w-begin))
'(begin call-with-exit call/cc call-with-current-continuation
with-baffle with-output-to-string call-with-output-string hash-table inlet))
;; -------- dynamic-wind call-with-values
(define (w-dynwind obj port column)
(format port "(~A" (car obj))
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cdr obj) (+ column *pretty-print-spacing*))
(write-char #\) port))
(hash-table-set! h 'dynamic-wind w-dynwind)
(hash-table-set! h 'call-with-values w-dynwind)
;; -------- lambda etc
(define (w-lambda obj port column)
(if (not (and (pair? (cdr obj))
(pair? (cddr obj))))
(write obj port)
(begin
(format port "(~A " (car obj)); (cadr obj))
(pretty-print-1 (cadr obj) port (+ column *pretty-print-spacing* (length (symbol->string (car obj)))))
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cddr obj) (+ column *pretty-print-spacing*))
(write-char #\) port))))
(for-each
(lambda (f)
(hash-table-set! h f w-lambda))
'(lambda lambda* define* define-macro define-macro* define-bacro define-bacro* with-let
call-with-input-string call-with-input-file call-with-output-file
with-input-from-file with-input-from-string with-output-to-file))
;; -------- defmacro defmacro*
(define (w-defmacro obj port column)
(if (not (and (pair? (cdr obj))
(pair? (cddr obj))))
(write obj port)
(begin
(format port "(~A ~A ~A" (car obj) (cadr obj) (caddr obj))
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cdddr obj) (+ column *pretty-print-spacing*))
(write-char #\) port))))
(hash-table-set! h 'defmacro w-defmacro)
(hash-table-set! h 'defmacro* w-defmacro)
;; -------- catch
(define (w-catch obj port column)
(if (not (pair? (cdr obj))) ; (catch) or (catch . 1)
(write obj port)
(begin
(format port "(~A ~S" catch (cadr obj))
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cddr obj) (+ column *pretty-print-spacing*))
(write-char #\) port))))
(hash-table-set! h 'catch w-catch)
h)))
;; pretty-print-1
(lambda (obj port column)
(cond ((number? obj)
(if (rational? obj)
(write obj port)
(display (messy-number obj) port)))
((hash-table? obj)
(display "(hash-table" port)
(for-each (lambda (field)
(let ((symstr (object->string (car field))))
(spaces port (+ column 2))
(format port "'(~A . " symstr)
(pretty-print-1 (cdr field) port (+ column 4 (length symstr)))
(write-char #\) port)))
obj)
(write-char #\) port))
((let? obj)
(if (and (openlet? obj)
(defined? 'pretty-print obj))
((obj 'pretty-print) obj port column)
(begin
(display "(inlet" port)
(for-each (lambda (field)
(let ((symstr (symbol->string (car field))))
(spaces port (+ column 2))
(format port ":~A " symstr)
(pretty-print-1 (cdr field) port (+ column 2 (length symstr)))))
obj)
(write-char #\) port))))
((or (int-vector? obj)
(float-vector? obj))
(let* ((objstr (object->string obj))
(strlen (length objstr)))
(if (< (+ column strlen) *pretty-print-length*)
(display objstr port)
(let ((name-len (if (int-vector? obj) 10 12)))
(display (if (int-vector? obj) "(int-vector " "(float-vector ") port)
(set! column (+ column 2))
(if (< (- *pretty-print-length* column) 30)
(spaces port column)
(set! column (+ column name-len)))
(do ((len (min (length obj) (*s7* 'print-length)))
(col column)
(i 0 (+ i 1)))
((= i len)
(if (> len (*s7* 'print-length))
(write-string " ...)" port)
(write-char #\) port)))
(let* ((numstr (number->string (obj i)))
(numlen (length numstr)))
(if (not (= col column))
(if (> (+ col numlen) *pretty-print-length*)
(begin
(spaces port column)
(set! col column))
(display #\space port)))
(display numstr port)
(set! col (+ col numlen 1))))))))
((vector? obj)
(let* ((objstr (object->string obj))
(strlen (length objstr)))
(if (< (+ column strlen) *pretty-print-length*)
(display objstr port)
(begin
(display "(vector " port)
(set! column (+ column 2))
(if (< (- *pretty-print-length* column) 30)
(spaces port column)
(set! column (+ column 6)))
(do ((len (min (length obj) (*s7* 'print-length)))
(col column)
(i 0 (+ i 1)))
((= i len)
(if (> len (*s7* 'print-length))
(write-string " ...)" port)
(write-char #\) port)))
(let* ((ostr (object->string (obj i)))
(olen (length ostr)))
(if (not (= col column))
(if (> (+ col olen) *pretty-print-length*)
(begin
(spaces port column)
(set! col column))
(display #\space port)))
(pretty-print-1 (obj i) port col)
(set! col (+ col olen 1))))))))
((not (pair? obj))
(write obj port))
((hash-table-ref writers (car obj)) => (lambda (f)
(f obj port column)))
((any? (lambda (p)
(or (hash-table? p)
(let? p)))
obj)
(let ((first #t))
(write-char #\( port)
(for-each (lambda (p)
(if first (set! first #f) (spaces port (+ column 4)))
(pretty-print-1 p port (+ column 4)))
obj)
(write-char #\) port)))
(else
(let* ((objstr (object->string obj))
(strlen (length objstr)))
(if (< (+ column strlen) *pretty-print-length*)
(display objstr port)
(let ((lstlen (length obj)))
(cond ((or (infinite? lstlen)
(not (positive? lstlen)))
(display objstr port))
((and (symbol? (car obj))
(> (length (symbol->string (car obj))) 12)
(pair? (cdr obj))
(pair? (cadr obj))
(memq (caadr obj) '(lambda lambda* let let* cond case letrec)))
(write-char #\( port)
(pretty-print-1 (car obj) port column)
(spaces port (+ column 2))
(stacked-list port (cdr obj) (+ column 2))
(write-char #\) port))
((= lstlen 1)
(if (pair? (car obj))
(begin
(write-char #\( port)
(pretty-print-1 (car obj) port (+ column 1))
(write-char #\) port))
(display objstr port)))
((and (pair? (car obj))
(memq (caar obj) '(lambda lambda* let let* letrec letrec* cond if case)))
(write-char #\( port)
(pretty-print-1 (car obj) port column)
(spaces port (+ column 1))
(if (and (memq (caar obj) '(cond if case))
(do ((p (cdr obj) (cdr p)))
((or (null? p)
(pair? (car p)))
(null? p))))
(do ((p (cdr obj) (cdr p)))
((null? p))
(display (car p) port)
(if (pair? (cdr p))
(write-char #\space port)))
(stacked-list port (cdr obj) (+ column 1)))
(write-char #\) port))
(else
(let* ((carstr (object->string (car obj)))
(carstrlen (length carstr)))
(if (eq? (car obj) 'quote)
(write-char #\' port)
(format port "(~A" carstr))
(if (any-keyword? (cdr obj))
(begin
(spaces port (+ column *pretty-print-spacing*))
(stacked-list port (cdr obj) (+ column *pretty-print-spacing*)))
(let ((line-start (+ column *pretty-print-spacing*
(if (> carstrlen 16) 0 carstrlen))))
(case lstlen
((2)
(write-char #\space port)
(pretty-print-1 (cadr obj) port line-start))
((3)
(write-char #\space port)
(stacked-list port (cdr obj) line-start))
(else
(do ((obj-start line-start)
(lst (cdr obj) (cdr lst)))
((null? lst))
(let* ((str (object->string (car lst)))
(strlen1 (length str)))
(if (and (> strlen1 (- *pretty-print-length* obj-start))
(not (eq? lst (cdr obj))))
(begin
(set! obj-start (+ line-start 1 strlen1))
(spaces port line-start)
(pretty-print-1 (car lst) port line-start))
(let ((at-line-start (= line-start obj-start)))
(set! obj-start (+ obj-start 1 strlen1))
(if (> strlen1 40)
(begin
(if at-line-start
(write-char #\space port)
(spaces port line-start))
(pretty-print-1 (car lst) port line-start))
(begin
(write-char #\space port)
(display str port)))))))))))
(if (not (eq? (car obj) 'quote))
(write-char #\) port))))))))))))))
;; pretty-print
(lambda* (obj (port (current-output-port)) (column 0))
(let ((old-port port))
(if (boolean? old-port)
(set! port (open-output-string)))
(pretty-print-1 obj port column)
(flush-output-port port)
(if (not (boolean? old-port))
(values)
(let ((str (get-output-string port)))
(close-output-port port)
(if (eq? old-port #t)
(display str))
str))))))
(define (pp obj)
(call-with-output-string
(lambda (p)
(if (keyword? obj)
(symbol->string obj)
(pretty-print obj p)))))
#|
(define (pretty-print-all)
(let ((st (symbol-table)))
(for-each
(lambda (sym)
(if (defined? sym)
(let ((val (symbol->value sym)))
(let ((source (and (procedure? val)
(procedure-source val))))
(if (pair? source)
(format *stderr* "~<sym~> ~<val~>:~%~<(pp source)~>~%~%"))))))
st)))
(define-macro (fully-macroexpand form)
(define (expand form)
;; walk form looking for macros, expand any that are found -- see stuff.scm for a newer version
(if (pair? form)
(if (and (symbol? (car form))
(macro? (symbol->value (car form))))
(expand ((eval (procedure-source (symbol->value (car form)))) form))
(cons (expand (car form))
(expand (cdr form))))
form))
`(pretty-print ',(expand form)))
(define* (pp-sequence seq)
(let ((iter (make-iterator seq))
(strs ())
(plen (*s7* 'print-length)))
(do ((i 0 (+ i 1))
(entry (iterate iter) (iterate iter)))
((or (= i plen)
(eof-object? entry))
(if (not (eof-object? entry))
(apply string-append (append (reverse! strs) (list "...")))
(apply string-append (reverse! strs))))
(set! strs (cons (format #f "~S " entry) strs)))))
|#