Skip to content

Latest commit

 

History

History
141 lines (103 loc) · 2.41 KB

File metadata and controls

141 lines (103 loc) · 2.41 KB

Compiling and loading continuation-based evaluators

Chapter 11 introduces the concept of continuation, which helps understand such notions as tail call, exceptions and exception handling, execution stack, and backtracking. A continuation is an explicit representation of the rest of the computation. Usually this is implicit in a program: after executing one statement, the computation will continue with the next statement; when returning from a method, the computation will continue where the method was called; and so on. Making the continuation explicit has the advantage that we can ignore it (and so model abnormal termination), and that we can have more than one continuation (and so model exception handling and backtracking).

A. Two continuation-based interpreters for functional language

Loading two continuation-based interpreters for a functional language with exceptions:

dotnet fsi Contfun.fs
open Contfun;;
eval1 ex1 [];; 
eval1 ex2 [("n", Int 10)];;
#q;;

B. Two continuation-based interpreters for an imperative language

Loading two continuation-based interpreters for an imperative language with exceptions:

dotnet fsi Contimp.fs
open Contimp;;
run1 ex1;;
run1 ex2;;
run2 ex3;;
#q;;

C. A continuation-based interpreter for micro-Icon

Loading a continuation-based interpreter for micro-Icon, a language in which an expression can have multiple results:

dotnet fsi Icon.fs
open Icon;;
run ex1;;
run ex2;;
run ex3and;;
run ex3or;;
#q;;

D. Java implementation of factorial

Compile and run a Java implementation of factorial in continuation-passing style:

cd Factorial/

javac Factorial.java
java Factorial 10
javac Factorial2.java
java Factorial2 10

E. C# implementation of factorial

Compile and run a C# implementation of factorial in continuation-passing style:

cd Factorial/

dotnet build Factorial.csproj
dotnet run 10

F. Example illustrating longjmp

Compile and run example illustrating longjmp and setjmp in C (under Linux and MacOS):

We recommend using clang as compiler. See Platform Dependencies on how to install across platforms.

clang testlongjmp.c -o testlongjmp
./testlongjmp 10
./testlongjmp 11