Question: 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.

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
Get step-by-step solutions from verified subject matter experts
