Growing a Language from the Inside Out Theo D’Hondt

Growing a Language from the Inside Out

Francqui Chair - 2010

Inaugural Lecture - 19 March 2010

Theo D’Hondt Software Languages Lab Faculty of Sciences - Vrije Universiteit Brussel

http://soft.vub.ac.be

Francqui Chair - 2010 1 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Francqui Chair - 2010 2 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Francqui Chair - 2010 2 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Converting to MP3

Francqui Chair - 2010 2 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Francqui Chair - 2010 3 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Compiling a big project

Francqui Chair - 2010 3 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Francqui Chair - 2010 4 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Compiling a small project

Francqui Chair - 2010 4 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Francqui Chair - 2010 5 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Application with green threads

Francqui Chair - 2010 5 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Francqui Chair - 2010 6 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Simple Experiment

Application without threads

Francqui Chair - 2010 6 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt The infamous “law” of Moore

Francqui Chair - 2010 7 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt The infamous “law” of Moore

This is a law of human ingenuity, not a law of nature

Francqui Chair - 2010 7 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt The infamous “law” of Moore

This is a law of human ingenuity, not a law of nature

This law has hit a law of nature

Francqui Chair - 2010 7 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt The infamous “law” of Moore

This is a law of human ingenuity, not a law of nature

This law has hit a law of nature

Ingenuity has kicked in again, but in a different direction

Francqui Chair - 2010 7 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Computer{Engineering|Science}

Replication instead of Miniaturization

Concurrency becomes the Default

Francqui Chair - 2010 8 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Technology Response

Multi-core processors Hyperthreading Multi-level caching

Francqui Chair - 2010 9 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt An Apt Quote ...

“Software gets slower, faster than hardware gets faster”

Niklaus Wirth, 1995

Francqui Chair - 2010 10 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt The General Feeling of Security

Francqui Chair - 2010 11 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt The General Feeling of Security

Shmuel Katz CS department Technion

Francqui Chair - 2010 11 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt The General Feeling of Security

Shmuel Katz CS department Technion

Francqui Chair - 2010 11 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt History repeats itself

Francqui Chair - 2010 12 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt History repeats itself

Francqui Chair - 2010 12 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt History repeats itself

Francqui Chair - 2010 12 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt History repeats itself

Anno 1990

Francqui Chair - 2010 12 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Occam = Instantiation of CSP

