forked from pkrumins/the-reasoned-schemer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkextraforms.scm
executable file
·40 lines (36 loc) · 1.22 KB
/
mkextraforms.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
;;; 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))))))