<br>(define (valid-symbol? x)<br> (and (symbol? x) (not (equal? x '¥ë))))<br><br>;;;<br><br>(define-type LS<br> (id (s symbol?))<br> (func-def (id symbol?) (body LS?))<br> (func-app (applier LS?) (applyed LS?)))<br><br>
;;recognizer: s-expression -> boolean<br>;;x -> #t<br>;;(x y) -> #t<br>;;(x) -> #f<br><br>(define (hof-filter s body)<br> (filter (lambda(x) (equal? x s)) body))<br><br>(define (recognizer sexp)<br> (cond<br>
((valid-symbol? sexp) true)<br> ((and (list? sexp) (= (length sexp) 3) (equal? (first sexp) '¥ë)) (and (valid-symbol? (second sexp)) (recognizer (third sexp))))<br> ((and (list? sexp) (= (length sexp) 2)) (and (recognizer (first sexp)) (recognizer (second sexp))))<br>
(else false)))<br><br>;(test (recognizer 'ali) true)<br>;(test (recognizer '(¥ë ali veli)) true)<br>;(test (recognizer '(¥ë ali (¥ë veli nuri))) true)<br>;(test (recognizer '(¥ë ali veli nuri)) false)<br>;(test (recognizer '(ali nuri)) true)<br>
;(test (recognizer '(ali '(¥ë ali nuri))) true)<br>;(test (recognizer '(ali)) false)<br>;(test (recognizer '(k l z)) false)<br>;(test (recognizer '(¥ë x)) false)<br>;(test (recognizer '(¥ë ¥ë x)) false)<br>
;(test (recognizer '(¥ë x ¥ë)) false)<br><br>;;parser<br>;;parser: s-exp--> lambda-sentence<br><br>(define (parser sexp)<br> (cond<br> ((valid-symbol? sexp) (id sexp))<br> ((and (list? sexp) (= (length sexp) 3) (equal? (first sexp) '¥ë)) (func-def (second sexp) (parser (third sexp))))<br>
((and (list? sexp) (= (length sexp) 2)) (func-app (parser (first sexp)) (parser (second sexp))))<br> (else (error "z"))))<br>;(parser '(¥ë x (¥ë y (y x))))<br>;(test (parser 'x) (id 'x))<br>;(test (parser '(x y)) (func-app (id 'x) (id 'y)))<br>
(parser '(¥ë x (¥ë y ((y z) v))))<br>;(func-def 'x (id 'y)))<br>;(test (parser '((¥ë x y) (¥ë z x))))<br>;(test (parse '(¥ë x(¥ë y ((y x) z)))))<br>;(parser 'x)<br>;(parser '(x y))<br>;(parser '(¥ë x y))<br>
<br>;<br><br>(define (remove-from-body s body)<br> (cond<br> ((null? body) null)<br> ((not (equal? s (car body))) (cons (car body) (remove-from-body s (cdr body))))<br> (else<br> (remove-from-body s (cdr body)))))<br>
;contract : s(element) body(list) -> body <br>(define (addition s body)<br> (cond<br> ((null? body) null)<br> ((eqv? s (car body)) body)<br> ;(((not (eqv? s (car body))) (cons s (car body)))))<br> (else<br>
(cons s (car body)))))<br> <br> <br><br>(define (append-my-own-ver body1 body2)<br> (cond<br> ((null? body1) body2)<br> ((null? body2) body1)<br> (else<br> (cons (car body1) (append-my-own-ver (cdr body1) body2)))))<br>
<br>;;LS--> list-of-free variables<br>(define (find-frees ls)<br>(type-case LS ls<br> (id (x) (list x))<br> (func-def (name body) (remove-from-body name (find-frees body)))<br> (func-app (body1 body2) (append-my-own-ver (find-frees body1) (find-frees body2)))))<br>
<br>(define (find-bounds ls)<br>(type-case LS ls<br> (id (x) (list x))<br> (func-def (name body) (addition name (find-bounds body)))<br><p> (func-app (body1 body2) (append-my-own-ver (find-bounds body1) (find-bounds body2)))))<br>
</p><p><br></p><p>i try to implement lambda calculu©¥s in plai scheme.I define find-frees which help from a function that is remove-from body.That works perfectly.</p><p>And i wrote find-bounds which takes help from a function whose name is addition.But find-bounds is little problematic and i cannot find the mistake.How can i fix that ?</p>
<p>thank very regards.</p>