For the 1st example given on site: View-Site, my understanding is that normal order evaluates to [6;1;1] and applicative order evaluates to [6;2;2]
Can anyone please confirm my assessment?
Regards,
darkie
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ok, let’s go through the steps of evaluating
(cons res v)with normal-order evaluation:vhas been defined as(cons a (cons b ’())), so we havecons res (cons a (cons b ’())).resis defined as(foo ...), so we haveLastly
foo x yis defined as(+ x y y), so by substituting(begin (set! a (+ a 1)) a)forxand(begin (set! b (* b 2)) b)fory, we get:So now let’s evaluate this: To get the result of cons, we first need to evaluate its first argument,
(+ ...). So we first need to evaluate the first argument of+which is(begin (set! a (+ a 1)) a). This evaluates to 2, so the value ofais now 2 and the first argument to+is also 2. Now we do the same thing with the second argument. This also evaluates to 2 and sets b to 2. The third argument is(begin (set! b (* b 2)) b)again, so the value ofbis now 4 and the third argument is 4. So the first argument toconsis the result(+ 2 2 4), which is 8 and the values ofaandbare 2 and 4.Now we need to evaluate the second argument,
(cons a (cons b ’())). So since the value ofaandbare 2 and 4, the end result is(8 2 4).