grams, three basic constructs have received widespread recognition and use: A repetitive construct (e.g. the while loop), an alternative construct (e.g. the conditional if..then..else), and normal sequential program composi- Programming S. L. Graham, R. L. Rivest tion (often denoted by a semicolon). Less agreement has Teclmiques Editors been reached about the design of other important pro- gram structures, and many suggestions have been made: Communicating Subroutines (Fortran), procedures (Algol 60 [15]), entries (PL/I), coroutines (UNIX [171), classes (SIMULA 67 [5]), Sequential Processes processes and monitors (Concurrent Pascal [2]), clusters (CLU [13]), forms (ALPHARD [19]), actors (Hewitt [1]). .A.R. Hoare The traditional stored program digital computer has The Queen's University been designed primarily for deterministic execution of a Belfast, Northern Ireland single sequential program. Where the desire for greater speed has led to the introduction of parallelism, every attempt has been made to disguise this fact from the This paper suggests that input and output are basic programmer, either by hardware itself (as in the multiple primitives of programming and that parallel function units of the CDC 6600) or by the software (as composition of communicating sequential processes is a in an I/O control package, or a multiprogrammed op- fundamental program structuring method. When erating system). However, developments of processor combined with a development of Dijkstra's guarded technology suggest that a multiprocessor machine, con- command, these concepts are surprisingly versatile. structed from a number of similar self-contained proc- Their use is illustrated by sample solutions of a variety essors (each with its own store), may become more of familiar programming exercises. powerful, capacious, reliable, and economical than a Key Words and Phrases: programming, machine which is disguised as a monoprocessor. programming languages, programming primitives, In order to use such a machine effectively on a single program structures, parallel programming, concurrency, task, the component processors must be able to com- input, output, guarded commands, nondeterminacy, municate and to synchronize with each other. Many coroutines, procedures, multiple entries, multiple exits, methods of achieving this have been proposed. A widely classes, data representations, recursion, conditional adopted method of communication is by inspection and critical regions, monitors, iterative arrays updating of a common store (as in Algol 68 [18], PL/I, CR Categories: 4.20, 4.22, 4.32 and many machine codes). However, this can create severe problems in the construction of correct programs and it may lead to expense (e.g. crossbar switches) and 1. Introduction unreliability (e.g. glitches) in some technologies of hard- ware implementation. A greater variety of methods has Among the primitive concepts of computer program- been proposed for synchronization: semaphores [6], ming, and of the high level languages in which programs events (PL/I), conditional critical regions [10], monitors are expressed, the action of assignment is familiar and and queues (Concurrent Pascal [2]), and path expressions well understood. In fact, any change of the internal state [3]. Most of these are demonstrably adequate for their of a machine executing a program can be modeled as an purpose, but there is no widely recognized criterion for assignment of a new value to some variable part of that choosing between them. machine. However, the operations of input and output, This paper makes an ambitious attempt to find a which affect the external environment of a machine, are single simple solution to all these problems. The essential not nearly so well understood. They are often added to proposals are: a programming language only as an afterthought. (1) Dijkstra's guarded commands [8] are adopted (with Among the structuring methods for computer pro- a slight change of notation) as sequential control struc- General permission to make fair use in teaching or research of all tures, and as the sole means of introducing and control- or part of this material is granted to individual readers and to nonprofit ling nondeterminism. libraries acting for them provided that ACM's copyright notice is given (2) A parallel command, based on Dijkstra's and that reference is made to the publication, to its date of issue, and parbegin to the fact that reprinting privileges were granted by permission of the [6], specifies concurrent execution of its constituent se- Association for Computing Machinery. To otherwise reprint a figure, quential commands (processes). All the processes start table, other substantial excerpt, or the entire work requires specific simultaneously, and the parallel command ends only permission as does republication, or systematic or multiple reproduc- tion. when they are all finished. They may not communicate This research was supported by a Senior Fellowship of the Science with each other by updating global variables. Research Council. (3) Simple forms of input and output command are Author's present address: Programming Research Group, 45, Ban- bury Road, Oxford, England. introduced. They are used for communication between © 1978 ACM 0001-0782/78/0800-0666 $00.75 concurrent processes.

666 Communications August 1978 of Volume 21 the ACM Number 8

Francqui Chair - 2010 13 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Occam = Instantiation of CSP

grams, three basic constructs have received widespread recognition and use: A repetitive construct (e.g. the while loop), an alternative construct (e.g. the conditional if..then..else), and normal sequential program composi- Programming S. L. Graham, R. L. Rivest tion (often denoted by a semicolon). Less agreement has Teclmiques Editors been reached about the design of other important pro- gram structures, and many suggestions have been made: Communicating Subroutines (Fortran), procedures (Algol 60 [15]), entries (PL/I), coroutines (UNIX [171), classes (SIMULA 67 [5]), Sequential Processes processes and monitors (Concurrent Pascal [2]), clusters (CLU [13]), forms (ALPHARD [19]), actors (Hewitt [1]). C.A.R. Hoare The traditional stored program digital computer has The Queen's University been designed primarily for deterministic execution of a Belfast, Northern Ireland single sequential program. Where the desire for greater speed has led to the introduction of parallelism, every attempt has been made to disguise this fact from the This paper suggests that input and output are basic programmer, either by hardware itself (as in the multiple primitives of programming and that parallel function units of the CDC 6600) or by the software (as composition of communicating sequential processes is a in an I/O control package, or a multiprogrammed op- fundamental program structuring method. When erating system). However, developments of processor combined with a development of Dijkstra's guarded technology suggest that a multiprocessor machine, con- command, these concepts are surprisingly versatile. structed from a number of similar self-contained proc- Their use is illustrated by sample solutions of a variety essors (each with its own store), may become more of familiar programming exercises. powerful, capacious, reliable, and economical than a Key Words and Phrases: programming, machine which is disguised as a monoprocessor. programming languages, programming primitives, In order to use such a machine effectively on a single program structures, parallel programming, concurrency, task, the component processors must be able to com- input, output, guarded commands, nondeterminacy, municate and to synchronize with each other. Many coroutines, procedures, multiple entries, multiple exits, methods of achieving this have been proposed. A widely classes, data representations, recursion, conditional adopted method of communication is by inspection and critical regions, monitors, iterative arrays updating of a common store (as in Algol 68 [18], PL/I, CR Categories: 4.20, 4.22, 4.32 and many machine codes). However, this can create severe problems in the construction of correct programs and it may lead to expense (e.g. crossbar switches) and 1. Introduction unreliability (e.g. glitches) in some technologies of hard- ware implementation. A greater variety of methods has Among the primitive concepts of computer program- been proposed for synchronization: semaphores [6], ming, and of the high level languages in which programs events (PL/I), conditional critical regions [10], monitors are expressed, the action of assignment is familiar and and queues (Concurrent Pascal [2]), and path expressions well understood. In fact, any change of the internal state [3]. Most of these are demonstrably adequate for their of a machine executing a program can be modeled as an purpose, but there is no widely recognized criterion for assignment of a new value to some variable part of that choosing between them. machine. However, the operations of input and output, This paper makes an ambitious attempt to find a which affect the external environment of a machine, are single simple solution to all these problems. The essential not nearly so well understood. They are often added to proposals are: a programming language only as an afterthought. (1) Dijkstra's guarded commands [8] are adopted (with Among the structuring methods for computer pro- a slight change of notation) as sequential control struc- General permission to make fair use in teaching or research of all tures, and as the sole means of introducing and control- or part of this material is granted to individual readers and to nonprofit ling nondeterminism. libraries acting for them provided that ACM's copyright notice is given (2) A parallel command, based on Dijkstra's and that reference is made to the publication, to its date of issue, and parbegin to the fact that reprinting privileges were granted by permission of the [6], specifies concurrent execution of its constituent se- Association for Computing Machinery. To otherwise reprint a figure, quential commands (processes). All the processes start table, other substantial excerpt, or the entire work requires specific simultaneously, and the parallel command ends only permission as does republication, or systematic or multiple reproduc- tion. when they are all finished. They may not communicate This research was supported by a Senior Fellowship of the Science with each other by updating global variables. Research Council. (3) Simple forms of input and output command are Author's present address: Programming Research Group, 45, Ban- bury Road, Oxford, England. introduced. They are used for communication between © 1978 ACM 0001-0782/78/0800-0666 $00.75 concurrent processes.

666 Communications August 1978 of Volume 21 the ACM Number 8 Anno 1978

Francqui Chair - 2010 13 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Occam = Instantiation of CSP

grams, three basic constructs have received widespread recognition and use: A repetitive construct (e.g. the while loop), an alternative construct (e.g. the conditional if..then..else), and normal sequential program composi- Programming S. L. Graham, R. L. Rivest tion (often denoted by a semicolon). Less agreement has Teclmiques Editors been reached about the design of other important pro- gram structures, and many suggestions have been made: Communicating Subroutines (Fortran), procedures (Algol 60 [15]), entries ALT (PL/I), coroutines (UNIX [171), classes (SIMULA 67 [5]), Sequential Processes processes and monitors (Concurrent Pascal [2]), clusters count1 < 100 & c1 ? data (CLU [13]), forms (ALPHARD [19]), actors (Hewitt [1]). C.A.R. Hoare The traditional stored program digital computer has SEQ The Queen's University been designed primarily for deterministic execution of a Belfast, Northern Ireland single sequential program. Where the desire for greater count1 := count1 + 1 speed has led to the introduction of parallelism, every merged ! data attempt has been made to disguise this fact from the This paper suggests that input and output are basic programmer, either by hardware itself (as in the multiple count2 < 100 & c2 ? data primitives of programming and that parallel function units of the CDC 6600) or by the software (as composition of communicating sequential processes is a in an I/O control package, or a multiprogrammed op- SEQ fundamental program structuring method. When erating system). However, developments of processor count2 := count2 + 1 combined with a development of Dijkstra's guarded technology suggest that a multiprocessor machine, con- command, these concepts are surprisingly versatile. structed from a number of similar self-contained proc- merged ! data Their use is illustrated by sample solutions of a variety essors (each with its own store), may become more of familiar programming exercises. powerful, capacious, reliable, and economical than a status ? request Key Words and Phrases: programming, machine which is disguised as a monoprocessor. programming languages, programming primitives, In order to use such a machine effectively on a single SEQ program structures, parallel programming, concurrency, task, the component processors must be able to com- out ! count1 input, output, guarded commands, nondeterminacy, municate and to synchronize with each other. Many coroutines, procedures, multiple entries, multiple exits, methods of achieving this have been proposed. A widely out ! count2 classes, data representations, recursion, conditional adopted method of communication is by inspection and critical regions, monitors, iterative arrays updating of a common store (as in Algol 68 [18], PL/I, CR Categories: 4.20, 4.22, 4.32 and many machine codes). However, this can create severe problems in the construction of correct programs and it may lead to expense (e.g. crossbar switches) and 1. Introduction unreliability (e.g. glitches) in some technologies of hard- ware implementation. A greater variety of methods has Among the primitive concepts of computer program- been proposed for synchronization: semaphores [6], ming, and of the high level languages in which programs events (PL/I), conditional critical regions [10], monitors are expressed, the action of assignment is familiar and and queues (Concurrent Pascal [2]), and path expressions well understood. In fact, any change of the internal state [3]. Most of these are demonstrably adequate for their of a machine executing a program can be modeled as an purpose, but there is no widely recognized criterion for assignment of a new value to some variable part of that choosing between them. machine. However, the operations of input and output, This paper makes an ambitious attempt to find a which affect the external environment of a machine, are single simple solution to all these problems. The essential not nearly so well understood. They are often added to proposals are: a programming language only as an afterthought. (1) Dijkstra's guarded commands [8] are adopted (with Among the structuring methods for computer pro- a slight change of notation) as sequential control struc- General permission to make fair use in teaching or research of all tures, and as the sole means of introducing and control- or part of this material is granted to individual readers and to nonprofit ling nondeterminism. libraries acting for them provided that ACM's copyright notice is given (2) A parallel command, based on Dijkstra's and that reference is made to the publication, to its date of issue, and parbegin to the fact that reprinting privileges were granted by permission of the [6], specifies concurrent execution of its constituent se- Association for Computing Machinery. To otherwise reprint a figure, quential commands (processes). All the processes start table, other substantial excerpt, or the entire work requires specific simultaneously, and the parallel command ends only permission as does republication, or systematic or multiple reproduc- tion. when they are all finished. They may not communicate This research was supported by a Senior Fellowship of the Science with each other by updating global variables. Research Council. (3) Simple forms of input and output command are Author's present address: Programming Research Group, 45, Ban- bury Road, Oxford, England. introduced. They are used for communication between © 1978 ACM 0001-0782/78/0800-0666 $00.75 concurrent processes.

666 Communications August 1978 of Volume 21 the ACM Number 8 Anno 1978

Francqui Chair - 2010 13 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Revival of Occam?

Francqui Chair - 2010 14 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Only one way to go ...

Francqui Chair - 2010 15 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Only one way to go ...

Francqui Chair - 2010 15 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A Point in Case:

LISP AND SYMBOLIC COMPUTATION: An International Journal, 6, 233–247, 1993 c 1993 Kluwer Academic Publishers – Manufactured in The Netherlands ￿

The Discoveries of Continuations

JOHN C. REYNOLDS ([email protected]) School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213-3890

Keywords: Semantics, , Continuation-Passing Style

Abstract. We give a brief account of the discoveries of continuations and related con- cepts by A. van Wijngaarden, A. W. Mazurkiewicz, F. L. Morris, C. P. Wadsworth, J. H. Morris, M. J. Fischer, and S. K. Abdali.

In the early history of continuations, basic concepts were independently discovered an extraordinary number of times. This was due less to poor communication among computer scientists than to the rich variety of set- tings in which continuations were found useful: They underlie a method of program transformation (into continuation-passing style), a style of def- initional interpreter (defining one language by an interpreter written in another language), and a style of denotational semantics (in the sense of Scott and Strachey). In each of these settings, by representing “the mean- ing of the rest of the program” as a function or procedure, continuations provide an elegant description of a variety of language constructs, including call by value and goto statements.

1. The Background

In the early 1960’s, the appearance of Algol 60 [32, 33] inspired a ferment of research on the implementation and formal definition of programming languages. Several aspects of this research were critical precursors of the discovery of continuations. The ability in Algol 60 to jump out of blocks, or even procedure bod- ies, forced implementors to realize that the representation of a label must include a reference to an environment. According to Peter Naur:

... in order to specify a transfer of control we must in general supply both the static description of the destination ... and a dynamic description of its environment, the stack reference. This set . . . together define what we call a program point. [31]

Francqui Chair - 2010 16 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations: Roll your own

(begin (define (fibonacci p) (if (> p 1) (+ (fibonacci (- p 1)) (fibonacci (- p 2))) 1)) (fibonacci 15))

(begin (define (fibonacci n continue) (define (continuation_1 p) (define (continuation_2 q) (continue (+ p q))) (fibonacci (- n 2) continuation_2)) (if (> n 1) (fibonacci (- n 1) continuation_1) (continue 1))) (fibonacci 15 display))

(begin (define (fibonacci p continue) (define (continuation q r) (continue r (+ q r))) (if (> p 1) (fibonacci (- p 1) continuation) (continue 1 1))) (fibonacci 15 (lambda (q r) (display r))))

Francqui Chair - 2010 17 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations: Roll your own

(begin (define (fibonacci p) (if (> p 1) (+ (fibonacci (- p 1)) (fibonacci (- p 2))) 1)) (fibonacci 15))

(begin (define (fibonacci n continue) (define (continuation_1 p) (define (continuation_2 q) (continue (+ p q))) (fibonacci (- n 2) continuation_2)) (if (> n 1) (fibonacci (- n 1) continuation_1) (continue 1))) (fibonacci 15 display))

(begin (define (fibonacci p continue) (define (continuation q r) (continue r (+ q r))) (if (> p 1) (fibonacci (- p 1) continuation) (continue 1 1))) (fibonacci 15 (lambda (q r) (display r))))

Francqui Chair - 2010 18 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations: Roll your own

(begin (define (fibonacci p) (if (> p 1) (+ (fibonacci (- p 1)) (fibonacci (- p 2))) 1)) (fibonacci 15))

(begin (define (fibonacci n continue) (define (continuation_1 p) (define (continuation_2 q) (continue (+ p q))) (fibonacci (- n 2) continuation_2)) (if (> n 1) (fibonacci (- n 1) continuation_1) (continue 1))) (fibonacci 15 display))

(begin (define (fibonacci p continue) (define (continuation q r) (continue r (+ q r))) (if (> p 1) (fibonacci (- p 1) continuation) (continue 1 1))) (fibonacci 15 (lambda (q r) (display r))))

Francqui Chair - 2010 19 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations: Roll your own

(begin (define (fibonacci p) (if (> p 1) (+ (fibonacci (- p 1)) (fibonacci (- p 2))) 1)) (fibonacci 15))

(begin (define (fibonacci n continue) (define (continuation_1 p) (define (continuation_2 q) (continue (+ p q))) (fibonacci (- n 2) continuation_2)) (if (> n 1) (fibonacci (- n 1) continuation_1) (continue 1))) (fibonacci 15 display))

(begin (define (fibonacci p continue) 1st class closures (define (continuation q r) ⇒ (continue r (+ q r))) (if (> p 1) 1st class continuations (fibonacci (- p 1) continuation) (continue 1 1))) (e.g. Haskell CONT monad) (fibonacci 15 (lambda (q r) (display r))))

Francqui Chair - 2010 19 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Guy Steele: Growing a Language

Francqui Chair - 2010 20 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Actors + Lisp ➜ Scheme

Structure and Interpretation of Computer Programs, 2nd Edition Harold Abelson and Gerald J. Sussman (1993) MIT Press — ISBN: 0-262-01077-1 http://mitpress.mit.edu/sicp/

Francqui Chair - 2010 21 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations and Actors

(begin (load "dictionary.scheme") (load "queue.scheme") (load "scheduler.scheme") (load "actor-generator.scheme")

(define p (act->scheme '((define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (display number) (newline) (if (= number 0) (SEND customer result 1) (let ((x (NEW FactCust customer number))) (SEND SELF doit x (- number 1)))))))

(define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2)))))

(define User (BEHAVIOR (fact) (METHOD (doit number) (SEND fact doit SELF number)) (METHOD (result number) (display (list "Value= " number)) (newline))))

(define fact (NEW Factorial)) (SEND (NEW User fact) doit 10) (SEND (NEW User fact) doit 4)))) (define act-p (eval p (interaction-environment))) (act-p))

