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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay