-
Notifications
You must be signed in to change notification settings - Fork 0
/
reasoned-mk.scm
874 lines (767 loc) · 21.6 KB
/
reasoned-mk.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
;;; Code that accompanies ``The Reasoned Schemer''
;;; Daniel P. Friedman, William E. Byrd and Oleg Kiselyov
;;; MIT Press, Cambridge, MA, 2005
;;;
;;; The implementation of the logic system used in the (2nd printing) of
;;; the book.
;;; This file was generated by writeminikanren.pl
;;; Generated at 2006-02-01 18:26:02
(define-syntax lambdag@
(syntax-rules ()
((_ (s) e) (lambda (s) e))))
(define-syntax lambdaf@
(syntax-rules ()
((_ () e) (lambda () e))))
(define-syntax rhs
(syntax-rules ()
((rhs p) (cdr p))))
(define-syntax lhs
(syntax-rules ()
((lhs p) (car p))))
(define-syntax var
(syntax-rules ()
((var w) (vector w))))
(define-syntax var?
(syntax-rules ()
((var? w) (vector? w))))
(define-syntax size-s
(syntax-rules ()
((size-s ls) (length ls))))
(define empty-s '())
(define walk
(lambda (v s)
(cond
((var? v)
(cond
((assq v s) =>
(lambda (a)
(let ((v^ (rhs a)))
(walk v^ s))))
(else v)))
(else v))))
(define ext-s
(lambda (x v s)
(cons `(,x . ,v) s)))
(define unify
(lambda (v w s)
(let ((v (walk v s))
(w (walk w s)))
(cond
((eq? v w) s)
((var? v) (ext-s v w s))
((var? w) (ext-s w v s))
((and (pair? v) (pair? w))
(cond
((unify (car v) (car w) s) =>
(lambda (s)
(unify (cdr v) (cdr w) s)))
(else #f)))
((equal? v w) s)
(else #f)))))
(define ext-s-check
(lambda (x v s)
(cond
((occurs-check x v s) #f)
(else (ext-s x v s)))))
(define occurs-check
(lambda (x v s)
(let ((v (walk v s)))
(cond
((var? v) (eq? v x))
((pair? v)
(or
(occurs-check x (car v) s)
(occurs-check x (cdr v) s)))
(else #f)))))
(define unify-check
(lambda (v w s)
(let ((v (walk v s))
(w (walk w s)))
(cond
((eq? v w) s)
((var? v) (ext-s-check v w s))
((var? w) (ext-s-check w v s))
((and (pair? v) (pair? w))
(cond
((unify-check (car v) (car w) s) =>
(lambda (s)
(unify-check (cdr v) (cdr w) s)))
(else #f)))
((equal? v w) s)
(else #f)))))
(define walk*
(lambda (v s)
(let ((v (walk v s)))
(cond
((var? v) v)
((pair? v)
(cons
(walk* (car v) s)
(walk* (cdr v) s)))
(else v)))))
(define reify-s
(lambda (v s)
(let ((v (walk v s)))
(cond
((var? v) (ext-s v (reify-name (size-s s)) s))
((pair? v) (reify-s (cdr v) (reify-s (car v) s)))
(else s)))))
(define reify-name
(lambda (n)
(string->symbol
(string-append "_" "." (number->string n)))))
(define reify
(lambda (v)
(walk* v (reify-s v empty-s))))
(define-syntax run
(syntax-rules ()
((_ n^ (x) g ...)
(let ((n n^) (x (var 'x)))
(if (or (not n) (> n 0))
(map-inf n
(lambda (s) (reify (walk* x s)))
((all g ...) empty-s))
'())))))
(define-syntax case-inf
(syntax-rules ()
((_ e on-zero ((a^) on-one) ((a f) on-choice))
(let ((a-inf e))
(cond
((not a-inf) on-zero)
((not (and
(pair? a-inf)
(procedure? (cdr a-inf))))
(let ((a^ a-inf))
on-one))
(else (let ((a (car a-inf))
(f (cdr a-inf)))
on-choice)))))))
(define-syntax mzero
(syntax-rules ()
((_) #f)))
(define-syntax unit
(syntax-rules ()
((_ a) a)))
(define-syntax choice
(syntax-rules ()
((_ a f) (cons a f))))
(define map-inf
(lambda (n p a-inf)
(case-inf a-inf
'()
((a)
(cons (p a) '()))
((a f)
(cons (p a)
(cond
((not n) (map-inf n p (f)))
((> n 1) (map-inf (- n 1) p (f)))
(else '())))))))
(define ==
(lambda (v w)
(lambdag@ (s)
(cond
((unify v w s) => succeed)
(else (fail s))))))
(define ==-check
(lambda (v w)
(lambdag@ (s)
(cond
((unify-check v w s) => succeed)
(else (fail s))))))
(define-syntax fresh
(syntax-rules ()
((_ (x ...) g ...)
(lambdag@ (s)
(let ((x (var 'x)) ...)
((all g ...) s))))))
(define-syntax all
(syntax-rules ()
((_) succeed)
((_ g) (lambdag@ (s) (g s)))
((_ g^ g ...) (lambdag@ (s) (bind (g^ s) (all g ...))))))
(define-syntax conde
(syntax-rules (else)
((_) fail)
((_ (else g0 g ...)) (all g0 g ...))
((_ (g0 g ...) c ...)
(anye (all g0 g ...) (conde c ...)))))
(define succeed (lambdag@ (s) (unit s)))
(define fail (lambdag@ (s) (mzero)))
(define bind
(lambda (a-inf g)
(case-inf a-inf
(mzero)
((a) (g a))
((a f) (mplus (g a)
(lambdaf@ () (bind (f) g)))))))
(define mplus
(lambda (a-inf f)
(case-inf a-inf
(f)
((a) (choice a f))
((a f0) (choice a
(lambdaf@ () (mplus (f0) f)))))))
(define-syntax anye
(syntax-rules ()
((_ g1 g2)
(lambdag@ (s)
(mplus (g1 s)
(lambdaf@ () (g2 s)))))))
(define-syntax alli
(syntax-rules ()
((_) succeed)
((_ g) (lambdag@ (s) (g s)))
((_ g^ g ...)
(lambdag@ (s)
(bindi (g^ s) (alli g ...))))))
(define-syntax condi
(syntax-rules (else)
((_) fail)
((_ (else g0 g ...)) (all g0 g ...))
((_ (g0 g ...) c ...)
(anyi (all g0 g ...) (condi c ...)))))
(define-syntax anyi
(syntax-rules ()
((_ g1 g2)
(lambdag@ (s)
(mplusi (g1 s)
(lambdaf@ () (g2 s)))))))
(define bindi
(lambda (a-inf g)
(case-inf a-inf
(mzero)
((a) (g a))
((a f) (mplusi (g a)
(lambdaf@ () (bindi (f) g)))))))
(define mplusi
(lambda (a-inf f)
(case-inf a-inf
(f)
((a) (choice a f))
((a f0) (choice a
(lambdaf@ () (mplusi (f) f0)))))))
(define-syntax conda
(syntax-rules (else)
((_) fail)
((_ (else g0 g ...)) (all g0 g ...))
((_ (g0 g ...) c ...)
(ifa g0 (all g ...) (conda c ...)))))
(define-syntax condu
(syntax-rules (else)
((_) fail)
((_ (else g0 g ...)) (all g0 g ...))
((_ (g0 g ...) c ...)
(ifu g0 (all g ...) (condu c ...)))))
(define-syntax ifa
(syntax-rules ()
((_ g0 g1 g2)
(lambdag@ (s)
(let ((s-inf (g0 s)) (g^ g1))
(case-inf s-inf
(g2 s)
((s) (g^ s))
((s f) (bind s-inf g^))))))))
(define-syntax ifu
(syntax-rules ()
((_ g0 g1 g2)
(lambdag@ (s)
(let ((s-inf (g0 s)) (g^ g1))
(case-inf s-inf
(g2 s)
((s) (g^ s))
((s f) (g^ s))))))))
;;; Code that accompanies ``The Reasoned Schemer''
;;; Daniel P. Friedman, William E. Byrd and Oleg Kiselyov
;;; MIT Press, Cambridge, MA, 2005
;;;
;;; Extra forms appearing in the framenotes of the book.
;;;
;;; run* is a convenient macro (see frame 10 on page 4 of chapter 1)
;;; (run* (q) ...) is identical to (run #f (q) ...)
;;; See frame 40 on page 68 of chapter 5 for a description of 'lambda-limited'.
;;; See frame 47 on page 138 of chapter 9 for a description of 'project'.
;;;
;;; This file was generated by writeminikanren.pl
;;; Generated at 2005-08-12 11:27:16
(define-syntax run*
(syntax-rules ()
((_ (x) g ...) (run #f (x) g ...))))
(define-syntax lambda-limited
(syntax-rules ()
((_ n formals g)
(let ((x (var 'x)))
(lambda formals
(ll n x g))))))
(define ll
(lambda (n x g)
(lambdag@ (s)
(let ((v (walk x s)))
(cond
((var? v) (g (ext-s x 1 s)))
((< v n) (g (ext-s x (+ v 1) s)))
(else (fail s)))))))
(define-syntax project
(syntax-rules ()
((_ (x ...) g ...)
(lambdag@ (s)
(let ((x (walk* x s)) ...)
((all g ...) s))))))
;;; Code that accompanies ``The Reasoned Schemer''
;;; Daniel P. Friedman, William E. Byrd and Oleg Kiselyov
;;; MIT Press, Cambridge, MA, 2005
;;;
;;; Useful definitions from the book
;;; This file was generated by writeminikanren.pl
;;; Generated at 2005-08-12 11:27:16
;;; 3 October 2005 [WEB]
;;; Renamed 'any*' to 'anyo'.
;;; Renamed 'never' and 'always' to 'nevero' and 'alwayso'.
(define caro
(lambda (p a)
(fresh (d)
(== (cons a d) p))))
(define cdro
(lambda (p d)
(fresh (a)
(== (cons a d) p))))
(define conso
(lambda (a d p)
(== (cons a d) p)))
(define nullo
(lambda (x)
(== '() x)))
(define eqo
(lambda (x y)
(== x y)))
(define eq-caro
(lambda (l x)
(caro l x)))
(define pairo
(lambda (p)
(fresh (a d)
(conso a d p))))
(define listo
(lambda (l)
(conde
((nullo l) succeed)
((pairo l)
(fresh (d)
(cdro l d)
(listo d)))
(else fail))))
(define membero
(lambda (x l)
(conde
((nullo l) fail)
((eq-caro l x) succeed)
(else
(fresh (d)
(cdro l d)
(membero x d))))))
(define rembero
(lambda (x l out)
(conde
((nullo l) (== '() out))
((eq-caro l x) (cdro l out))
(else (fresh (a d res)
(conso a d l)
(rembero x d res)
(conso a res out))))))
(define appendo
(lambda (l s out)
(conde
((nullo l) (== s out))
(else
(fresh (a d res)
(conso a d l)
(conso a res out)
(appendo d s res))))))
(define anyo
(lambda (g)
(conde
(g succeed)
(else (anyo g)))))
(define nevero (anyo fail))
(define alwayso (anyo succeed))
(define build-num
(lambda (n)
(cond
((zero? n) '())
((and (not (zero? n)) (even? n))
(cons 0
(build-num (quotient n 2))))
((odd? n)
(cons 1
(build-num (quotient (- n 1) 2)))))))
(define full-addero
(lambda (b x y r c)
(conde
((== 0 b) (== 0 x) (== 0 y) (== 0 r) (== 0 c))
((== 1 b) (== 0 x) (== 0 y) (== 1 r) (== 0 c))
((== 0 b) (== 1 x) (== 0 y) (== 1 r) (== 0 c))
((== 1 b) (== 1 x) (== 0 y) (== 0 r) (== 1 c))
((== 0 b) (== 0 x) (== 1 y) (== 1 r) (== 0 c))
((== 1 b) (== 0 x) (== 1 y) (== 0 r) (== 1 c))
((== 0 b) (== 1 x) (== 1 y) (== 0 r) (== 1 c))
((== 1 b) (== 1 x) (== 1 y) (== 1 r) (== 1 c))
(else fail))))
(define poso
(lambda (n)
(fresh (a d)
(== `(,a . ,d) n))))
(define >1o
(lambda (n)
(fresh (a ad dd)
(== `(,a ,ad . ,dd) n))))
(define addero
(lambda (d n m r)
(condi
((== 0 d) (== '() m) (== n r))
((== 0 d) (== '() n) (== m r)
(poso m))
((== 1 d) (== '() m)
(addero 0 n '(1) r))
((== 1 d) (== '() n) (poso m)
(addero 0 '(1) m r))
((== '(1) n) (== '(1) m)
(fresh (a c)
(== `(,a ,c) r)
(full-addero d 1 1 a c)))
((== '(1) n) (gen-addero d n m r))
((== '(1) m) (>1o n) (>1o r)
(addero d '(1) n r))
((>1o n) (gen-addero d n m r))
(else fail))))
(define gen-addero
(lambda (d n m r)
(fresh (a b c e x y z)
(== `(,a . ,x) n)
(== `(,b . ,y) m) (poso y)
(== `(,c . ,z) r) (poso z)
(alli
(full-addero d a b c e)
(addero e x y z)))))
(define +o
(lambda (n m k)
(addero 0 n m k)))
(define -o
(lambda (n m k)
(+o m k n)))
(define *o
(lambda (n m p)
(condi
((== '() n) (== '() p))
((poso n) (== '() m) (== '() p))
((== '(1) n) (poso m) (== m p))
((>1o n) (== '(1) m) (== n p))
((fresh (x z)
(== `(0 . ,x) n) (poso x)
(== `(0 . ,z) p) (poso z)
(>1o m)
(*o x m z)))
((fresh (x y)
(== `(1 . ,x) n) (poso x)
(== `(0 . ,y) m) (poso y)
(*o m n p)))
((fresh (x y)
(== `(1 . ,x) n) (poso x)
(== `(1 . ,y) m) (poso y)
(odd-*o x n m p)))
(else fail))))
(define odd-*o
(lambda (x n m p)
(fresh (q)
(bound-*o q p n m)
(*o x m q)
(+o `(0 . ,q) m p))))
(define bound-*o
(lambda (q p n m)
(conde
((nullo q) (pairo p))
(else
(fresh (x y z)
(cdro q x)
(cdro p y)
(condi
((nullo n)
(cdro m z)
(bound-*o x y z '()))
(else
(cdro n z)
(bound-*o x y z m))))))))
(define =lo
(lambda (n m)
(conde
((== '() n) (== '() m))
((== '(1) n) (== '(1) m))
(else
(fresh (a x b y)
(== `(,a . ,x) n) (poso x)
(== `(,b . ,y) m) (poso y)
(=lo x y))))))
(define <lo
(lambda (n m)
(conde
((== '() n) (poso m))
((== '(1) n) (>1o m))
(else
(fresh (a x b y)
(== `(,a . ,x) n) (poso x)
(== `(,b . ,y) m) (poso y)
(<lo x y))))))
(define <=lo
(lambda (n m)
(condi
((=lo n m) succeed)
((<lo n m) succeed)
(else fail))))
(define <o
(lambda (n m)
(condi
((<lo n m) succeed)
((=lo n m)
(fresh (x)
(poso x)
(+o n x m)))
(else fail))))
(define <=o
(lambda (n m)
(condi
((== n m) succeed)
((<o n m) succeed)
(else fail))))
(define /o
(lambda (n m q r)
(condi
((== r n) (== '() q) (<o n m))
((== '(1) q) (=lo n m) (+o r m n)
(<o r m))
(else
(alli
(<lo m n)
(<o r m)
(poso q)
(fresh (nh nl qh ql qlm qlmr rr rh)
(alli
(splito n r nl nh)
(splito q r ql qh)
(conde
((== '() nh)
(== '() qh)
(-o nl r qlm)
(*o ql m qlm))
(else
(alli
(poso nh)
(*o ql m qlm)
(+o qlm r qlmr)
(-o qlmr nl rr)
(splito rr r '() rh)
(/o nh m qh rh)))))))))))
(define splito
(lambda (n r l h)
(condi
((== '() n) (== '() h) (== '() l))
((fresh (b n^)
(== `(0 ,b . ,n^) n)
(== '() r)
(== `(,b . ,n^) h)
(== '() l)))
((fresh (n^)
(== `(1 . ,n^) n)
(== '() r)
(== n^ h)
(== '(1) l)))
((fresh (b n^ a r^)
(== `(0 ,b . ,n^) n)
(== `(,a . ,r^) r)
(== '() l)
(splito `(,b . ,n^) r^ '() h)))
((fresh (n^ a r^)
(== `(1 . ,n^) n)
(== `(,a . ,r^) r)
(== '(1) l)
(splito n^ r^ '() h)))
((fresh (b n^ a r^ l^)
(== `(,b . ,n^) n)
(== `(,a . ,r^) r)
(== `(,b . ,l^) l)
(poso l^)
(splito n^ r^ l^ h)))
(else fail))))
(define logo
(lambda (n b q r)
(condi
((== '(1) n) (poso b) (== '() q) (== '() r))
((== '() q) (<o n b) (+o r '(1) n))
((== '(1) q) (>1o b) (=lo n b) (+o r b n))
((== '(1) b) (poso q) (+o r '(1) n))
((== '() b) (poso q) (== r n))
((== '(0 1) b)
(fresh (a ad dd)
(poso dd)
(== `(,a ,ad . ,dd) n)
(exp2 n '() q)
(fresh (s)
(splito n dd r s))))
((fresh (a ad add ddd)
(conde
((== '(1 1) b))
(else (== `(,a ,ad ,add . ,ddd) b))))
(<lo b n)
(fresh (bw1 bw nw nw1 ql1 ql s)
(exp2 b '() bw1)
(+o bw1 '(1) bw)
(<lo q n)
(fresh (q1 bwq1)
(+o q '(1) q1)
(*o bw q1 bwq1)
(<o nw1 bwq1))
(exp2 n '() nw1)
(+o nw1 '(1) nw)
(/o nw bw ql1 s)
(+o ql '(1) ql1)
(conde
((== q ql))
(else (<lo ql q)))
(fresh (bql qh s qdh qd)
(repeated-mul b ql bql)
(/o nw bw1 qh s)
(+o ql qdh qh)
(+o ql qd q)
(conde
((== qd qdh))
(else (<o qd qdh)))
(fresh (bqd bq1 bq)
(repeated-mul b qd bqd)
(*o bql bqd bq)
(*o b bq bq1)
(+o bq r n)
(<o n bq1)))))
(else fail))))
(define exp2
(lambda (n b q)
(condi
((== '(1) n) (== '() q))
((>1o n) (== '(1) q)
(fresh (s)
(splito n b s '(1))))
((fresh (q1 b2)
(alli
(== `(0 . ,q1) q)
(poso q1)
(<lo b n)
(appendo b `(1 . ,b) b2)
(exp2 n b2 q1))))
((fresh (q1 nh b2 s)
(alli
(== `(1 . ,q1) q)
(poso q1)
(poso nh)
(splito n b s nh)
(appendo b `(1 . ,b) b2)
(exp2 nh b2 q1))))
(else fail))))
(define repeated-mul
(lambda (n q nq)
(conde
((poso n) (== '() q) (== '(1) nq))
((== '(1) q) (== n nq))
((>1o q)
(fresh (q1 nq1)
(+o q1 '(1) q)
(repeated-mul n q1 nq1)
(*o nq1 n nq)))
(else fail))))
(define expo
(lambda (b q n)
(logo n b q '())))
;;; 'trace-vars' can be used to print the values of selected variables
;;; in the substitution.
(define-syntax trace-vars
(syntax-rules ()
((_ title x ...)
(lambdag@ (s)
(begin
(printf "~a~n" title)
(for-each (lambda (x_ t)
(printf "~a = ~s~n" x_ t))
`(x ...) (reify (walk* `(,x ...) s)))
(unit s))))))
;;; (run* (q)
;;; (fresh (r)
;;; (== 3 q)
;;; (trace-vars "What it is!" q r)))
;;;
;;; What it is!
;;; q = 3
;;; r = _.0
;;; (3)
;;; ========================================
(define-syntax run1 (syntax-rules () ((_ (x) g0 g ...) (run 1 (x) g0 g ...))))
(define-syntax run2 (syntax-rules () ((_ (x) g0 g ...) (run 2 (x) g0 g ...))))
(define-syntax run3 (syntax-rules () ((_ (x) g0 g ...) (run 3 (x) g0 g ...))))
(define-syntax run4 (syntax-rules () ((_ (x) g0 g ...) (run 4 (x) g0 g ...))))
(define-syntax run5 (syntax-rules () ((_ (x) g0 g ...) (run 5 (x) g0 g ...))))
(define-syntax run6 (syntax-rules () ((_ (x) g0 g ...) (run 6 (x) g0 g ...))))
(define-syntax run7 (syntax-rules () ((_ (x) g0 g ...) (run 7 (x) g0 g ...))))
(define-syntax run8 (syntax-rules () ((_ (x) g0 g ...) (run 8 (x) g0 g ...))))
(define-syntax run9 (syntax-rules () ((_ (x) g0 g ...) (run 9 (x) g0 g ...))))
(define-syntax run10 (syntax-rules () ((_ (x) g0 g ...) (run 10 (x) g0 g ...))))
(define-syntax run11 (syntax-rules () ((_ (x) g0 g ...) (run 11 (x) g0 g ...))))
(define-syntax run12 (syntax-rules () ((_ (x) g0 g ...) (run 12 (x) g0 g ...))))
(define-syntax run13 (syntax-rules () ((_ (x) g0 g ...) (run 13 (x) g0 g ...))))
(define-syntax run14 (syntax-rules () ((_ (x) g0 g ...) (run 14 (x) g0 g ...))))
(define-syntax run15 (syntax-rules () ((_ (x) g0 g ...) (run 15 (x) g0 g ...))))
(define-syntax run16 (syntax-rules () ((_ (x) g0 g ...) (run 16 (x) g0 g ...))))
(define-syntax run17 (syntax-rules () ((_ (x) g0 g ...) (run 17 (x) g0 g ...))))
(define-syntax run18 (syntax-rules () ((_ (x) g0 g ...) (run 18 (x) g0 g ...))))
(define-syntax run19 (syntax-rules () ((_ (x) g0 g ...) (run 19 (x) g0 g ...))))
(define-syntax run20 (syntax-rules () ((_ (x) g0 g ...) (run 20 (x) g0 g ...))))
(define-syntax run21 (syntax-rules () ((_ (x) g0 g ...) (run 21 (x) g0 g ...))))
(define-syntax run22 (syntax-rules () ((_ (x) g0 g ...) (run 22 (x) g0 g ...))))
(define-syntax run23 (syntax-rules () ((_ (x) g0 g ...) (run 23 (x) g0 g ...))))
(define-syntax run24 (syntax-rules () ((_ (x) g0 g ...) (run 24 (x) g0 g ...))))
(define-syntax run25 (syntax-rules () ((_ (x) g0 g ...) (run 25 (x) g0 g ...))))
(define-syntax run26 (syntax-rules () ((_ (x) g0 g ...) (run 26 (x) g0 g ...))))
(define-syntax run27 (syntax-rules () ((_ (x) g0 g ...) (run 27 (x) g0 g ...))))
(define-syntax run28 (syntax-rules () ((_ (x) g0 g ...) (run 28 (x) g0 g ...))))
(define-syntax run29 (syntax-rules () ((_ (x) g0 g ...) (run 29 (x) g0 g ...))))
(define-syntax run30 (syntax-rules () ((_ (x) g0 g ...) (run 30 (x) g0 g ...))))
(define-syntax run31 (syntax-rules () ((_ (x) g0 g ...) (run 31 (x) g0 g ...))))
(define-syntax run32 (syntax-rules () ((_ (x) g0 g ...) (run 32 (x) g0 g ...))))
(define-syntax run33 (syntax-rules () ((_ (x) g0 g ...) (run 33 (x) g0 g ...))))
(define-syntax run34 (syntax-rules () ((_ (x) g0 g ...) (run 34 (x) g0 g ...))))
(define-syntax run35 (syntax-rules () ((_ (x) g0 g ...) (run 35 (x) g0 g ...))))
(define-syntax run36 (syntax-rules () ((_ (x) g0 g ...) (run 36 (x) g0 g ...))))
(define-syntax run37 (syntax-rules () ((_ (x) g0 g ...) (run 37 (x) g0 g ...))))
(define-syntax run38 (syntax-rules () ((_ (x) g0 g ...) (run 38 (x) g0 g ...))))
(define-syntax run39 (syntax-rules () ((_ (x) g0 g ...) (run 39 (x) g0 g ...))))
(define-syntax run40 (syntax-rules () ((_ (x) g0 g ...) (run 40 (x) g0 g ...))))
;;; ========================================
(define SUCC succeed)
(define FAIL fail)
(define STR
(lambda (data)
(cond ((null? data) "")
((string? data) data)
((number? data) (number->string data))
((symbol? data) (symbol->string data))
((vector? data) (string-append "@" (STR (vector->list data))))
((list? data) (string-append
"("
(fold-left (lambda (x y)
(string-append
x
(if (zero? (string-length x)) "" " ")
(STR y))) "" data)
")"))
(else
(error "unknown object" data)))))
(define D
(lambda (l)
(for-each (lambda (x) (display x) (newline))
l)
unspecific))
'load-minikanren:done