Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Normal Order vs. Applicative Order

Name: Anonymous 2013-07-01 22:38

Fucking SICP does a piss-poor job of explaining this, and the cunts on /g/ are too busy creating threads about the fucking Macbook Air to answer the two separate threads I created about this today.

I am stuck on this concept for two days. Yes, I _am_ a retard but that's beside the point. Does anyone want to help me conceptually understand this using Excercise 1.5 in SICP? I'm pasting it below:

**********
Ben Bitdiddle has invented a test to determine whether the interpreter he is faced with is using applicative-order evaluation or normal-order evaluation. He defines the following two procedures:

(define (p) (p))

(define (test x y)
  (if (= x 0)
      0
      y))

Then he evaluates the expression

(test 0 (p))

What behavior will Ben observe with an interpreter that uses applicative-order evaluation? What behavior will he observe with an interpreter that uses normal-order evaluation? Explain your answer. (Assume that the evaluation rule for the special form 'if' is the same whether the interpreter is using normal or applicative order: The predicate expression is evaluated first, and the result determines whether to evaluate the consequent or the alternative expression.)
**********

I can't for the life of me decipher what GJ Sussman means by his confounding use of the words 'apply', 'evaluate', 'expand' and 'reduce' in the relevant section of the book.

Elsewhere on the internet, the solutions say that since Scheme uses Applicative Order (= "evaluate arguments then apply"), (test 0 (p)) does not terminate... and I understand that, I think. But it shouldn't terminate even if Scheme used Normal Order, because Normal Order = "fully expand, then reduce". Now (p) is defined as itself, so trying to "fully expand" (p) shouldn't ever terminate.

But then he springs this on me: Normal Order is also "...An alternative evaluation model [that does not] evaluate the operands until their values [are] needed." So Normal Order is also the same as Lazy Evaluation?

There's surely a gap in my thinking process, but for fuck's sake, where is it?? PLEASE HELP.

Name: Anonymous 2013-07-01 22:49

i think i get it... =/ so normal order should just return 0?
what nasty code..

Name: Anonymous 2013-07-01 23:00

Well yeah, according to some  solutions posted online, Normal should return 0, as the 'alternative' portion of the if statement allegedly isn't evaluated at all, so (p) allegedly isn't called at all.

Name: Anonymous 2013-07-01 23:04

muh Cross-Interpreter-Compatibility..
ugh, why doesn't it just flag p as undefined?

Name: Anonymous 2013-07-01 23:11

>>4
You're getting way ahead of me. I don't know what cross-interpreter-compatibility means. Please just explain Normal Order vs Applicative Order to me in the context of the above exercise; I'd appreciate it very much.

Name: Anonymous 2013-07-01 23:17

....oh god.. it's not even undefined, its effectively this..?
function p(){
  p();
  }

Name: Anonymous 2013-07-01 23:20

>>6
Yes, I think that's it.

Name: Anonymous 2013-07-01 23:23

>>1
Source on the "fully expand and reduce" part, sounds wrong? Perhaps what is meant is that the outermost structure is expanded only, and reduced as in (if #t b c) => b?
Anyway, normal form in this case would indeed be similar to lazy evaluation, except that I'm guessing this case the outermost evaluator won't necessarily ask for a value and can just ask for a structure/name, e.g. "(p)" instead of its result "(p)".

Name: Anonymous 2013-07-01 23:27

>>6
>>4
/polecats kébabs/

Name: Anonymous 2013-07-01 23:33

...So, Applicative order will probably jump straight to the deepest pair of brackets in the test expression, which instantly gets stuck in an empty recursion loop..
Normal order appears to be checking the outer expression first, and then because if x=0 it can skip y, it does?

Name: Anonymous 2013-07-01 23:34

Expansion in applicative order:
(test 0 (p)) ; eval args them apply to test
(test 0 (p)) ; 0 evaluates to 0
(test 0 (p)) ; apply p
(test 0 (p)) ; (p) expands to (p), apply p
(test 0 (p)) ; (p) expands to (p), apply p
(test 0 (p)) ; (p) expands to (p), apply p
... ; infinite loop


Expansion in normal order:
(test 0 (p)) ; apply 0 and (p) to test without evaluating them
(if (= 0 0) 0 (p)) ; evaluate condition, (= 0 0)
(if #t 0 (p)) ; condition is true, so return consequent, ignore alternative
0 ; 0 evaluates to 0

Name: Anonymous 2013-07-01 23:42

So Normal Order is also the same as Lazy Evaluation?
Pretty much.

Name: Anonymous 2013-07-02 0:23

Name: Anonymous 2013-07-02 0:28


Don't change these.
Name: Email:
Entire Thread Thread List