How Many Continuations can Dance on the Head of a Pin Matthias Felleisen King of Continuations and Professor of Computer Science.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

!""""""" "# $t+ W Tl+% $Oo+ OoVo% $ Mo+ Mo+% $+ Q + + % $ + PpBv+% $+ N +n+ % $pP + PpP% $+ +rKb+r% /((((((( () !""""""" "# $t+ W Tl+% $Oo+ OoVo% $ Mo+
E-Commerce CMM503 – Lecture 8 Stuart Watt Room C2.
/ department of mathematics and computer sciencedepartment of mathematics and computer science / architecture of information systems.
Microsoft ® Office Access ® 2007 Training Easy Access with templates I: Create a database susanguggenheim-is.com presents:
Essentials for Design JavaScript Level One Michael Brooks
COM vs. CORBA.
Software Development Languages and Environments. Programming languages High level languages are problem orientated contain many English words are easier.
Compiling Web Scripts for Apache Jacob Matthews Luke Hoban Robby Findler Rice University.
Web Programming Language Week 6 Dr. Ken Cosh PHP Functions & Objects.
Programming Paradigms and languages
Programming the Interactive Web Shriram Krishnamurthi Brown University.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Safety as a Software Metric Matthias Felleisen and Robert Corky Cartwright Rice University.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 42 Web Services.
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
CS2135 Lectures on Script Position. Recap: CGI scripts In the CGI protocol, there is no way to send the result of a script back to the page that invoked.
CS2135 Lectures on Script Position (aka: the “web compiler”)
SCRIPTING LANGUAGE. The first interactive shells were developed in the 1960s to enable remote operation of the first time-sharing systems, and these,
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Chapter 3 Software Two major types of software
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Chapter 9 – Software Evolution and Maintenance
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Building Applications.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
A First Program Using C#
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
K. Jamroendararasame*, T. Matsuzaki, T. Suzuki, and T. Tokuda Department of Computer Science, Tokyo Institute of Technology, JAPAN Two Generators of Secure.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
GDT V5 Web Services. GDT V5 Web Services Doug Evans and Detlef Lexut GDT 2008 International User Conference August 10 – 13  Lake Las Vegas, Nevada GDT.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
JSP Java Server Pages Softsmith Infotech.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
4 Dec 2001Kestrel1 From Patterns to Programming Languages Matthias Felleisen Northeastern University.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
16-Oct-15 JSP Implicit Objects. 2 JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
1 Nov 2001Yale1 Programming Interactive Web Scripts Matthias Felleisen Northeastern University.
Chapter 6 Server-side Programming: Java Servlets
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Client-side processing in JavaScript.... JavaScript history Motivations –lack of “dynamic content” on web pages animations etc user-customised displays.
INTRODUCTION TO WEB APPLICATION Chapter 1. In this chapter, you will learn about:  The evolution of the Internet  The beginning of the World Wide Web,
6 Feb 2002PL Day1 Programming Interactive Web Scripts Matthias Felleisen PLT.
Intermediate 2 Computing Unit 2 - Software Development Topic 2 - Software Development Languages and Environments.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
Introduction to JavaScript Fort Collins, CO Copyright © XTR Systems, LLC Introduction to JavaScript Programming Instructor: Joseph DiVerdi, Ph.D., MBA.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 14 Database Connectivity and Web Technologies.
The Hashemite University Computer Engineering Department
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Cgi programs rise from ash then burn again upon each request.
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Chapter 42 Web Services.
Presentation transcript:

How Many Continuations can Dance on the Head of a Pin Matthias Felleisen King of Continuations and Professor of Computer Science

What does this mean? The theory of continuations (85-95) Phil: “Here is the king of continuations.” The practice of PLT Scheme at ICFP (95-… Dick Gabriel: “Theoreticians just count how many continuations …” It’s really all about the Web. Academia and the Real World

What does this mean? Functions are values like all other values. Continuations are fine values, too. Tail calls are jumps. Macros don’t surprise you. Functions live on a different planet. What’s a continuation? We have do. Who needs protection? It’s really about the Web. Common Lisp and PLT Scheme

What does this mean? The “Orbitz” Problem Programming the Interactive Web Continuations, closures and the Web Academia and the Real World, Again

The Interactive Web and the “Orbitz Problem”

The “Orbitz Problem” The same problem found on Web sites of Microsoft / Apple / … Continental Airlines / Orbitz / Hertz / … the National Science Foundation … … and many other companies

Programming the Interactive Web

The Interactive Web Numerous Web APIs: The Common Gateway Interface (CGI) Java Servlets Active Server Pages, Java Server Pages Scripting languages (Perl, PHP, etc) Microsoft’s Web Services

Printing a Message (Console) (print “Hello, World\n”) (exit)

Printing a Message (Web) (print Test Hello, World! ) (exit)

Do it!.. In DrScheme

Printing Uptime (Console) (print “Uptime: %s\n” (system “uptime”)) (exit)

Printing Uptime (Web) (print Uptime (system “uptime”) ) (exit)

Do it! … In DrScheme …

Area of Circle (Console) (define r (read “Enter radius:” ) (print “area is %d\n” (* 3.14 r r)) (exit)

Area of Circle (Web) Enter radius: (define r (get_binding “radius” bindings)) (print area is (3.14*r*r)

Adding Two Numbers (Console) (define n1 (prompt-read “Enter first:”)) (define n2 (prompt-read “Enter second:”)) (print “sum: %d\n”(+ n1 n2)) (exit)

Adding Two Numbers: User Interfaces Enter first: Enter second: Enter first: Enter second:

Adding Two Numbers: Web Interactions

Adding Two Numbers (Web) Enter first: (define n1 (get “n1 bindings)) …

Adding Two Numbers: The Problem Web scripts write a page, then terminate When the user replies, another script reads the form’s bindings and performs the next step

Adding Two Numbers (Web) Enter first: (define n1 (get_binding “n1” bindings)) … Enter second: (define n2 (get_binding “n2” bindings)) sum: (+ n1 n2)

In Practice System halts cleanly with an error –The user doesn’t get a useful answer –The user may not understand the error –User expended a lot of effort and time Program captures variable by accident (i.e., it implements dynamic scope!), or “internal server error”

Enter second: : n1: Adding Two Numbers (Web) Enter first: (define n1 (get_binding “n1” bindings)) … Enter second: (define n1 (get_binding “n1” bindings)) (define n2 (get_binding “n2” bindings)) sum: (+ n1 n2)

The Actual Form The Addition Page Enter the second number: <form method="get" action="

General Web Programming Problems “Invert” the program Manually tracks hidden fields It’s difficult and mistakes have painful consequences.

Bad News That’s the easy part!

The Real Picture The script and the user are scriptuser Event lines coroutines!

Control Flow: Back Button scriptuserscriptuser A silent action!

Control Flow: Cloning scriptuser scriptuser

Control Flow: Bookmarks scriptuser scriptuser

What Programmers Need “Multiply-resumable and restartable coroutines” No language has exactly this – the new control operator for the Web How do we implement it?

How to Reengineer Programs for the Web Automated Software Engineering 2002 J. Automated Software Engineering 2003

The Legacy Code (define n1 (read “Enter first: ”)) (define n2 (read “Enter second: ”)) (print “sum: %d\n” (+ n1 n2)) (exit)

How we should take this code to the Web (define n1 (read “Enter first: ”)) (define n2 (read “Enter second: ”)) (print “sum: %d\n” (+ n1 n2) (exit) (define n1 (read/web Enter first: )) (define n2 (read/web Enter second: )) (print sum: (+ n1 n2) ) (exit)

But: the program structure is destroyed (define n1 (read/web Enter first: )) (define n2 (read/web Enter second: )) (print sum: (+ n1 n2) )) (exit) (define (main) (print Enter first: )) (define (f1 form) (print <input hidden name=“n1” value= (form-n1 form)> Enter second: )) (define (f2 form) (print The sum is (+ (form-n1 form) (form-n2 form))

The Reengineering Challenge Web interfaces have grown up: from “scripts” to “programs” (or “services”) Need debugging, maintenance, evolution, … We would like a “Web compiler” that automatically –splits programs into procedures by form –propagates fields as needed –preserves behavior yet accommodates “bizarre” control

The Key Insight The manual conversion simply implements the continuation-passing style transformation!

Step 1: Create Function for the “Rest of the Computation” (define n1 (read/web Enter first: )) … n2 … (read/web/k Enter first: (lambda(n1) … n2 …

The Result (read/web/k Enter first: (lambda (n1) (read/web/k Enter second: (lambda(n2) (print sum: (+ n1 n2 ) )

Lift Functions (define (main) (read/web/k Enter first: f1)) (define (f1 n1) (read/web/k Enter second: f2)) (define (f2 n2) (print sum: (+ n1 n2)

Step 2: Propagate Free Variables (define (main) (read/web/k Enter first: f1)) (define (f1 n1) (read/web/k/args n1 Enter second: f2)) (define (f2 n1 n2) = (print sum: (+ n1 n2) )

Convert to Web API (define (f1 n1) (read/web/k/args n1 Enter second: f2)) (define (f1 form) (print <input hidden name=“n1” value=(form-n1 form)> Enter second: ))

Resulting Web Application (define (main) (print Enter first: )) (define (f1 form) (print <input hidden name=“n1” value=(form-n1 form)> Enter second: )) (define (f2 form) (print sum: (+ (form-n1 form) (form-n2 form)) ))

Summary Three transformations: Make all value receivers explicit functions Make all functions top-level, replace free variables with explicit parameters Replace first-class functions with first-order representations

A Remarkable Coincidence These are known as: Continuation-passing style transformation Lambda lifting Closure conversion (to first-order values) You’ve studied them in academic compilers & languages courses, especially when functions are ordinary values.

Can’t Languages do Better? European Symposium on Programming 2001 J. Higher-Order Symbolic Logic 2004 see also: Hughes (1999), Queinnec (ICFP 2000), Thielman (ESOP 2002)

Program Structure Reinstatement (define n1 (read “Enter first: ”)) (define n2 (read “Enter second: ”)) (print “sum: %d\n” (+ n1 n2)) (exit) (define n1 (read/web Enter first: )) (define n2 (read/web Enter second: )) (print sum: (+ n1 n2) (exit) What we have:What we want:

Now What? APIs offer form, cookie, &c primitives Why not an API with read/web ?

Now what? Programmers: Stand up for your rights – make server implementers work harder!

The Real Primitive read/web is a small lie: (define n1 (read/web Enter first: )) We provide send/suspend: (define n1 (send/suspend (lambda (k) Enter first: )) send/suspend generates the URL that resumes computation

Generated URLs send/suspend generates a URL: When a consumer uses this URL, the Web server delivers the filled out form as the result of the call to send/suspend.

And send/suspend is what … … a plain old call-with-current-contiuation.

The PLT Web Server send/suspend associates url’s with continuation objects reading and writing becomes a coroutine action the rest is (interesting) engineering

The Moral of the Story

How Many Continuations can Dance on the Head of a Pin

So what does this mean? Because we have closures and continuations in Scheme and because this motivates us to think about CPS and friends, we can design, implement, and teach robust interactive Web programs easily. Can Common LISPers do it? Paul Graham did it. But with closures and hygienic macros, things would have been so much easier and cleaner.

The End Shriram Krisnamurthi (Brown) Robert Bruce Findler (Chicago) Matthew Flatt (Utah) Paul T. Graunke (Northeastern) Credits …