Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following question in racket language. The template is provided below. The answer should strictly follow the template. *Solutions are expected to only

Please answer the following question in racket language. The template is provided below. The answer should strictly follow the template. *Solutions are expected to only use functions from the standard library that was given* image text in transcribed Solution Template

#lang racket (require "ast.rkt") (require "hw1.rkt") (require rackunit) (provide (all-defined-out))

;; Exercise 1.a: Read-write cell ;; Solution has 3 lines. (define (rw-cell x) 'todo)

;; Exercise 1.b: Read-only cell ;; Solution has 4 lines. (define (ro-cell x) 'todo)

1. (15 points) Your goal is to implement a memory cell encoded with functions as data. A memory cell is a function that takes a list as its only argument. The list may have zero or one elements. If the list has one element, then we are setting the value of the memory cell. Setting the value of a memory cell returns a new memory cell If the list is empty, then we are getting the value contained in the memory cell. The following definitions abstract these notions: (define (cell-get c) (c (list))) (define (cell-set cx) (c (list x))) (a) (7.5 points) Implement a read-write cell. Function r-cell takes a number that initializes the memory cel Operation set returns a new cell with the value given. Operation get returns the contents of the cell (define w1 (rv-cell 10)) (check-equal? 10 (cell-get w1)) (define w2 (cell-set w1 20)) (check-equal? 20 (cell-get w2)) (b) (7.5 points) Implement a read-only cell. Function ro-cell takes a number and return a read-only cell. Putting a value in a read-only cell should not change the stored value. Getting a value should always return the initial value. (define ri (ro-cell 10)) (check-equal? 10 (cell-get r1)) (define r2 (cell-set r1 20)) (check-equal? 10 (cell-get r2)) 1. (15 points) Your goal is to implement a memory cell encoded with functions as data. A memory cell is a function that takes a list as its only argument. The list may have zero or one elements. If the list has one element, then we are setting the value of the memory cell. Setting the value of a memory cell returns a new memory cell If the list is empty, then we are getting the value contained in the memory cell. The following definitions abstract these notions: (define (cell-get c) (c (list))) (define (cell-set cx) (c (list x))) (a) (7.5 points) Implement a read-write cell. Function r-cell takes a number that initializes the memory cel Operation set returns a new cell with the value given. Operation get returns the contents of the cell (define w1 (rv-cell 10)) (check-equal? 10 (cell-get w1)) (define w2 (cell-set w1 20)) (check-equal? 20 (cell-get w2)) (b) (7.5 points) Implement a read-only cell. Function ro-cell takes a number and return a read-only cell. Putting a value in a read-only cell should not change the stored value. Getting a value should always return the initial value. (define ri (ro-cell 10)) (check-equal? 10 (cell-get r1)) (define r2 (cell-set r1 20)) (check-equal? 10 (cell-get r2))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago