Continuations in place of exceptions

Assignment Help Basic Computer Science
Reference no: EM13963490

Continuations

In addition to continuations that represent the "normal" continued execution of a program, we can use continuations in place of exceptions. For example, consider the following function f that raises an exception when the argument x is too small:

exception Too Small;

fun f(x) = if x<> then raise Too Small else x/2; (1 + f(y)) handle Too Small => 0;

If we use continuations, then f could be written as afunction with two extra arguments, one for normal exit and the other for "exceptional exit," to be called if the argument is too small:

fun f(x, k normal, k exn) = if x normal(x/2); f(y, (fn z => 1+z), (fn () => 0));

(a) Explain why the ?nal expressions in each program fragment will have the same value for any value of y.

(b) Why would tail call optimization be helpful when we use the second style of programming instead of exceptions?

Reference no: EM13963490

Questions Cloud

What are the capacity implications of the marketing campaign : Suppose that AlwaysRain Irrigation's marketing department will undertake an intense ad campaign for the bronze sprinklers, which are more expensive but also more durable than the plastic ones. What are the capacity implications of the marketing cam..
Which of the following statements is necessarily true : If the temperature of the contents is increased by 10 C degrees, the reading on the Kelvin thermometer should increase by 273 K
What is covalent bonding : What is covalent bonding? why is it different from ionic bonds?
Calculate the first order energy shifts for the ground : Consider a particle in the one dimensional infinite square well potential with width L. The perturbation potential W(x) = b sin(xpi/L) is added to the bottom of the infinite well. Calculate the first order energy shifts for the ground and first e..
Continuations in place of exceptions : In addition to continuations that represent the "normal" continued execution of a program, we can use continuations in place of exceptions. For example, consider the following function f that raises an exception when the argument x is too small:
Control flow and memory management : An exception aborts part of a computation and transfers control to a handler that was established at some earlier point in the computation.
The reaction involved in the purification of nickel : The reaction involved in the purification of nickel is given below. Ni(s) + x CO(g) → Ni(CO)x(g)
Discuss the innovation involved in product development : Choose a product that they are interested in or provides the required information to discuss the innovation involved in its development - What aspect of the technology influenced the development and the products
Ealuation order and exceptions : Suppose we add an exception mechanism similar to the one used in ML to pure Lisp. Pure Lisp has the property that if every evaluation order for expression e terminates, then e has the same value under every evaluation order. Does pure Lisp with ex..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Why motherboard sometimes support more than one speed

Why does motherboard sometimes support more than one system bus speed? So that it can support different processors running at different speeds.

  What are the functions of the cps

what are the functions of the CPS? (control prossesing system)

  Experiment with computer system measurements

Platform. Pick a Unix-based platform to work on. This might very likely be something like a PC running Linux, but feel free to experiment with whatever system you have access to, e.g., FreeBSD, some old UNIX system like AIX, or even Mac OS X.

  Recognize root-subsystem-functional decomposition diagram

You want to add another column to report showing number of cases still in progress which are over six months old. Also design functional decomposition diagram. Recognize the root and subsystems.

  Which information in computer critical to personal life

Let the information stored in the personal computer. Do you, at this moment, have information stored in your computer that is critical to your personal life?

  Explain how class (static) variables and methods

Explain how class (static) variables and methods differ from their instance counterparts. Give an example of a class that contains at least one class variable and at least one class method. Explain why using a class variable and method rather than an..

  Explain dispatcher and data access object design

Prepare a two page paper comparing and contrasting five of design. Dispatcher - controls client access and re-directs or dispatches client requests to proper party which can be located on same or different tier.

  Compare the running time of this modification

Compare the running time of this modification with that of the original algorithm on sequences that are nearly sorted or reverse sorted, and on sequences with many identical elements. What do you observe?

  Prolog sudoku

Write a Prolog program to solve the 6 by 6 Sudoku puzzle distributed in class. Do not use a solution downloaded from the Internet or elsewhere. Write your own. It should be designed along these lines

  What is the brains of the computer

What is the "brains" of the computer? What is the largest non-stationary component inside a hard drive? Bob has 87 GB of video of his 1 year old learning to walk. If he deletes 99% of it (saving 1%), about how much is left in MB

  Internet service addressing

Are there names or numbers used in Internet Service Addressing (websites, and other Internet applications)? Explain your answer.

  Display a graphical representation of the binary search tree

The program should display a graphical representation of the binary search tree. Show all the leaf nodes; Show all the nodes in PreOrder, InOrder and PostOrder traversals.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd