Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE RACKET PROGRAMMING LANGUAGE AND VERIFY OUTPUTS OR I WILL DISLIKE Question 2: Strings as Arithmetic We can use a string to represent arithmetic expressions.

image text in transcribed

USE RACKET PROGRAMMING LANGUAGE AND VERIFY OUTPUTS OR I WILL DISLIKE

Question 2: Strings as Arithmetic We can use a string to represent arithmetic expressions. For example, "12+73" represents the sum of 12 and 73, and "7*6" represents the product of 7 and 6. A computer program, in any language, can be represented as a sequence of strings. To write a program to interpret computer programs, we need to be able to be able to make sense of such strings. At this point, we do not have the tools to interpret any string. For the purpose of this question, we will define a short expression string as a string of length 3, contain two natural numbers each of 1 digit, separated by any single character indicating the operation to perform. So "5+4" and "219" are both short expression strings, but "765+4", "45678", and "a*3" are not. Write a function interpret-string that consumes a short expression string expr. When the operation is +, -, *, or /, the function shall return the mathematical value of the expression, if it is defined. If the value of the expression is undefined, the function shall return 'undefined. When the operation is anything else, the function shall return 'unknown-operation. For example: 1 > (interpret-string "1/0") 2 "undefined 3> (interpret-string "7*6") 4 42 5 > (interpret-string "2.9") 6 "unknown-operation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

Students also viewed these Databases questions