1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
slamgirl [31]
3 years ago
8

In Scheme, source code is data. Every non-atomic expression is written as a Scheme list, so we can write procedures that manipul

ate other programs just as we write procedures that manipulate lists.
Rewriting programs can be useful: we can write an interpreter that only handles a small core of the language, and then write a procedure that converts other special forms into the core language before a program is passed to the interpreter.
For example, the let special form is equivalent to a call expression that begins with a lambda expression. Both create a new frame extending the current environment and evaluate a body within that new environment. Feel free to revisit Problem 15 as a refresher on how the let form works.
(let ((a 1) (b 2)) (+ a b))
;; Is equivalent to:
((lambda (a b) (+ a b)) 1 2)
These expressions can be represented by the following diagrams:
Let Lambda
let lambda
Use this rule to implement a procedure called let-to-lambda that rewrites all let special forms into lambda expressions. If we quote a let expression and pass it into this procedure, an equivalent lambda expression should be returned: pass it into this procedure:
scm> (let-to-lambda '(let ((a 1) (b 2)) (+ a b)))
((lambda (a b) (+ a b)) 1 2)
scm> (let-to-lambda '(let ((a 1)) (let ((b a)) b)))
((lambda (a) ((lambda (b) b) a)) 1)
In order to handle all programs, let-to-lambda must be aware of Scheme syntax. Since Scheme expressions are recursively nested, let-to-lambda must also be recursive. In fact, the structure of let-to-lambda is somewhat similar to that of scheme_eval--but in Scheme! As a reminder, atoms include numbers, booleans, nil, and symbols. You do not need to consider code that contains quasiquotation for this problem.
(define (let-to-lambda expr)
(cond ((atom? expr) )
((quoted? expr) )
((lambda? expr) )
((define? expr) )
((let? expr) )
(else )))
CODE:
; Returns a function that checks if an expression is the special form FORM
(define (check-special form)
(lambda (expr) (equal? form (car expr))))
(define lambda? (check-special 'lambda))
(define define? (check-special 'define))
(define quoted? (check-special 'quote))
(define let? (check-special 'let))
;; Converts all let special forms in EXPR into equivalent forms using lambda
(define (let-to-lambda expr)
(cond ((atom? expr)
; BEGIN PROBLEM 19
'replace-this-line
; END PROBLEM 19
)
((quoted? expr)
; BEGIN PROBLEM 19
'replace-this-line
; END PROBLEM 19
)
((or (lambda? expr)
(define? expr))
(let ((form (car expr))
(params (cadr expr))
(body (cddr expr)))
; BEGIN PROBLEM 19
'replace-this-line
; END PROBLEM 19
))
((let? expr)
(let ((values (cadr expr))
(body (cddr expr)))
; BEGIN PROBLEM 19
'replace-this-line
; END PROBLEM 19
))
(else
; BEGIN PROBLEM 19
'replace-this-line
; END PROBLEM 19
)))
Computers and Technology
1 answer:
svet-max [94.6K]3 years ago
7 0
What are you saying at the bottom?
You might be interested in
The command-line interface tells a user that it's ready to receive commands by displaying a specific set of characters called a(
Brrunno [24]

Answer:

B) prompt

Explanation:

Prompt tells a user that it's ready to receive commands by displaying a specific set of characters.

For example in <em>windows</em> it can be:

C:\Temp>, The prompt states that user is currently in <em>C </em>drive <em>Temp</em> directory.

in <em>Linux </em>based operating systems it can be:

[email protected]:~/Documents$

where it is in the format [email protected]:~directory$

5 0
3 years ago
What is the focus of developers interested in the Internet of Things?
zhuklara [117]

Answer: A. Converting electrical devices into programmable appliances

Explanation:

4 0
4 years ago
Read 2 more answers
Tuple in Python code help pleaseee!!! And of course I'll make you as Branlist
GuDViN [60]

<u>Question 9:</u>

The correct answer would be either (b) or (d).

<u>Question 10:</u>

<u></u>

The correct answer would be (b).

Hope it helps. :)

7 0
3 years ago
Tom and Jerry opened a new lawn service. They provide three types of services: mowing, fertilizing, and planting trees. The cost
vaieri [72.5K]

Answer:

INPUT area of the lawn

INPUT number of fertilizing applications

INPUT number of trees to be planted

SET bill = (35 x area of the lawn/5000) + (30 x number of fertilizing applications) + (50 x number of trees to be planted)

PRINT bill

Explanation:

Ask the user to enter the area of the lawn, the number of fertilizing applications, and the number of trees to be planted

Calculate the bill

Print the bill

5 0
4 years ago
A tortoise is walking in the desert. It walks for 6 minutes at a speed of 7.68 meters per minute. How many meters does it walk?​
stiks02 [169]
The tortoise walked 46.08 meters
6 0
3 years ago
Other questions:
  • An engineer is assigned the task of reducing the air pollutants being released from a power plant that generates electricity by
    9·1 answer
  • when applying styles to a document, which features of the style can be modified in the themes grouping?
    9·2 answers
  • Which of the following is ideal for long distance communication ?
    5·1 answer
  • An attacker has hidden an NFC reader behind an NFC-based kiosk in an airport. The attacker uses the device to capture NFC data i
    12·1 answer
  • Calculator is an example of
    14·1 answer
  • Select three physical forms of storage. USB drive Primary cache Magnetic storage Secondary cache Dynamic RAM Optical drive
    7·2 answers
  • Pls help
    13·1 answer
  • Based on three scores that the user inputs, display the average of the score and the letter grade that is assigned fort he test
    5·1 answer
  • Which three steps might be included in an algorithm for a digital thermostat?
    13·1 answer
  • A ____ attack is much more substantial than a dos attack because of the use of multiple systems to simultaneously attack a singl
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!