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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay