New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
an experiential introduction to principles of programming languages
An Experiential Introduction To Principles Of Programming Languages 1st Edition Hridesh Rajan - Solutions
Modify the call-by-name Funclang interpreter to implement the call-by-need parameter passing strategy discussed previously.
Extend the syntax and semantics of the Funclang language to add support for the logical conjunction (and) and logical disjunction (or) expressions.
Extend the syntax and semantics of the Funclang language to add support for a switch expression.
In some programming languages such as Scheme, pairs are the basic values and lists are defined in terms of pairs. Define a pair as a 2-tuple and redefine the value relations for list, car, cdr, cons, and null? in terms of pair values.
Extend the Funclang language to support a new expression equal?, which takes two subexpressions and returns #t if their values are equal and #f otherwise.The following interaction log illustrates the semantics of equal:
Extend the Funclang programming language to support a new list comprehension expression. A list comprehension is a concise way of representing higher-order functions that operate over a list. It should have the following syntax:The following interaction log illustrates the list comprehension
Design and implement Heap, a new abstraction representing area in the memory reserved for dynamic memory allocation. For testing, you can assume the capacity of the heap to be 8 KB.The heap abstraction internally maintains a contiguous space of memory and a free list, which is a collection of
Create an example allocation and deallocation test case for heap, which allocates n chunks of memory of size s, where n is size/s. Here, size is the capacity of the heap. The test case then frees every alternate chunk of memory to effectively free approximately half the heap (i.e., zeroth chunk,
Extend the heap abstraction with three operations: allocArray, getAt, and setAt, which allows for treating a chunk of memory as a two-dimensional array. Given the row and column sizes, allocArray allocates a chunk of memory sufficient to hold the array. If contiguous space is not available, the
Allocate a chunk of memory of size 16 cells containing the consecutive natural numbers 1–16 using the alloc and set operations provided by the heap abstraction. Then treat this chunk of memory as a 4 x 4 array and use the setAt operation to set diagonal elements of this array to the value 0.
Extend the Funclang language to add array of numeric values as a new kind of value to the programming language. This would require adding three new kinds of expressions, arrayexp, indexexp, and assignexp. You will also need to generalize the array allocation and access operations for heap from the
The goal of this question is to understand the semantics of the Reflang expressions. Perform the following operations on your implementation of Reflang and explain the output.
Write three Reflang programs that use aliases. Recall that an alias is created when two variables refer to the same memory location.
Modify the Reflang language so that the locations 0, 1, and 2 are treated specially as standard input, standard output, and standard error, respectively. Take the following steps to implement this functionality:1. Modify the heap abstraction so that it allocates memory starting with location 3.2.
Modify the semantics of Reflang to implement a heap abstraction that implements versions of a heap. In a versioned heap, writing to an existing memory location does not overwrite the old value; rather, it creates a new version of that memory location that contains the new value.
This problem is about references and aliasing. In Reflang, an expression like the following creates two aliases (class and course) to the memory cell storing the value 342:Modify the Reflang interpreter so it prints a message when an alias is created. An example appears here:
This question is about a semantic variation of the heap abstraction.A typed heap enforces the property that in a memory location, only values of compatible types can be stored. Two types are compatible if one is the subtype of the other. Extend the Reflang interpreter to support a typed heap.Modify
This question is about a semantic variation of reference-related expressions. A hot heap location is one that is accessed more often by a program.Extend Reflang to support hot store locations. The first step in keeping track of hot store locations is to augment the store locations to have an
This problem is about memory deallocation. In Reflang, the free expression deallocates memory. The current semantics of free expression is permissive, in that it allows a memory location to be deallocated even if it has been deallocated previously.Change the semantics of the free expression such
This problem is about explicit references. In current realization of the Reflang language, arithmetic operations are not permitted on a reference value.1. Modify the semantics of a dereference expression such that it can dereference locations specified as explicit natural numbers. See the
This problem is about explicit references.1. In the previous problem, we enhanced the Reflang language to allow reference arithmetic. Add a new predicate expression, rarith?, to check if an expression uses reference arithmetic during its evaluation.The expression rarith? follows the grammar shown
This problem is about reachability, which is an important concept for automatic memory management. Given a name, the set of reachable memory locations includes those that can be accessed directly or indirectly using that name. For instance, for the following expression, the reachable memory
Our concurrency model includes facilities for creating a collection of tasks and mutually exclusive access to memory locations.These facilities can be used to model synchronization between two tasks, typically known as join. For example, consider join, an expression that allows a current task to
Extend the fork expression in the language of this chapter to be able to create two or more concurrent tasks, instead of exactly two concurrent tasks.
In the Forklang language, it is possible for a task to access a memory location without acquiring a lock first. This makes it possible for a task to introduce errors in the execution of another task, even if that other task properly acquires and releases locks. Modify the semantics of heap read and
The following problems relate to data races in Forklang programs.1. Write a Forklang function that creates a location in the heap, stores an empty list at that location, and assigns the name “buffer.”Following this, the program forks two concurrent tasks: the first task replaces the value
The following problems are about deadlocks in Forklang programs:1. Write a Forklang function that creates three references and assigns them the name ‘a’, ‘b’, and ‘c’. After creating these three references, the program forks three concurrent tasks: the first task acquires a lock on
Forklang supports the locking and unlocking of locks to synchronize accesses (read and write) to memory.Languages like Java provide higher-level synchronization mechanisms such as synchronized methods or blocks. A synchronized method of an object locks the object at the beginning of the execution
Our realization of the Forklang language maintained a shared heap. Those program expressions that assess heap directly manipulated this shared heap. This design had the advantage that it avoided having to pass around the heap object (similar to environments). The main disadvantage of this design
Our realization of the Forklang language creates two threads. In some programming languages, fork creates a separate process (i.e., the forked task and the original task do not share memory). In this exercise, you will gradually modify the Forklang interpreter to implement processes.[Heap clone]
Write five examples of well-typed and ill-typed programs that use all the arithmetic expressions.
For some expressions such as (/ x 0), where 0 appears as an immediate subexpression, it is easy to check for and eliminate divide-by-zero errors. Enhance the typechecking rule for the division expression so that the type-system is able to detect and remove such errors, where 0 is an immediate
More practice with types in Typelang:1. Check this let expression, explain why it is well typed, and write its type.2. Check this let expression, explain why it is well typed, and write its type.3. Check this lambda expression, explain why it is well typed, and write its type.4. Check this lambda
Explain the following typechecking errors in Typelang programs: 1. Check this let expression, explain why it is ill typed, and specify the typechecking rule that will detect the error.What did the typechecking rule expect, and what did it find?2. Check this let expression, explain why it is ill
Write a specification for the sumcubes function, as shown here:
Write a specification for the function find shown here:
Write a more detailed specification for the function append shown here, which uses specification cases to make four separate instances of the function explicit in the specification:when lst1 is empty and lst2 is empty, when lst1 is empty and lst2 is nonempty, when lst1 is nonempty and lst2 is
When writing specifications, it is helpful to have access to the values of the variables in the precondition state (i.e., when the function body has not run). In some specification languages, the precondition state is also referred to as the old state. Extend Speclang to add the ability to access
Invariants are conditions that hold throughout a computation. Invariants are useful for specifying data structures since there are certain constraints that must always hold for the data structure. Such invariants are called data structure invariants.Invariants are also useful for loops in the
It is often desirable to make assertions about the set of memory locations that a function is allowed to modify. Other memory locations remain unchanged. A specification language typically provides features to identify memory locations that might be modified by a function.Add the modifies feature
Write a Msglang program that declares a process that, when sent a number n as a message, prints n, and then sends itself n-1 as a message. This countdown terminates when n is 0.
Write a Msglang program that models a state machine. If the process receives an message containing number 0 followed by another message containing number 1, it prints “accept.” Otherwise, it prints “reject.”
Using Msglang features, define a processbased sorting structure for positive and negative numbers. This structure will consist of four bins represented as global references(posevenbin, posoddbin, negevenbin, negoddbin), each of which holds a list of numbers. Each bin is initially an empty list. The
In the current design of Msglang, the receive expression fails if the cardinality of the received message doesn’t match with the expected cardinality of the sent message. That might seem overly restrictive to some. If the sender sends more values then the receiver needs, known as wider messages,
If there are two receive expressions in the body of a process expression, and the first receive expression is expecting a message with two fields and the second receive expression is expecting a message with three fields, then the receive message will fail if the sender that is sending a message
Design and implement a variation of ProcExp and SendExp that supports prioritized message processing. Each message includes priority as its first field, a positive integer, where lower numbers mean higher priority. Each process consumes its incoming messages in the order of priority (i.e.,
In the current design of Msglang, the receive expression fails if the cardinality of the received message doesn’t match with the expected cardinality of the sent message. In practice, stronger guarantees might be necessary. Design and implement a typed variation of the receive expression in which
In the current design of Msglang, a send expression transmits a message to the receiver and proceeds without waiting for a response from the recipient. This messagedelivery style is called asynchronous message send or nonblocking send. At a future time, the recipient might not receive the actual
Design and implement a variation of Msglang in which each process has its own heap. Creating a process creates the heap of that process. Then, implement two variations of the send expression, as follows:In the first variation, prohibit the send expression from sending any reference values, whether
A process is a garbage process if it is not performing independent computation, it is blocked to receive a message from another process, and there are no other processes that can send the process a message to unblock it. Such processes can consume resources without performing any meaningful work.
Write a Eventlang program that declares an event, CountDown, that accepts a single context variable, n. Register a handler with this event such that when the event is announced with the number n as the payload, the handler prints the number n and announces another event, CountDown with n-1, as the
Write an Eventlang program that models a vending machine that dispenses four objects: milk, cookies, chocolate, and candy. The vending machine accepts an amount, dispenses the appropriate product, and gives change. Milk costs $1, cookies cost $0.75, chocolate costs $0.50, and candy costs $0.25.The
Using Eventlang features, define an event-based sorting structure for positive and negative numbers. This structure will consist of four bins represented as global references (posevenbin, posoddbin, negevenbin, and negoddbin), each of which holds a list of numbers. Each bin is initially an empty
The goal of this question is to learn about a variation of event-driven programming language features. A common variation of event support in languages and libraries allows programmers to specify a priority among observers, and the observers run according to the specified priority. A common usage
The goal of this question is to learn about another variation of event-driven features by extending the semantics of the Eventlang language. We will learn about announce expressions that return results of all observers, which is different from the announce expressions that we have been seeing so
The goal of this question is to extend the Eventlang interpreter to add expressions for unregistering an observer expression. So far, we have only discussed registering an observer expression using the when expression, but once registered, the observer expression cannot be removed. Some programming
Showing 100 - 200
of 156
1
2
Step by Step Answers