Francqui Chair - 2010 22 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations and Actors

(begin (load "dictionary.scheme") (load "queue.scheme") (load "scheduler.scheme") (load "actor-generator.scheme")

(define p (act->scheme '((define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (display number) (newline) (if (= number 0) (SEND customer result 1) (let ((x (NEW FactCust customer number))) (SEND SELF doit x (- number 1)))))))

(define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2)))))

(define User (BEHAVIOR (fact) (METHOD (doit number) (SEND fact doit SELF number)) (METHOD (result number) (display (list "Value= " number)) (newline))))

(define fact (NEW Factorial)) (SEND (NEW User fact) doit 10) (SEND (NEW User fact) doit 4)))) (define act-p (eval p (interaction-environment))) (act-p))

Francqui Chair - 2010 22 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations and Actors

(begin (load "dictionary.scheme") (load "queue.scheme") (load "scheduler.scheme") (load "actor-generator.scheme") < 10 pages (define p (act->scheme '((define Factorial (BEHAVIOR () (METHOD (doit customer number) (BECOME Factorial) (display number) (newline) (if (= number 0) (SEND customer result 1) (let ((x (NEW FactCust customer number))) (SEND SELF doit x (- number 1)))))))

(define FactCust (BEHAVIOR (customer number1) (METHOD (result number2) (SEND customer result (* number1 number2)))))

(define User (BEHAVIOR (fact) (METHOD (doit number) (SEND fact doit SELF number)) (METHOD (result number) (display (list "Value= " number)) (newline))))

(define fact (NEW Factorial)) (SEND (NEW User fact) doit 10) (SEND (NEW User fact) doit 4)))) (define act-p (eval p (interaction-environment))) (act-p))

