;; named let
(define (my-reverse ls)
(let loop ((l ls) (acc '()))
(if (null? l)
acc
(loop (cdr l) (cons (car l) acc)))))
(display (my-reverse '(1 2 3 4 5)))
(newline)
;; do
(define (my-reverse ls)
(do ((l ls (cdr l))
(acc '() (cons (car l) acc)))
((null? l) acc)))
(display (my-reverse '(1 2 3 4 5)))
(newline)
(define (my-reverse ls)
(do ((l ls (cdr l))
(acc '() (cons (car l) acc)))
((null? l) acc)
(for-each (lambda (x)
(for-each display x)
(newline)) `(("l => " ,l) ("acc => " ,acc)))))
(my-reverse '(1 2 3 4 5))
0 件のコメント:
コメントを投稿