문제

I need to eliminate this Scheme lambda construction for my school assignment.

Any ideas how to accomplish this?

(define (foo x)
(letrec
  ((h 
    (lambda (y z)
      (cond
        ((null? y) 'undefined)
        ((null? (cdr y)) (car z))
        (else (h (cddr y) (cdr z)))
        ))))
  (h x x))
)
도움이 되었습니까?

해결책

Well, you could replace the lambda expression in the letrec with an internal definition:

(define (foo x)
  (define (h y z)
    (cond
      ((null? y) 'undefined)
      ((null? (cdr y)) (car z))
      (else (h (cddr y) (cdr z)))))
  (h x x))

... Or you could extract the h procedure outside of foo, as a helper procedure. Either way the result would be the same.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top