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
-
Beyond the Leadership Council / Team , whose responsibility is it to provide resources and remove roadblocks that can hinder teams, particularly for projects that cross functional boundaries? a...
-
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
-
It is desired to accept lots that are 9.5% nonconforming with a probability of 0.10 and to accept lots that are 2.3% nonconforming with a probability of 0.95. Find a double sampling plan for a lot...
-
Hotel maintenance is the upkeep of the various systems and components used in the hospitality industry. These systems include general building operations such as HVAC, electrical, and plumbing, but...
-
Describe a conflict that may arise between the shareholders of a company and the managers of the company. Discuss what the shareholders might do to overcome that conflict and explain why you feel...
-
On November 1, 2010, Edwin, Inc., borrowed cash and signed a $60,000, one-year note payable. Required 1. Compute the following items assuming (i) an interest-bearing note at 12%, (ii) a...
-
Please create a SMART goal for yourself for your current job or your life and provide a rationale for how the goal meets each of the SMART items. please create a SMART goal for your personal...
-
1. When you are joining a server or client workstation to the domain, what is the purpose of supplying the Domain Administrator's username and password to complete the process? 2. Why would a company...
-
Company Tau and Company Upsilon are the only sellers of a good with no close substitutes. They are each considering whether to increase their store hours. They project the following daily profit...
-
The following table represents the total amount of money, a, in billions of dollars spent on health care in a country in different years, t. Year Amount 1970 1980 1985 1990 1995 2000 2003 2005 2008...
-
The Olney Corporation provided the following information to their CPA. The accountant was asked to help them answer the questions listed below. Sales $ 274,000 Variable expenses 225,000 Contribution...
-
Find the general solution to the system 1 9 0 + 0 4 0 or shew that there is no solution.
-
Research the Covid event using Web and the Library's databases. Find one source of information connected to the event from each of the seven formats listed below: Encyclopedia article or reference...
-
McKenzie Company can sell 20,000 pounds of product for $10 per pound. The company can also process this product further and sell it for $17 per pound at a cost of $110,000. Should McKenzie sell...
-
Walker, Inc., is an all-equity firm. The cost of the company's equity is currently 11.4 percent and the risk-free.rate is 3.3 percent. The company is currently considering a project that will cost...
-
If \(\kappa_{1}\) and \(\kappa_{2}\) are kernels on \(\mathscr{X}\) and \(\mathscr{Y}\), then \(\kappa_{+},\left((\boldsymbol{x}, \boldsymbol{y}),\left(\boldsymbol{x}^{\prime},...
-
Let \(\mathbf{X}\) be an \(\mathbb{R}^{d}\)-valued random variable that is symmetric about the origin (that is, \(\boldsymbol{X}\) and \((-\boldsymbol{X})\) are identically distributed). Denote by...
-
Suppose an \(\mathrm{RKHS} \mathscr{G}\) of functions from \(\mathscr{X} ightarrow \mathbb{R}\) (with kernel \(\kappa\) ) is invariant under a group \(\mathscr{T}\) of transformations \(T:...
Study smarter with the SolutionInn App