Francqui Chair - 2010 22 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt First-Class Continuations

(lambda () (lambda (args) ($new$ $scheduler$ (define tail (last args)) (lambda (ignore) (define (dispatcher msg arg-list) (define Factorial (set-cdr! tail arg-list) ((lambda () (apply ($get$ methods msg) args)) (define methods ($make-dictionary$)) dispatcher)))) ($put$ methods 'doit (define User (lambda (SELF become! customer number) ((lambda () (become! Factorial) (define methods ($make-dictionary$)) (display number) ($put$ methods 'doit (newline) (lambda (SELF become! fact number) (if (= number 0) ($new$ $scheduler$ ($new$ $scheduler$ (lambda (ignore) (lambda (ignore) ($switch$ $scheduler$) ($switch$ $scheduler$) (fact 'doit SELF number) (customer 'result 1) ($exit$ $scheduler$))))) ($exit$ $scheduler$))) ($put$ methods 'result (let ((x ($make-actor$ FactCust customer number))) (lambda (SELF become! fact number) ($new$ $scheduler$ (display (list Value= number)) (lambda (ignore) (newline))) ($switch$ $scheduler$) (lambda (args) (SELF 'doit x (- number 1)) (define tail (last args)) ($exit$ $scheduler$))))))) (define (dispatcher msg arg-list) (lambda (args) (set-cdr! tail arg-list) (define tail (last args)) (apply ($get$ methods msg) args)) (define (dispatcher msg arg-list) dispatcher)))) (set-cdr! tail arg-list) (define fact ($make-actor$ Factorial)) (apply ($get$ methods msg) args)) ($new$ $scheduler$ dispatcher)))) (lambda (ignore) (define FactCust ($switch$ $scheduler$) ((lambda () (($make-actor$ User fact) 'doit 10) (define methods ($make-dictionary$)) ($exit$ $scheduler$))) ($put$ methods 'result ($new$ $scheduler$ (lambda (SELF become! customer number1 number2) (lambda (ignore) ($new$ $scheduler$ ($switch$ $scheduler$) (lambda (ignore) (($make-actor$ User fact) 'doit 4) ($switch$ $scheduler$) ($exit$ $scheduler$))) (customer 'result (* number1 number2)) ($exit$ $scheduler$))) ($exit$ $scheduler$))))) ($start$ $scheduler$)) Francqui Chair - 2010 23 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt First-Class Continuations

(lambda () (lambda (args) ($new$ $scheduler$ (define tail (last args)) (lambda (ignore) (define (dispatcher msg arg-list) (define Factorial started (set-cdr! tail arg-list) ((lambda () (apply ($get$ methods10 msg) args)) (define methods ($make-dictionary$)) dispatcher)))) ($put$ methods 'doit 4 (define User (lambda (SELF become! customer number) ((lambda () 9 (become! Factorial) (define methods ($make-dictionary$))3 (display number) ($put$ methods 'doit (newline) 8 (lambda (SELF become! fact number) (if (= number 0) ($new$ $scheduler$2 ($new$ $scheduler$ (lambda (ignore) (lambda (ignore) 7 ($switch$ $scheduler$) ($switch$ $scheduler$) 1 (fact 'doit SELF number) (customer 'result 1) ($exit$ $scheduler$)))))6 ($exit$ $scheduler$))) ($put$ methods 'result (let ((x ($make-actor$ FactCust customer number))) 0 (lambda (SELF become! fact number) ($new$ $scheduler$ (display (list Value=5 number)) (lambda (ignore) (newline))) 4 ($switch$ $scheduler$) (lambda (args) (SELF 'doit x (- number 1)) 3 (define tail (last args)) ($exit$ $scheduler$))))))) (define (dispatcher msg2 arg-list) (lambda (args) (set-cdr! tail arg-list) (define tail (last args)) 1 (apply ($get$ methods msg) args)) (define (dispatcher msg arg-list) (Value= 24) dispatcher)))) (set-cdr! tail arg-list) (define fact ($make-actor$0 Factorial)) (apply ($get$ methods msg) args)) ($new$ $scheduler$ dispatcher)))) (Value= 3628800) (lambda (ignore) (define FactCust ($switch$ $scheduler$)no more processes ((lambda () (($make-actor$ User fact) 'doit 10) (define methods ($make-dictionary$)) ($exit$ $scheduler$))) ($put$ methods 'result ($new$ $scheduler$ (lambda (SELF become! customer number1 number2) (lambda (ignore) ($new$ $scheduler$ ($switch$ $scheduler$) (lambda (ignore) (($make-actor$ User fact) 'doit 4) ($switch$ $scheduler$) ($exit$ $scheduler$))) (customer 'result (* number1 number2)) ($exit$ $scheduler$))) ($exit$ $scheduler$))))) ($start$ $scheduler$)) Francqui Chair - 2010 23 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt First-Class Continuations

(lambda () (begin (lambda (args) ($new$ $scheduler$ (define tail (last args)) (lambda (ignore) (define ($make-scheduler$) (define (dispatcher msg arg-list) (define Factorial (define processes ($make-queue$)) started (set-cdr! tail arg-list) ((lambda () (define main '()) (apply ($get$ methods10 msg) args)) (define methods ($make-dictionary$)) dispatcher)))) ($put$ methods 'doit 4 (define User (lambda (SELF (define become! customer (transfer number) save-state new-state) ((lambda () 9 (become! Factorial) (call-with-current-continuation (define methods ($make-dictionary$))3 (display number) ($put$ methods 'doit (newline) (lambda (cont) 8 (lambda (SELF become! fact number) (if (= number 0) (save-state cont) ($new$ $scheduler$2 ($new$ $scheduler$ (lambda (ignore) (lambda (ignore) ((new-state) '())))) 7 ($switch$ $scheduler$) ($switch$ $scheduler$) 1 (fact 'doit SELF number) (customer 'result 1) (define actions ($exit$ $scheduler$)))))6 ($exit$ $scheduler$))) ($put$ methods 'result (let ((x ($make-actor$ FactCust customer number))) 0 (lambda (SELF become! fact number) ($new$ $scheduler$ (display (list Value=5 number)) (lambda (ignore) ... (newline))) 4 ($switch$ $scheduler$) (lambda (args) (SELF 'doit x (- number 1)) 3 (define tail (last args)) ($exit$ $scheduler$))))))) (define (dispatcher msg2 arg-list) (lambda (args) (set-cdr! tail arg-list) (define tail (define (last args)) ($new$ sched process) 1 (apply ($get$ methods msg) args)) (define (dispatcher ((sched msg arg-list) 0) process)) (Value= 24) dispatcher)))) (set-cdr! tail arg-list) (define fact ($make-actor$0 Factorial)) (apply ($get$ methods msg) args)) ($new$ $scheduler$ dispatcher)))) (define ($start$ sched) (Value= 3628800) (lambda (ignore) (define FactCust ((sched 1))) ($switch$ $scheduler$)no more processes ((lambda () (($make-actor$ User fact) 'doit 10) (define methods ($make-dictionary$)) ($exit$ $scheduler$))) ($put$ methods (define 'result ($exit$ sched) ($new$ $scheduler$ (lambda (SELF become! customer number1 number2) ((sched 2))) (lambda (ignore) ($new$ $scheduler$ ($switch$ $scheduler$) (lambda (ignore) (($make-actor$ User fact) 'doit 4) (define ($switch$ $scheduler$) ($switch$ sched) ($exit$ $scheduler$))) (customer 'result (* number1 number2)) ((sched 3)))) ($exit$ $scheduler$))) ($exit$ $scheduler$))))) ($start$ $scheduler$)) Francqui Chair - 2010 23 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt First-Class Continuations

