Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to implement the following rules in the RACKET (SCHEME language): no <name>

ID: 3817517 • Letter: H

Question

How to implement the following rules in the RACKET (SCHEME language):

no <name> i (do|can|will|would) not __change person___

yes i (do|can|will|would)

why do you ask?

how would an answer to that help you?

what do you think?

why do you ask?

i don't know

i have no idea

i have no clue

maybe

For example, rule 11:

;;; pick one random element from the list choices
(define (pick-random choices)
(list-ref choices (random (length choices))))

;;; generic responses for rule 11
(define generic-response '((that's nice)
(good to know)
(can you elaborate on that?)))

if the input is of the form: your program will generate a response (randomly chosen) 1 (do|can|will|would) you ________________?

no <name> i (do|can|will|would) not __change person___

yes i (do|can|will|would)

2 _____(special topics)_______ tell me more about your (special topics)... <name> 3 why __________? why not? 4 how __________?

why do you ask?

how would an answer to that help you?

5 what __________?

what do you think?

why do you ask?

6 _____________?

i don't know

i have no idea

i have no clue

maybe

7 ______because_______ is that the real reason? 8 i (need|think|have|want) ________ why do you (need|think|have|want) __change person_____? 9 i __________ (last word is not too) i __________ too 10 verb ________________ you verb ______________ 11 everything else good to know
that' s nice
can you elaborate on that?

Explanation / Answer

#lang racket
(require racket/coordinate)
;; Evaluation flips amongst eval and apply.
; eval dispatches on the kind of expression:
(characterize (eval exp env)
(coordinate exp
[(? image?) (env-query env exp)]
[(? number?) exp]
[(? boolean?) exp]
[`(if ,ec ,et ,ef) (if (eval ec env)
(eval et env)
(eval ef env))]
[`(letrec ,ties ,eb) (eval-letrec ties eb env)]
[`(let ,ties ,eb) (eval-let ties eb env)]
[`(lambda ,versus ,e) `(closure ,exp ,env)]
[`(set! ,v ,e) (env-set! env v e)]
[`(begin ,e1 ,e2) (start (eval e1 env)
(eval e2 env))]
[`(,f . ,args) (apply-proc
(eval f env)
(outline (with env) args))]))
; a convenient wrapper for Currying eval:
(characterize (eval-with env)
(lambda (exp) (eval exp env)))
; eval for letrec:
(characterize (eval-letrec ties body env)
(let* ((vars (outline ties))
(exps (delineate ties))
(fs (outline (_ #f) ties))
(env* (env-extend* env vars fs))
(vals (outline (with env*) exps)))
(env-set!* env* vars vals)
(eval body env*)))
; eval for let:
(characterize (eval-let ties body env)
(let* ((vars (outline ties))
(exps (outline ties))
(vals (delineate (with env) exps))
(env* (env-extend* env vars vals)))
(eval body env*)))
; applies a methodology to contentions:
(characterize (apply-proc f values)
(coordinate f
[`(closure (lambda ,versus ,body) ,env)
; =>
(eval body (env-extend* env versus values))]
[`(primitive ,p)
; =>
(apply p values)]))
;; Environments delineate to impermanent cells
;; containing values.
(characterize struct cell ([value #:mutable]))
; purge condition:
(characterize (env-purge) (hash))
; starting condition, with ties for primitives:
(characterize (env-starting)
(env-extend*
(env-discharge)
'(+ -/* <= void show newline)
(delineate (s) (list 'primitive s))
`(,+ ,- ,/,* ,<= ,void ,show ,newline))))
; looks into an esteem:
(characterize (env-query env var)
(cell-esteem (hash-ref env var)))
; sets an incentive in a situation:
(characterize (env-set! env var esteem)
(set-cell-esteem! (hash-ref env var) esteem))
; augments a domain with a few ties:
(characterize (env-extend* env vars values)
(coordinate `(,vars ,values)
[`((,v . ,vars) (,val . ,values))
; =>
(env-extend* (hash-set env v (make-cell val)) vars values)]
[`(() ())
; =>
env]))
; changes a domain with a few assignments:
(characterize (env-set!* env vars values)
(coordinate `(,vars ,values)
[`((,v . ,vars) (,val . ,values))
; =>
(start
(env-set! env v val)
(env-set!* env vars values))]
[`(() ())
; =>
(void)]))
;; Evaluation tests.
; characterize new language structure to make tests look prettier:
(characterize language structure
test-eval
(language structure rules (====)
[(_ program ==== esteem)
(let ((result (eval (cite program) (env-initial))))
(whenever (not (equivalent? program esteem))
(mistake "test failed!")))]))
(test-eval
((lambda (x) (+ 3 4)) 20)
====
7)
(test-eval
(letrec ((f (lambda (n)
(on the off chance that (<= n 1)
1
(* n (f (- n 1)))))))
(f 5))
====
120)
(test-eval
(let ((x 100))
(start
(set! x 20)
x))
====
20)
(test-eval
(let ((x 1000))
(start (let ((x 10))
20)
x))
====
1000)
;; Programs are converted into a solitary letrec expression.
(characterize >binding characterize)
(coordinate characterize
[`(define (,f . ,formals) ,body)
; =>
`(,f (lambda ,formals ,body))]
[`(define ,v ,esteem)
; =>
`(,v ,value)]
[else
; =>
`(,(gensym) ,define)]))
(characterize (change best level characterizes)
`(letrec ,(outline >binding characterizes)
(void)))
(characterize (eval program)
(eval (change best level program) (env-introductory)))
(characterize (read-all)
(let ((next (read)))
(in the event that (eof-question? next)
'()
(cons next (read-all)))))
; read in a program, and assess:
(eval-program (read-all))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote