DEV Community

Cover image for Evaluation in Racket
Imran Shaikh
Imran Shaikh

Posted on

Evaluation in Racket

(+ 2 (* 3 4) (- (+ 1 2) 3))
Enter fullscreen mode Exit fullscreen mode

This expression is an primitive call or call to a primitive. Because expression starts with a primitive operator.

Operator: In this primitive call + is the operator

Operands: And all the expression followed by the operator are called operands

Rules to Evaluate a Primitive Call

Step

  1. First reduce all the operands to values.
  2. Then apply primitive oparation to the values.

Order

  • Evaulation happens from left to right and inside to outside.

Step by step Evaluation Example:

(+ 2 (* 3 4) (- (+ 1 2) 3))
(+ 2 12 (- (+ 1 2) 3)) ; Step 1
(+ 2 12 (- 3 3)) ; Step 2
(+ 2 12 0) ; Step 3
14 ; Step 4
Enter fullscreen mode Exit fullscreen mode

This example demonstrates the step-by-step evaluation of the expression according to the rules mentioned above. Understanding the order of evaluation is crucial for accurately assessing complex expressions in Racket.

Top comments (0)