(lambda () (begin (lambda (args) ($new$ $scheduler$ (define tail (last args)) (lambda (ignore) (define ($make-scheduler$) (define (dispatcher msg arg-list) (define Factorial (define processes ($make-queue$)) started (set-cdr! tail arg-list) ((lambda () (define main '()) (apply ($get$ methods10 msg) args)) (define methods ($make-dictionary$)) dispatcher)))) ($put$ methods 'doit 4 (define User (lambda (SELF (define become! customer (transfer number) save-state new-state) ((lambda () 9 (become! Factorial) (call-with-current-continuationcall-with-current-continuation (define methods ($make-dictionary$))3 (display number) ($put$ methods 'doit (newline) (lambda (cont) 8 (lambda (SELF become! fact number) (if (= number 0) (save-state cont) ($new$ $scheduler$2 ($new$ $scheduler$ (lambda (ignore) (lambda (ignore) ((new-state) '())))) 7 ($switch$ $scheduler$) ($switch$ $scheduler$) 1 (fact 'doit SELF number) (customer 'result 1) (define actions ($exit$ $scheduler$)))))6 ($exit$ $scheduler$))) ($put$ methods 'result (let ((x ($make-actor$ FactCust customer number))) 0 (lambda (SELF become! fact number) ($new$ $scheduler$ (display (list Value=5 number)) (lambda (ignore) ... (newline))) 4 ($switch$ $scheduler$) (lambda (args) (SELF 'doit x (- number 1)) 3 (define tail (last args)) ($exit$ $scheduler$))))))) (define (dispatcher msg2 arg-list) (lambda (args) (set-cdr! tail arg-list) (define tail (define (last args)) ($new$ sched process) 1 (apply ($get$ methods msg) args)) (define (dispatcher ((sched msg arg-list) 0) process)) (Value= 24) dispatcher)))) (set-cdr! tail arg-list) (define fact ($make-actor$0 Factorial)) (apply ($get$ methods msg) args)) ($new$ $scheduler$ dispatcher)))) (define ($start$ sched) (Value= 3628800) (lambda (ignore) (define FactCust ((sched 1))) ($switch$ $scheduler$)no more processes ((lambda () (($make-actor$ User fact) 'doit 10) (define methods ($make-dictionary$)) ($exit$ $scheduler$))) ($put$ methods (define 'result ($exit$ sched) ($new$ $scheduler$ (lambda (SELF become! customer number1 number2) ((sched 2))) (lambda (ignore) ($new$ $scheduler$ ($switch$ $scheduler$) (lambda (ignore) (($make-actor$ User fact) 'doit 4) (define ($switch$ $scheduler$) ($switch$ sched) ($exit$ $scheduler$))) (customer 'result (* number1 number2)) ((sched 3)))) ($exit$ $scheduler$))) ($exit$ $scheduler$))))) ($start$ $scheduler$)) Francqui Chair - 2010 23 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Programming Language Support

■ C: setcontext et al. (UNIX System V and GNU libc) ■ Factor: callcc0 and callcc1 ■ Icon, Unicon : create, suspend, @ operator: coexpressions ■ Parrot: Continuation PMC; uses continuation passing style for all control flow ■ Perl: Coro and Continuity ■ Pico: call(exp()) and continue(aContinuation, anyValue) ■ JavaScript Rhino : Continuation ■ Mythryl: callcc ■ Ruby: callcc ■ Scala: Responder ■ Scheme: call-with-current-continuation (commonly shortened to calłcc) ■ Smalltalk: Continuation currentDo:, in most modern Smalltalk environments continuations can be implemented without additional VM support. ■ Standard ML of New Jersey: SMLofNJ.Cont.callcc ■ Unlambda: c, the flow control operation for call with current continuation

as enumerated by Wikipedia

Francqui Chair - 2010 24 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations and the Web

Francqui Chair - 2010 25 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations and the Web

Anno 2001 Francqui Chair - 2010 25 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Continuations and the Web

AJAX (Asynchronous JavaScript with XML)

Anno 2001 Francqui Chair - 2010 25 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Language

Francqui Chair - 2010 26 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Language

Francqui Chair - 2010 26 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Language

Francqui Chair - 2010 26 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Language

Francqui Chair - 2010 26 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Language

Francqui Chair - 2010 26 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Language

(define (bind-variable variable value) (define binding (cons variable value)) (set! environment (cons binding environment)))

(define (bind-parameters parameters arguments) (for-each bind-variable parameters arguments))

(define (evaluate-sequence expressions) (define head (car expressions)) (define tail (cdr expressions)) (define value (evaluate head)) (if (null? tail) value (evaluate-sequence tail)))

(define (make-procedure parameters expression) (define lexical-scope environment) (lambda arguments (define dynamic-scope environment) (set! environment lexical-scope) (bind-parameters parameters arguments) (let ((value (evaluate expression))) (set! environment dynamic-scope) value)))

