Can someone help me break down the exact execution order for future versions of anti-aliasing? I am using Racket.
version 1, from the racket itself, and the second version is more common? implementation.
(define (flatten1 list) (let loop ([l list] [acc null]) (printf "l = ~a acc = ~a\n" l acc) (cond [(null? l) acc] [(pair? l) (loop (car l) (loop (cdr l) acc))] [else (cons l acc)]))) (define (flatten2 l) (printf "l = ~a\n" l) (cond [(null? l) null] [(atom? l) (list l)] [else (append (flatten2 (car l)) (flatten2 (cdr l)))]))
Now, running the first example with '(1 2 3), do:
l = (1 2 3) acc = () l = (2 3) acc = () l = (3) acc = () l = () acc = () l = 3 acc = () l = 2 acc = (3) l = 1 acc = (2 3) '(1 2 3)
and the second produces:
l = (1 2 3) l = 1 l = (2 3) l = 2 l = (3) l = 3 l = () '(1 2 3)
The execution order seems different. In the first example, it looks like the second cycle (loop (cdr l) acc) starts before the first cycle, because "(2 3) prints immediately. While in the second example, 1 fingerprint before '(2 3) is evaluated first, which , as the first smoothing call inside the append, is evaluated first.
I am experiencing Little Schemer, but these are more complex examples that I could really use.
Thank you very much.
source share