Modification of the basic if expression in Scheme. Why does it go into an infinite loop?

后端 未结 2 1063
面向向阳花
面向向阳花 2021-01-21 08:42

In Scheme, I modified the basic \'if\' command as:

(define (modified-if predicate then-clause else-clause)
  (if predicate
      then-clause
      else-clause))
         


        
2条回答
  •  深忆病人
    2021-01-21 09:02

    Use the stepper in DrRacket to see how your modified-if behaves.

    Choose the "Beginner" language. Enter the program below, and then click the stepper icon:

    (define (modif predicate then-clause else-clause)
      (if predicate then-clause else-clause))
    (define (factorial n)
      (modif (= n 0) 1 (* n (factorial (- n 1)))))
    (factorial 5)
    

    You can now step for step see how the computation evolves. Notice that modif follows the rule of function application.

    For an example of how the DrRacket stepper looks like: enter image description here

提交回复
热议问题