(define (evaluate-application operator) (lambda operands (apply (evaluate operator) (map evaluate operands))))

Francqui Chair - 2010 26 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Executable anything

(define (expression-meaning-abstraction-fixed-arity I* G* E0) (lambda (r k) (lambda (s) (if (ds:location? (ds:new s)) ((ds:send (ds:inject-value (ds:sequence (ds:project-location (ds:new s)) (lambda (e* k-prime) (if (= (ds:length e*) (ds:length I*)) (ds:tievals executable (lambda (a*) ((lambda (r-prime) ((command-sequence-meaning G*) r-prime ; delay required to avoid out-of-order evaluation of final expression semantics (delay ((expression-meaning E0) r-prime k-prime)))) (ds:extends r I* a*))) e*) (ds:wrong “wrong number of arguments”))))) k) (ds:update (ds:project-location (ds:new s)) ds:unspecified s)) ((ds:wrong “out of memory”) s)))))

Francqui Chair - 2010 27 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Executable anything executable specifications

(define (expression-meaning-abstraction-fixed-arity I* G* E0) (lambda (r k) (lambda (s) (if (ds:location? (ds:new s)) ((ds:send (ds:inject-value (ds:sequence (ds:project-location (ds:new s)) (lambda (e* k-prime) (if (= (ds:length e*) (ds:length I*)) (ds:tievals executable (lambda (a*) ((lambda (r-prime) ((command-sequence-meaning G*) r-prime ; delay required to avoid out-of-order evaluation of final expression semantics (delay ((expression-meaning E0) r-prime k-prime)))) (ds:extends r I* a*))) e*) (ds:wrong “wrong number of arguments”))))) k) (ds:update (ds:project-location (ds:new s)) ds:unspecified s)) ((ds:wrong “out of memory”) s)))))

Francqui Chair - 2010 27 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Executable anything executable specifications

(define (expression-meaning-abstraction-fixed-arity I* G* E0) (lambda (r k) (lambda (s) (if (ds:location? (ds:new s)) ((ds:send (ds:inject-value (ds:sequence (ds:project-location (ds:new s)) (lambda (e* k-prime) (if (= (ds:length e*) (ds:length I*)) (ds:tievals executable (lambda (a*) ((lambda (r-prime) ((command-sequence-meaning G*) r-prime ; delay required to avoid out-of-order evaluation of final expression semantics (delay ((expression-meaning E0) r-prime k-prime)))) (ds:extends r I* a*))) e*) (ds:wrong “wrong number of arguments”))))) k) (ds:update (ds:project-location (ds:new s)) ds:unspecified s)) ((ds:wrong “out of memory”) s)))))

executable models

Francqui Chair - 2010 27 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Executable anything executable specifications

(define (expression-meaning-abstraction-fixed-arity I* G* E0) (lambda (r k) (lambda (s) (if (ds:location? (ds:new s)) ((ds:send (ds:inject-value (ds:sequence (ds:project-location (ds:new s)) (lambda (e* k-prime) (if (= (ds:length e*) (ds:length I*)) (ds:tievals executable (lambda (a*) ((lambda (r-prime) ((command-sequence-meaning G*) r-prime ; delay required to avoid out-of-order evaluation of final expression semantics (delay ((expression-meaning E0) r-prime k-prime)))) (ds:extends r I* a*))) e*) (ds:wrong “wrong number of arguments”))))) k) (ds:update (ds:project-location (ds:new s)) ds:unspecified s)) ((ds:wrong “out of memory”) s)))))

executable Old wine in newmodels bags?

