Download Sections - MIT Computer Science and Artificial Intelligence Laboratory
Transcript
48 MIT Scheme Reference zero? z positive? x negative? x odd? x even? x procedure procedure procedure procedure procedure These numerical predicates test a number for a particular property, returning #t or #f. See note above regarding inexact numbers. max x1 x2 . . . min x1 x2 . . . procedure procedure These procedures return the maximum or minimum of their arguments. ⇒ 4 (max 3 4) ; exact ⇒ 4.0 ; inexact (max 3.9 4) Note: If any argument is inexact, then the result will also be inexact (unless the procedure can prove that the inaccuracy is not large enough to affect the result, which is possible only in unusual implementations). If min or max is used to compare numbers of mixed exactness, and the numerical value of the result cannot be represented as an inexact number without loss of accuracy, then the procedure may report a violation of an implementation restriction.4 + z1 . . . * z1 . . . procedure procedure These procedures return the sum or product of their arguments. ⇒ 7 (+ 3 4) ⇒ 3 (+ 3) ⇒ 0 (+) ⇒ 4 (* 4) ⇒ 1 (*) - z1 z2 . . . / z1 z2 . . . procedure procedure With two or more arguments, these procedures return the difference or quotient of their arguments, associating to the left. With one argument, however, they return the additive or multiplicative inverse of their argument. ⇒ -1 (- 3 4) ⇒ -6 (- 3 4 5) ⇒ -3 (- 3) ⇒ 3/20 (/ 3 4 5) ⇒ 1/3 (/ 3) 1+ z -1+ z procedure+ procedure+ (1+ z) is equivalent to (+ z 1); (-1+ z) is equivalent to (- z 1). 4 MIT Scheme signals an error of type condition-type:bad-range-argument in this case.