Programming Languages

Similar documents
CS2 Current Technologies Lecture 2: SQL Programming Basics

Real-World Performance Training SQL Introduction

CS2 Current Technologies Lecture 3: SQL - Joins and Subqueries

King Fahd University of Petroleum and Minerals

CS2 Current Technologies Note 1 CS2Bh

Department of Computer Science and Information Systems, College of Business and Technology, Morehead State University

Database Management System. * First install Mysql Database or Wamp Server which contains Mysql Databse.

Pivot Tables Motivation (1)

Informatics Practices (065) Sample Question Paper 1 Section A

Introduction. Introduction to Oracle: SQL and PL/SQL

Part III. Data Modelling. Marc H. Scholl (DBIS, Uni KN) Information Management Winter 2007/08 1

Table : Purchase. Field DataType Size Constraints CustID CHAR 5 Primary key CustName Varchar 30 ItemName Varchar 30 PurchaseDate Date

RDBMS Using Oracle. BIT-4 Lecture Week 3. Lecture Overview

Introduc.on to Databases

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

SQL Structured Query Language Introduction

Topic 8 Structured Query Language (SQL) : DML Part 2

CS Reading Packet: "Views, and Simple Reports - Part 1"

Database implementation Further SQL


Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Slide 17-1

TO_CHAR Function with Dates

CS Reading Packet: "Writing relational operations using SQL"

Overview of PL/SQL. About PL/SQL. PL/SQL Environment. Benefits of PL/SQL. Integration

Objectives. After completing this lesson, you should be able to do the following:

1 SQL Structured Query Language

CS345 Project Presentation

SQL. - single row functions - Database Design ( 데이터베이스설계 ) JUNG, Ki-Hyun ( 정기현 )

7/17/2018. Copyright 2016, Oracle and/or its affiliates. All rights reserved. 2

1 SQL Structured Query Language

The Seven Case Tables

KENDRIYA VIDYALAYA ALIGANJ SHIFT-II HOLIDAY HOMEWORK CLASS-XII INFORMATICS PRACTICES

CIS Reading Packet: "Views, and Simple Reports - Part 1"

Database Compatibility for Oracle Developers Tools and Utilities Guide


Creating and Managing Tables Schedule: Timing Topic

Practical Workbook Database Management Systems

NURSING_STAFF NNbr NName Grade

CIS Week 11 Lab Exercise p. 1 Fall 2009

Q5 Question Based on SQL & Database Concept Total Marks 8. Theory Question 2 Marks / SQL Commands 6 Marks / Output of commands 2 Marks

GIFT Department of Computing Science. [Spring 2016] CS-217: Database Systems. Lab-3 Manual. Single Row Functions in SQL

Autonomous Transactions

a 64-bit Environment Author: Rob procedures. SSIS servers. Attunity.

Oracle Database 18c. Gentle introduction to Polymorphic Tables Functions with Common patterns and sample use cases

Programming Languages. Dr. Philip Cannata 1

Active Databases Part 1: Introduction CS561

Relational Database Management Systems Oct I. Section-A: 5 X 4 =20 Marks

Power Up Your Apps with Recursive Subquery Factoring. Jared Still 2014

THE INDIAN COMMUNITY SCHOOL, KUWAIT

Miguel Anjo (IT/ADC)

Create Rank Transformation in Informatica with example

Databases IIB: DBMS-Implementation Exercise Sheet 13

Q1. (SQL) Consider the following table HOSPITAL. Write SQL commands for the statements (i) to (v)

: ADMINISTRATION I EXAM OBJECTIVES COVERED IN THIS CHAPTER:

Relational Database Management Systems Mar/Apr I. Section-A: 5 X 4 =20 Marks

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

Database Compatibility for Oracle Developers Tools and Utilities Guide

Practical Workbook Database Management Systems

SQL. Char (30) can store ram, ramji007 or 80- b

Definitions. Database Architecture. References Fundamentals of Database Systems, Elmasri/Navathe, Chapter 2. HNC Computing - Databases

11 things about Oracle Database 11g Release 2. Thomas Kyte

ajpatelit.wordpress.com

What are temporary tables? When are they useful?

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until

Trigger is a stored procedure which is called implicitly by oracle engine whenever a insert, update or delete statement is fired.

5 Integrity Constraints and Triggers

Oracle REST Data Services Quick Start Guide. Release 17.4

Q.1 Short Questions Marks 1. New fields can be added to the created table by using command. a) ALTER b) SELECT c) CREATE. D. UPDATE.

Objectives. After completing this lesson, you should be able to do the following:


@vmahawar. Agenda Topics Quiz Useful Links

Tuning Considerations for Different Applications Lesson 4

Database Programming with SQL

Oracle 12c New Features For Developers

CS Reading Packet: "Simple Reports - Part 2"

PL/SQL User s Guide and Reference

C. Use the TO_CHAR function around SYSDATE, that is, 1_date := TO_CHAR (SYSDATE).

ACCESS isn t only a great development tool it s

<Insert Picture Here> Oracle Database 11g: Neue Features im Oracle Optimizer