Francqui Chair - 2010 27 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Executable models in Scheme (begin (define (evaluate-if predicate consequent alternative) (define environment ‘()) (define boolean (evaluate predicate)) (define (loop output) (if (eq? boolean #f) (define rollback environment) (evaluate alternative) (define (error message qualifier) (evaluate consequent))) (display message) (define (evaluate-lambda parameters expression) (set! environment rollback) (make-procedure parameters expression)) (loop qualifier)) (define (evaluate-set! variable expression) (define (bind-variable variable value) (define binding (assoc variable environment)) (define binding (cons variable value)) (if binding (set! environment (cons binding environment))) (let ((value (evaluate expression))) (define (bind-parameters parameters arguments) (set-cdr! binding value) (for-each bind-variable parameters arguments)) value) (define (evaluate-sequence expressions) (error “inaccessible variable: “ variable))) (define head (car expressions)) (define (evaluate-variable variable) (define tail (cdr expressions)) (define binding (assoc variable environment)) (define value (evaluate head)) (if binding (if (null? tail) (cdr binding) value (eval variable (interaction-environment)))) (evaluate-sequence tail))) (define (evaluate expression) (define (make-procedure parameters expression) (cond (define lexical-scope environment) ((symbol? expression) (lambda arguments (evaluate-variable expression)) (define dynamic-scope environment) ((pair? expression) (set! environment lexical-scope) (let ((operator (car expression)) (bind-parameters parameters arguments) (operands (cdr expression))) (let ((value (evaluate expression))) (apply (set! environment dynamic-scope) (case operator value))) ((begin) evaluate-begin ) (define (evaluate-application operator) ((define) evaluate-define) (lambda operands ((if) evaluate-if ) (apply (evaluate operator) (map evaluate operands)))) ((lambda) evaluate-lambda) (define (evaluate-begin . expressions) ((set!) evaluate-set! ) (evaluate-sequence expressions)) (else (evaluate-application operator))) operands))) (define (evaluate-define variable expression) (else (define binding (cons variable ‘())) expression))) (set! environment (cons binding environment)) (display output) (let ((value (evaluate expression))) (newline) (set-cdr! binding value) (display “>>>”) value)) (loop (evaluate (read)))) (loop “Slip version 0”))

Francqui Chair - 2010 28 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt “Programming in XML”

Results 1 - 10 of about 350,000 for "programming in XML". (0.27 seconds)

Literate Programming in XMLLiterate programming is a programming and documentation methodology. Its central tenet is that documentation is more important than source code and should ...

nwalsh.com/docs/articles/xml2002/lp/paper.html - Cached - Similar [PDF] Literate Programming in XMLFile Format: PDF/Adobe Acrobat - Quick View

Your browser may not have a PDF reader available. Google recommends visiting our text version of this document. The answer to this problem is literate programming in XML. ... The main advantage of programming in XML is that you can structure the program ... www.literateprogramming.com/lpxp.pdf Behavioral reactivity and real time programming in XMLby P King - 2004 - Cited by 10 - Related articles

Behavioral reactivity and real time programming in XML: meets SMIL animation. Full text, Pdf (297 KB) ... portal.acm.org/citation.cfm?id=1030411 - Similar LoPiX: Logic Programming in XMLLoPiX: Logic Programming in XML. The LoPiX system is an implementation of the XML querying and data manipulation language XPathLog. ...

www.dbis.informatik.uni-goettingen.de/lopix/ - Cached - Similar SuperxProgramming in XML itself has great potential and Superx++ pushes the envelope! Superx++ Compiler and Runtime 1.0 Released ...

xplusplus.sourceforge.net/ - Cached - Similar Amazon.com: Water: Simplified Web Services and XML Programming ...You'll discover how, by programming in XML syntax with Water, you can streamline the creation of complex Web services–for example, how a complete Web ...

www.amazon.com › ... › Home Computing › Internet - Cached - Similar 7 Applications of Semidefinite Programming in XML Document ...Your browser may not have a PDF reader available. Google recommends visiting our text version of this document.

by Z Xia - Related articles Applications of Semidefinite Programming in XML. Document Classification. Zhonghang Xia, Guangming Xing, Houduo Qi, and Qi Li. Overview ... www.springerlink.com/index/P837378162736875.pdf

Francqui Chair - 2010 29 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt XML as Panacea?

Parametric Polymorphism for XML

HARUO HOSOYA 2 The University of Tokyo ALAIN FRISCH LexiFi - France and GIUSEPPE CASTAGNA PPS (CNRS) - Universit´e Denis Diderot

Despite the extensiveness of recent investigations on static typing for XML, parametric polymor- phism has rarely been treated. This well-established typing discipline can also be useful in XML processing in particular for programs involving “parametric schemas,” that is, schemas parameter- ized over other schemas (e.g., SOAP). The difficulty in treating polymorphism for XML lies in how to extend the “semantic” approach used in the mainstream (monomorphic) XML type systems. A naive extension would be “semantic” quantification over all substitutions for type variables. However, this approach reduces to an NEXPTIME-complete problem for which no practical algorithm is known and induces a subtyping relation that may not always match the programmer’s intuition. In this article, we propose a different method that smoothly extends the semantic approach yet is algorith- mically easier. The key idea here is to devise a novel and simple marking technique, where we inter- pret a polymorphic type as a set of values with annotations of which subparts are parameterized. We exploit this interpretation in every ingredient of our polymorphic type system such as subtyping, inference of type arguments, etc. As a result, we achieve a sensible system that directly repre- sents a usual expected behavior of polymorphic type systems—“values of abstract types are never reconstructed”—in a reminiscence of Reynold’s parametricity theory. Also, we obtain a set of prac- tical algorithms for typechecking by local modifications to existing ones for a monomorphic system. Categories and Subject Descriptors: D.3.3 [Programming Languages]: Language Constructs and Features—polymorphism; data types and structure; F.3.3 [Logics and Meanings of Programs]: Studies of Program Constructs—type structure

This work was partly supported by The Inamori Foundation, Japan Society for the Promotion of Science, and European FET contract “MyThS,” IST-2001-32617. This article is the full version of our previous publication with the same title in Proceedings of the 32nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, ACM, New York, 2005, pp. 50–62. The main additional materials in this article are the full proofs of theorems and two additional algorithms (linearity in Section 4.2 and substitution in Section 4.3). Authors’ addresses: H. Hosoya, 7th Bld. Of Faculty of Science, the University of Tokyo, Hongo 7-3-1, Bunkyo-ku, Tokyo 113-0033, Japan; email: [email protected]; A. Frisch, LexiFi SAS, 49 rue de Billancourt, F-92100 Boulogne-Billancourt, France; G. Castagna, PPS (CNRS), Universite´ Denis Diderot, Paris, France. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies show this notice on the first page or initial screen of a display along with the full citation. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, to redistribute to lists, or to use any component of this work in other works requires prior specific permission and/or a fee. Permissions may be requested from Publications Dept., ACM, Inc., 2 Penn Plaza, Suite 701, New York, NY 10121-0701 USA, fax 1 (212) 869-0481, or [email protected]. + C 2009 ACM 0164-0925/2009/10-ART2 $10.00 ! DOI 10.1145/1596527.1596529 http://doi.acm.org/10.1145/1596527.1596529

ACM Transactions on Programming Languages and Systems, Vol. 32, No. 1, Article 2, Pub. date: October 2009.

Francqui Chair - 2010 30 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt A different Approach

Specializing Continuations A Model for Dynamic Join Points

Christopher J. Dutchyn Computer Science, University of Saskatchewan [email protected]

ABSTRACT joint procedures; in an object-oriented language, the feature By modeling dynamic join points, pointcuts, and advice in might span several methods or classes. a defunctionalized continuation-passing style interpreter, we These crosscutting features inhibit software development provide a fundamental account of these AOP mechanisms. in several ways. For one, it is difficult for the programmer Dynamic join points develop in a principled and natural way to reason about how the disparate pieces of the feature in- as activations of continuation frames. Pointcuts arise di- teract. In addition, they compound development workload rectly in the semantic specification as predicates identifying because features cannot be tested in isolation. Also, they continuation frames. Advice models procedures operating prevent modular assembly: the programmer cannot simply on continuations, specializing the behaviour of continuation add or delete these features from a program, since they are frames. In this way, an essential form of AOP is seen, nei- not separable units. Aspect-oriented programming (aop) ther as meta-programming nor as an ad hoc extension, but is intended to provide alternative forms of modularity, to as an intrinsic feature of programming languages. extract these crosscutting features into their own modules. As a result, the code more closely resembles the design. Aop subsumes a number of different modularity technolo- 1. INTRODUCTION gies, some pre-existing, such as open classes and rewriting Current programming languages offer many ways of orga- systems, and some more unconventional, including dynamic nizing code into conceptual blocks, through functions, ob- join points and advice. This work provides a novel seman- jects, modules, or some other mechanism. However, pro- tic description of this latter system of dynamic join points, grammers often encounter features that do not correspond pointcuts, and advice. From this semantics, we provide a well to these units of organization. Such features are said to new viewpoint to what this form of aop can modularize scatter and tangle with the design of a system, because the well, and eliminate the ad hoc foundation for dynamic join code that implements the feature appears across many pro- points, pointcuts, and advice. gram units. This scattering and tangling may derive from By modeling dynamic join points, pointcuts, and advice in poor modularization of the implementation; for example, a defunctionalized continuation-passing style interpreter, we as a result of maintaining pre-existing code. But, recent provide a fundamental account of these AOP mechanisms. work[Coady et al., 2004, De Win et al., 2004, Spinczyk and Dynamic join points no longer rely on intuition to provide Lohmann, 2004] shows that, in some cases, traditional mod- “well-defined points in the execution of a program”[Kiczales ularity constructs cannot localize a feature’s implementa- et al., 2001], but arise in the language semantics in a princi- tion. In these cases, the implementation contains features pled and natural way as activations of continuation frames. which inherently crosscut each other.1 In a procedural lan- Pointcuts arise directly in the semantic specification as pred- guage, such a feature might be implemented as parts of dis- icates identifying continuation frames. Advice models pro- cedures operating on continuations, the dual of its usual 1Strictly speaking, crosscutting is a three-place relation: we behaviour as value transformers. Advice is shown as spe- say that two concerns crosscut each other with respect to cializing the behaviour of continuation frames, leading us a mutual representation. The less rigorous ‘two concerns to understand dynamic join points, pointcuts, and advice crosscut each other’ means that they crosscut each other as enabling the modularization of control in programs. In with respect to an implementation that closely parallels typical executable code. Traditional modularity constructs, this way, an essential form of AOP is seen, neither as meta- such as procedures and classes, have a close parallel between programming nor as ad hoc extension, but as an intrinsic source and executable code. feature of programming languages. We begin our presentation by giving direct semantics for an idealized procedural language, in Section 2. We trans- Permission to make digital or hard copies of all or part of this work for form to the continuation passing semantics in Section 3, and personal or classroom use is granted without fee provided that copies are identify the three model elements within that semantics in not made or distributed for profit or commercial advantage and that copies Section 4. Following a comparison of our derivation with bear this notice and the full citation on the first page. To copy otherwise, to other accounts in Section 5, we close with observations on republish, to post on servers or to redistribute to lists, requires prior specific how this work informs our understanding of modularity and permission and/or a fee. provides future avenues of research in Section 6. Sixth International Workshop on Foundations of Aspect-Oriented Lan- guages (FOAL 2007) March 13, 2007, Vancouver, BC, Canada. Copyright 2007 ACM ISBN 1-59593-671-4/07/03 ...$5.00.

Francqui Chair - 2010 31 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Choice of Languages

plt-scheme.org

Francqui Chair - 2010 32 Inaugural Lecture \ˈskēm\ Growing a Language from the Inside Out Theo D’Hondt Choice of Languages

plt-scheme.org Slip

Francqui Chair - 2010 32 Inaugural Lecture \ˈskēm\ Growing a Language from the Inside Out Theo D’Hondt Choice of Languages

plt-scheme.org Slip

Francqui Chair - 2010 32 Inaugural Lecture \ˈskēm\ Growing a Language from the Inside Out Theo D’Hondt Choice of Languages

plt-scheme.org Slip ➽ ➽ ➽ ➽ ➽ \ˈskēm\

Francqui Chair - 2010 32 Inaugural Lecture \ˈskēm\ Growing a Language from the Inside Out Theo D’Hondt Additional Reading

Jamie Zawinski Brad Fitzpatrick Douglas Crockford Brendan Eich Joshua Bloch Joe Armstrong Simon Peyton Jones Peter Norvig Guy Steele Dan Ingalls L Peter Deutsch Ken Thompson Fran Allen Bernie Cosell Donald Knuth

Francqui Chair - 2010 33 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Recommended Reading

Essentials of Programming Languages, 3rd Edition Daniel P. Friedman and Mitchell Wand (2008) MIT Press — ISBN: 978-0-262-06279-4 http://www.eopl3.com

Francqui Chair - 2010 34 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt EOPL Essentials of Programming Languages, 3rd Edition Daniel P. Friedman and Mitchell Wand

Foreword by Hal Abelson ix Preface xv Acknowledgements xxi 1 Inductive Sets of Data 1 2 Data Abstraction 31 3 Expressions 57 4 State 103 5 Continuation-Passing Interpreters 139 6 Continuation-Passing Style 193 7 Types 233 8 Modules 275 9 Objects and Classes 325 A For Further Reading 371 B The SLLGEN Parsing System 377 Bibliography 391 Index 399 Francqui Chair - 2010 35 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt EOPL Essentials of Programming Languages, 3rd Edition Daniel P. Friedman and Mitchell Wand

Foreword by Hal Abelson ix Preface xv Acknowledgements xxi 1 Inductive Sets of Data 1 2 Data Abstraction 31 3 Expressions 57 4 State 103 5 Continuation-Passing Interpreters 139 6 Continuation-Passing Style 193 7 Types 233 8 Modules 275 9 Objects and Classes 325 A For Further Reading 371 B The SLLGEN Parsing System 377 Bibliography 391 Index 399 Francqui Chair - 2010 35 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Why C?

Francqui Chair - 2010 36 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Why C?

Francqui Chair - 2010 36 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Hardware in CS

Francqui Chair - 2010 37 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Hardware in CS

Francqui Chair - 2010 37 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Hardware in CS

Francqui Chair - 2010 37 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Hardware in CS

Francqui Chair - 2010 37 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Popular CS

Francqui Chair - 2010 38 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Popular CS

Francqui Chair - 2010 38 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Popular CS

Francqui Chair - 2010 38 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Popular CS

Francqui Chair - 2010 38 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Building a Virtual Machine

!1 !2 !

{ n: 200; c: 2000000; pushl %ebp t[n]: void; movl %esp, %ebp any(p): subl $8, %esp 1 + abs(random()) \\ p; .stabd 68,0,82 node(): movl 8(%ebp), %eax x[any(n)]: void; sall $2, %eax for(i:1, i<=n, i:=i+1, movl %eax, %edx t[i]:= node()); movl L__MEM_free$non_lazy_ptr, %eax while((c:=c-1)>0, movl (%eax), %eax { i: any(n); addl %eax, %edx s: t[i]; movl L__MEM_top$non_lazy_ptr, %eax m: size(s); movl (%eax), %eax j: any(m); cmpl %eax, %edx k: any(n + n); seta %al if(k>n, movzbl %al, %eax s[j]:= node(), s[j]:= t[k]) }); void }

concrete syntax abstract syntax VM codes machine codes

Δ1 » Δ2 ≈ 0 Δ2 » Δ1 ≈ 0

Francqui Chair - 2010 39 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Building a Virtual Machine

!

(begin (define (Fib n) (if (> n 1) (+ (Fib (- n 1)) (Fib (- n 2))) 1)) (Fib 35)) concrete syntax s-expressions abstract syntax

Francqui Chair - 2010 40 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Eat your own ...

Francqui Chair - 2010 41 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Eat your own ...

Francqui Chair - 2010 41 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Schedule

Lecture 2: Interpreters and Virtual Machines

• Interpreters as executable semantics • Meta-level abstraction • Growing a language: first-class environments • Abstract grammars and virtual machines

Friday, March 26th 13h30 - 17h30

Francqui Chair - 2010 42 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Schedule

Lecture 3: Continuations and Continuation Passing Style

• Continuations as first-class computation • CPS as a universal execution model • Tail-recursion and iteration

Friday, April 2nd 13h30 - 17h30

Francqui Chair - 2010 43 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Schedule

Lecture 4: Using Primitive Execution Models

• Expressing continuations in C • Trampolines as the root interpretation engine • Managing environments and threads

Friday, April 23rd 13h30 - 17h30

Francqui Chair - 2010 44 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Schedule

Lecture 5: Memory Management as a Crosscutting Concern

• A simple compacting mark-and-sweep garbage collector • Establishing critical sections for garbage collection • Weaving memory claims into a CPS-interpreter

Friday, April 30th 13h30 - 17h30

Francqui Chair - 2010 45 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt Schedule

Lecture 6: Binding it all Together

• Refactoring and partial evaluation • First-class procedures and first-class continuations • Smart caching • Evaluation of C as a target language

Friday, May 7th 13h30 - 17h30

Francqui Chair - 2010 46 Inaugural Lecture Growing a Language from the Inside Out Theo D’Hondt http://web.me.com/tjdhondt/ Francqui

Francqui Chair - 2010 47 Inaugural Lecture