Endrekursion
2003-03-31 14:05
Anonymer User
hallo leuds!
Also ich hab eine Funktion linear definiert:
(verdoppeln '(1 2 3 4)) -> (1 1 2 2 3 3 4 4)
(define (verdoppeln xs)
(if (null? xs) '()
(append (list (car xs) (car xs))
(verdoppeln (cdr xs)))))
So und nu möchte ich es endrekursiv schreiben.
Ist dann doch
(define (verdoppeln xs)(verdoppeln_acc xs '()))
(define (verdoppeln_acc xs acc)
(if (null? xs) acc
(append (list (car xs) (car xs))
(verdoppeln_acc (cdr sx)))))
Also da fehlt noch was
help
Also ich hab eine Funktion linear definiert:
(verdoppeln '(1 2 3 4)) -> (1 1 2 2 3 3 4 4)
(define (verdoppeln xs)
(if (null? xs) '()
(append (list (car xs) (car xs))
(verdoppeln (cdr xs)))))
So und nu möchte ich es endrekursiv schreiben.
Ist dann doch
(define (verdoppeln xs)(verdoppeln_acc xs '()))
(define (verdoppeln_acc xs acc)
(if (null? xs) acc
(append (list (car xs) (car xs))
(verdoppeln_acc (cdr sx)))))
Also da fehlt noch was
help