GET POST ORDS JSON: Web Services for APEX Decoded

Chapter _CH06/CouchmanX 10/2/01 1:32 PM Page 259. Manipulating Oracle Data

INDEX. 1 Introduction. 2 Types of Cursors 2.1 Explicit cursor 2.2 Attributes 2.3 Implicit cursor 2.4 Attributes. 3 Parameterized cursor

Infrastructure at your Service. In-Memory-Pläne für den 12.2-Optimizer: Teuer oder billig?

Expert Oracle Database Architecture

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.

Tables From Existing Tables

Partitioning. The Uses of Partitioning

Question Bank. Class : XII( ) Subject : Informatics Practices(065)

Using RESTfull services and remote SQL

Databases - 3. Null, Cartesian Product and Join. Null Null is a value that we use when. Something will never have a value

Appendix C. Database Administration. Using SQL. SQL Statements. Data Definition Statements (DDL)

Maintaining Data 3.3.1

Downloaded from

SYSTEM CODE COURSE NAME DESCRIPTION SEM

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

Database Programming with SQL 5-1 Conversion Functions. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

P.G.D.C.M. (Semester I) Examination, : ELEMENTS OF INFORMATION TECHNOLOGY AND OFFICE AUTOMATION (2008 Pattern)

Crystal Reports. Overview. Contents. Oracle Stored Procedures and Crystal Reports

SQL Simple Queries. Chapter 3.1 V3.01. Napier University

Michigan Tech University Banner Finance Self-Service User Guide. Revised 1/11/17

Transcription:

Programming Languages Chapter 19 - Continuations Dr. Philip Cannata 1

Exceptions (define (f n) (let/cc esc (/ 1 (if (zero? n) (esc 1) n)))) > (f 0) 1 > (f 2) 1/2 > (f 1) 1 > Dr. Philip Cannata 2

Exceptions (define (f n) (let/cc esc (/ 1 (if (zero? n) (esc 1) n)))) When you invoke the continuation, it s as if the entire let/cc expression that binds esc should be cut out of the program and replaced with the value passed to esc, i.e., its as if the actual code for f is really this: (define (f n) 1) Dr. Philip Cannata 3

Escaping Procedures (define (f n) (+ n (let/cc k (- 5 (k 5))))) > (f 6) 11 > Dr. Philip Cannata 4

(define route-producer (local ([define resume (box false)]) (lambda (real-send) (local ([define send (lambda (value-to-send) (let/cc k (set-box! resume k) ((unbox resume) 'dummy) (send 'providence) (send 'houston) (send 'bangalore))))))) Producers and Consumers We ll see these (real-send value-to-send))))]) details in a few slides 'providence 'houston 'bangalore 'dummy Dr. Philip Cannata 5

Producers and Consumers Oracle sequence example CREATE TABLE EMP (EMPNO NUMBER(7) NOT NULL, CONSTRAINT emp_pkey PRIMARY KEY (empno), ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7, 2), COMM NUMBER(7, 2), DEPTNO NUMBER(2)); drop sequence emp_empno; create sequence emp_empno start with 1 increment by 1 nomaxvalue; create or replace trigger emp_empno_trigger before insert on emp for each row begin select emp_empno.nextval into :new.empno from dual; end; INSERT INTO EMP VALUES (7369, 'SMITH', 'CLERK', 7902, TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, 20); INSERT INTO EMP VALUES (7499, 'ALLEN', 'SALESMAN', 7698, TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30); INSERT INTO EMP VALUES (7521, 'WARD', 'SALESMAN', 7698, TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30); INSERT INTO EMP VALUES (7566, 'JONES', 'MANAGER', 7839, TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20); INSERT INTO EMP VALUES (7654, 'MARTIN', 'SALESMAN', 7698, TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30); INSERT INTO EMP VALUES (7698, 'BLAKE', 'MANAGER', 7839, TO_DATE('1-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30); INSERT INTO EMP VALUES (7782, 'CLARK', 'MANAGER', 7839, TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10); INSERT INTO EMP VALUES (7788, 'SCOTT', 'ANALYST', 7566, TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20); INSERT INTO EMP VALUES (7839, 'KING', 'PRESIDENT', NULL, TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10); INSERT INTO EMP VALUES (7844, 'TURNER', 'SALESMAN', 7698, TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500, NULL, 30); INSERT INTO EMP VALUES (7876, 'ADAMS', 'CLERK', 7788, TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20); INSERT INTO EMP VALUES (7900, 'JAMES', 'CLERK', 7698, TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 950, NULL, 30); INSERT INTO EMP VALUES (7902, 'FORD', 'ANALYST', 7566, TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20); INSERT INTO EMP VALUES (7934, 'MILLER', 'CLERK', 7782, TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10); Dr. Philip Cannata 6

Producers and Consumers Oracle sequence example Dr. Philip Cannata 7

(define (f n) (let/cc esc (/ 1 (if (zero? n) (esc 1) n)))) Continuations 1. When you invoke the continuation, it s as if the entire let/cc expression that binds esc should be cut out of the program and replaced with the value passed to esc, i.e., its as if the actual code for f is really this: (define (f n) 1) 2. let/cc binds its variable to the next sexp when it is invoked. 3. let/cc causes the interpreter to revert to the state that it was in when the let/cc was defined when the let/cc variable is invoked. Dr. Philip Cannata 8

(define (route-producer send) (send 'providence) (send 'houston) (send 'bangalore))) Producers and Consumers > (route-producer display) providencehoustonbangalore 'providence 'providence Dr. Philip Cannata 9

Producers and Consumers (define route-producer (local ([define resume (box false)]) (lambda (send) ((unbox resume) 'dummy) (send 'providence) (send 'houston) (send 'bangalore)))))) 'providence 'providence Dr. Philip Cannata 10

Producers and Consumers (define route-producer (local ([define resume (box false)]) (lambda (send) ((unbox resume) 'dummy) (send (unbox resume)) (send 'houston) (send 'bangalore)))))) false > Dr. Philip Cannata 11

(define route-producer (local ([define resume (box false)]) (lambda (real-send) (local ([define send (lambda (value-to-send) (let/cc k (set-box! resume k) (real-send value-to-send))))]) ((unbox resume) 'dummy) (send 'providence) (send 'houston) (send 'bangalore))))))) Producers and Consumers > (let/cc q (route-producer q)) 'providence > (let/cc q (route-producer q)) 'houston > (let/cc q (route-producer q)) 'bangalore > (let/cc q (route-producer q)) 'dummy Dr. Philip Cannata 12

(define route-producer (local ([define resume (box false)]) (lambda (real-send) (local ([define send (lambda (value-to-send) (let/cc k (set-box! resume k) (real-send value-to-send))))]) ((unbox resume) 'dummy) (send 'providence) (send 'houston) (send 'bangalore))))))) Producers and Consumers > (route-producer display) providencehoustonbangalore > (route-producer display) 'dummy > (route-producer display) 'dummy Dr. Philip Cannata 13

(define route-producer (local ([define resume (box false)]) (lambda (real-send) (local ([define send (lambda (value-to-send) (let/cc k (set-box! resume k) (real-send value-to-send))))]) ((unbox resume) 'dummy) (send 'providence) (send 'houston) (send 'bangalore))))))) > (let/cc q (route-producer q)) 'providence > (let/cc q (route-producer q)) 'houston > (let/cc q (route-producer q)) 'bangalore > (let/cc q (route-producer q)) 'dummy Producers and Consumers Run 1. and then run 2. Then restart and just run 2. 1. What will this do? (let ((a 1)) (display (let/cc q (route-producer q))) (display a) (display " ") (let ((a 2)) (display a))) 2. What will this do? (let ((a 1)) (display (let/cc q (route-producer q))) (display a) (display " ") (let ((a 2)) (route-producer display) (display a))) Dr. Philip Cannata 14

Producers and Consumers (define (make-producer body) (define resume (box false)) (lambda (real-send) (define send-to (box real-send)) (define (send value-to-send) (set-box! send-to (let/cc k (set-box! resume k) ((unbox send-to) value-to-send))))) ((unbox resume) real-send) (body send)))) (define number-producer (make-producer (lambda (send) (send 1) (send 2) (send 3))))) (define get call/cc) (get number-producer) press Run > (+ (get number-producer) (get number-producer) (get number-producer) ) 6 > press Run > (+ (get number-producer) (get number-producer) (get number-producer) (get number-producer)).. user break > Dr. Philip Cannata 15

(define (make-producer body) (define resume (box false)) (lambda (real-send) (define send-to (box real-send)) (define (send value-to-send) (set-box! send-to (let/cc k (set-box! resume k) ((unbox send-to) value-to-send))))) ((unbox resume) real-send) (body send)))) (define (odds-producer-body send) (local ([define (loop n) (send n) (loop (+ n 2)))]) (loop 1))) (define odds-producer (make-producer odds-producer-body)) (define (get producer) (let/cc k (producer k))) Producers and Consumers press Run > (+ (get odds-producer) (get odds-producer) (get odds-producer) (get odds-producer) (get odds-producer)) 25 > Dr. Philip Cannata 16

(define (make-producer body) (define resume (box false)) (lambda (real-send) (define send-to (box real-send)) (define (send value-to-send) (set-box! send-to (let/cc k (set-box! resume k) ((unbox send-to) value-to-send))))) ((unbox resume) real-send) (body send)))) (define (integer-producer-body send) (local ([define (loop n) (send n) (loop (+ n 1)))]) (loop 1))) (define integer-producer (make-producer integer-producer-body)) (define (get producer) (let/cc k (producer k))) Producers and Consumers (define (Loop n) (define integer-producer (make-producer integer-producer-body)) (define List (box (list))) (let y ((x n)) (set-box! List (cons (get integer-producer) (unbox List ))) (if (> x 1) (y (- x 1) ) (display (unbox List)) (newline) (eval (cons '* (unbox List))))))) Dr. Philip Cannata 17