Q4: Swap Implement swap, a procedure which takes a call expression expr and returns the same...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Q4: Swap Implement swap, a procedure which takes a call expression expr and returns the same expression with its first two operands swapped if the evaluated value of the second operand is greater than the evaluated value of the first operand. Otherwise, it should just return the original expression. For example, (swap '(-1 (+ 3 5) 7)) should return the expression (- (+ 3 5) 1 7) since 1 evaluates to 1, (+ 3 5) evaluates to 8, and 8 > 1. Any operands after the first two should not be evaluated during the execution of the procedure, and they should be left unchanged in the final expression. You may assume that every operand evaluates to a number and that there are always at least two operands in expr. Hint: Quasiquotation might not be the best way to approach this problem (look at the bindings in the let expression to see why this might be the case). What other methods of building lists could we use to solve this problem? Q1: WWSD: Quasiquote Programs as Data Q2: If Program Q3: Exponential Powers Q4: Swap lab12.scm-lab12 - Visual Studio Code File Edit Selection View Go Run Terminal Help EXPLORER lab12.scm x Reminder: Don't forget to evaluate the first two operands when comparing them! (define (cddr s) (cdr (cdr s)) > (define (cadr s) > (car (cdr s)) (define (caddr s) (car (cddr s)) > (define (swap expr) (let ((op (car expr)) ) (first (car (cdr expr))) (second (caddr expr)) (rest (cdr (cddr expr)))) 'YOUR-CODE-HERE ) Q LAB12 > editor > tests 1 2 lab12.scm (define (if-program condition if-true if-false) 'YOUR-CODE-HERE) 3 = .ok_history 4 (define (pow-expr n p) 'YOUR-CODE-HERE) lab12.ok 5 lab12.scm 6 (define (cddr s) (cdr (cdr s))) ok 7 =scheme 8 (define (cadr s) (car (cdr s))) 9 10 (define (caddr s) (car (cddr s))) 11 12 (define (swap expr) 13 (let ((op (car expr)) 14 15 16 17 (first (car (cdr expr))) (second (caddr expr)) (rest (cdr (cddr expr)))) 'YOUR-CODE-HERE)) 18 4 % Q4: Swap Implement swap, a procedure which takes a call expression expr and returns the same expression with its first two operands swapped if the evaluated value of the second operand is greater than the evaluated value of the first operand. Otherwise, it should just return the original expression. For example, (swap '(-1 (+ 3 5) 7)) should return the expression (- (+ 3 5) 1 7) since 1 evaluates to 1, (+ 3 5) evaluates to 8, and 8 > 1. Any operands after the first two should not be evaluated during the execution of the procedure, and they should be left unchanged in the final expression. You may assume that every operand evaluates to a number and that there are always at least two operands in expr. Hint: Quasiquotation might not be the best way to approach this problem (look at the bindings in the let expression to see why this might be the case). What other methods of building lists could we use to solve this problem? Q1: WWSD: Quasiquote Programs as Data Q2: If Program Q3: Exponential Powers Q4: Swap lab12.scm-lab12 - Visual Studio Code File Edit Selection View Go Run Terminal Help EXPLORER lab12.scm x Reminder: Don't forget to evaluate the first two operands when comparing them! (define (cddr s) (cdr (cdr s)) > (define (cadr s) > (car (cdr s)) (define (caddr s) (car (cddr s)) > (define (swap expr) (let ((op (car expr)) ) (first (car (cdr expr))) (second (caddr expr)) (rest (cdr (cddr expr)))) 'YOUR-CODE-HERE ) Q LAB12 > editor > tests 1 2 lab12.scm (define (if-program condition if-true if-false) 'YOUR-CODE-HERE) 3 = .ok_history 4 (define (pow-expr n p) 'YOUR-CODE-HERE) lab12.ok 5 lab12.scm 6 (define (cddr s) (cdr (cdr s))) ok 7 =scheme 8 (define (cadr s) (car (cdr s))) 9 10 (define (caddr s) (car (cddr s))) 11 12 (define (swap expr) 13 (let ((op (car expr)) 14 15 16 17 (first (car (cdr expr))) (second (caddr expr)) (rest (cdr (cddr expr)))) 'YOUR-CODE-HERE)) 18 4 %
Expert Answer:
Related Book For
Computer Architecture Fundamentals And Principles Of Computer Design
ISBN: 9781032097336
2nd Edition
Authors: Joseph D. Dumas II
Posted Date:
Students also viewed these algorithms questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
The new line character is utilized solely as the last person in each message. On association with the server, a client can possibly (I) question the situation with a client by sending the client's...
-
What constant should replace the question mark in this system so that the solution set is {(1, 1, 1)}? 2x - 3y + -5x + 2y z = 0 - 2 = x + y + 2z = ? 4 -4
-
Refer to Exercise 10-33. Find the double sampling plan if the second sample is to be twice as large as the first sample and the consumer's stipulation is to be satisfied exactly. In Exercise 10.33 A...
-
Identify the reasons for differences in employee voice across geographical boundaries
-
Auto-USA spent \($300\) million in total to produce 50,000 cars this year. The \($300\) million breaks down as follows: The company spent \($50\) million on fixed costs to run its manufacturing...
-
A quartz sphere is 8.75 cm in diameter. What will be its change in volume if it is heated from 30oC to 200oC?
-
What are the legal consequences of using corporate assets for personal use? Back it with primary sources like the internal revenue code, internal revenue manual, treasury regulations.
-
Respond that the following statements are true or false: 1. The income summary account is an account used only during the closing process. 2. The purpose and use of the income summary account is to...
-
Jos opened a bag of M&M's and recorded the following number of candies of each color: Brown: 15 Green: 5 Yellow: 4 Orange: 8 Blue: 6 Red: 12 Find the probabilities of the following events. a. One...
-
After doing an origami of crane and pigeon. for me Its hard to make an crane make a paragraph form of answer with introduction 1.Was easier to estimate the entire packet as a whole (task 2) or in...
-
An ideal Brayton cycle operates between 15 psia, 60F and 100 psia, 1500F; the compressor and expander are both perfectly efficient. Determine the net work and back-work ratio.
-
An 8% $200,000 bond has exactly 9 years to maturity and pays semi-annually. What is the price of the bond if the yield is 9.18% pa? Give your answer to two decimal places and no $ sign
-
3.2 Comment on the following ratios: Inventory turnover Debtors collection period Earnings per share 2022 15 times 40.50 days 31.5 cents 2021 19 times 26.35 days 41 cents
-
You need to read a paper about Data Driven Decision Making and write a Reflection paper
-
Chao, Louis, and Mari, unrelated individuals, own all of the shares of Cerise Corporation. All three shareholders have been active in the management of Cerise since its inception. In the current...
-
A Pepsi promotion encouraged consumers to collect Pepsi points and redeem them for merchandise. If they did not have quite enough points for the prize they wanted, they could buy additional points...
-
What is the mirror-image rule?
-
In July 2008, Brian, Dale, and Sandra Allen signed a contract with East Resources, Inc., concerning 148 acres of the Allens property. East wanted to develop and exploit the oil and gas resources...
Study smarter with the SolutionInn App