lundi 9 novembre 2020

How does SICP intend if forms without their alternative (else) part to work?

Exercise 1.22 of SICP contains the following procedure:

(define (start-prime-test n start-time)
  (if (prime? n)
      (report-prime (- (runtime) start-time))))

To my eyes, the if form has no alternative branch. I can only see if(test)(consequent). Where does SICP introduce this form? if is introduced in Section 1.1.6 but I see nowhere in that section that covers "if without else" cases. It is possible that I could guess the intended behavior from the definition of cond in that same section, but said section has a footnote that shows that the two are different. So how can I tell how SICP intends such if forms to work?

Aucun commentaire:

Enregistrer un commentaire