What's the explanation for Exercise 1.6 in SICP?

前端 未结 6 514
一个人的身影
一个人的身影 2021-01-30 16:08

I\'m just beginning to work through SICP (on my own; this isn\'t for a class), and I\'ve been struggling with Exercise 1.6 for a couple of days and I just can\'t seem to figure

6条回答
  •  难免孤独
    2021-01-30 16:38

    Ex1.6. new-if:

    (define (new-if predicate then-clause else-clause)
         (cond (predicate then-clause)
                    (else else-clause)))
    

    Difference with ‘if-statements’: if-statements evaluate one by one from predicate -> consequent -> alternative,

    however the ‘new-if’ has to evaluate all parameters aka arguments the MOMENT its called(which means 'else-clause' is evaluated at the start!!),

    and thus this causes an infinite loop when any of these parameters call themselves into an iterative loop

提交回复
热议问题