LISP Trace of (sum_list '(((1) (2 3)) (4 5)))

In the following trace, the highlighted sections indicate which portion of the expression is to be evaluated in the next step. We have chosen to always evaluate the leftmost expression.

(sum_list '(((1) (2 3)) (4 5))) =>

(+ (sum_list ((1) (2 3))) (sum_list (4 5))) =>

(+ (+ (sum_list (1)) (sum_list (2 3))) (sum_list (4 5))) =>

(+ (+ (+ (car (1)) (sum_list ())) (sum_list (2 3))) (sum_list (4 5))) =>

(+ (+ (+ 1 (sum_list ())) (sum_list (2 3))) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (sum_list (2 3))) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (+ (car (2 3)) (sum_list (cdr (2 3)))) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (+ 2 (sum_list (cdr (2 3)))) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (+ 2 (sum_list (3))) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (+ 2 (+ (car (3)) (sum_list (cdr (3))))) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 (sum_list ()))) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (sum_list (4 5))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ (car (4 5)) (sum_list (cdr (4 5))))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ 4 (sum_list (cdr (4 5))))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ 4 (sum_list (5)))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ 4 (+ (car (5)) (sum_list (cdr (5)))))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ 4 (+ 5 (sum_list (cdr (5)))))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ 4 (+ 5 (sum_list ())))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ 4 (+ 5 0))) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) (+ 4 5)) =>

(+ (+ (+ 1 0) (+ 2 (+ 3 0)) 9) =>

(+ (+ (+ 1 0) (+ 2 3)) 9) =>

(+ (+ (+ 1 0) 5) 9) =>

(+ (+ 1 5) 9) =>

(+ 6 9) =>

15

[TOC]


Last updated 2000/05/18
© J.A.N. Lee, 2000.