Approaches to Expression Evaluation • Innermost Evaluation • Outermost Evaluation • Selective Evaluation • Evaluation of Recursive Functions • Short-Circuit Evaluation
Innermost Evaluation Under the innermost-evaluation rule, a function application < name > < actual- parameter > is computed as follows: Evaluate the expression represented by < actual- parameter>. Substitute the result for the formal in the function body. Evaluate the body and return its value as the answer. e.g: fun successor n = n + 1 ; successor (2+3) 2 + 3 = 5 successor (5)
Outermost Evaluation Under the outermost-evaluation rule, a function is computed as follows Substitute the actual parameter for the formal in the function body. Evaluate the body and return its value as the answer. e.g: fun successor n = n + 1 successor (2 + 3) n = 2+3+1 = 6 The answer is the same in both the cases.
Selective Evaluation The ability to evaluate selectively some parts of an expression and ignore others is provided by the construct if < condition > then < expression 1 > else < expression 2 >
You've reached the end of your free preview.
Want to read all 13 pages?
- Fall '19