f lexib o language design work-in-progress yifeng chen university of leicester 7 may 2004 unu/iist,...
TRANSCRIPT
![Page 1: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/1.jpg)
FLEXIBO Language Design
Work-in-Progress
Yifeng Chen
University of Leicester
7 May 2004 UNU/IIST, Macau
![Page 2: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/2.jpg)
Language Design
Programming languages form an interface between computer science and computer engineering.
Good software engineering practice eventually goes into language design.
![Page 3: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/3.jpg)
Design Philosophy of FLEXIBO
Open source with different levels of trust in decentralized multi-user environment.
Developing || Testing || Running Limiting the effective scope of bugs. Specifications with optional controls. True flexibility = flexibility + inflexibility. Compilation as execution.
![Page 4: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/4.jpg)
Main Features
Everything is a value. Classes, types, methods and
specifications of different “shapes”. Variables of different “colors”. Correctness, ownership, resources cont
rol and smooth exception handling. Run-time type checking for compilation. Full Java access
![Page 5: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/5.jpg)
Example Program: Hello World!
print "Hello world!"
![Page 6: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/6.jpg)
Imperative Programming
var x:= [12, "A string in an array"];
x[0] := x[0] + 1;
if x[0]>12 print "yes\n" else print "no\n";
{var x:="inside a block\n"; print x;
{var x:="inside another block\n"; print x;}};
while x>0 {print x; x:= x - 1};
while true {}
![Page 7: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/7.jpg)
Class, Method and Invocation
var c := class Value {
var dynamic x :="static value in class\n";
var static n := method [x] {var x:="value of local variable\n"; return x;};
var static m := method x { return x}};
var o:= new c; print o.n ["value from argument\n"];
print o.m ! "value from argument\n";
print o. (1 + m ! 2)
![Page 8: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/8.jpg)
Specification and implementation
var spec := specification [x,y] pre: true post: true ;
spec.implement[body (x := "I implement by adding a prefix to "+x; return x)];
print spec["the argument.\n",2];
spec := specification [x,y] pre: true post: true ;
print spec["the argument.\n",2];
![Page 9: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/9.jpg)
Ownership Control
print project; // show the shared project
project.spec := "I have modified changed this specification.";
print project; // show its change
project.spec := "I have reset this specification.";
project := "I want to delete the whole project.";
print project; // This point is not reachable.
![Page 10: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/10.jpg)
Exception Handling
try {print 1+true;}
catch "Cannot add" {print "I have caught it.\n"};
var timer:= new tclass;
try {timer.start[2000]; while true {}}
catch "" {print "I have caught my own timeout error.\n"};
timer:=new tclass;
try {timer.start[5000]; while true {}}
catch "" {print "I cannot catch the server's timeout.\n"};
![Page 11: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/11.jpg)
Overloading Method Invocation
var c := class Value { var m := method [a] { return a };
var n := class Value {var invoke:= method [a] return "Overloading method invocation is "+a}; };
print (new c).m ["invoked in a usual way\n"]; // x->m->a
var x:=new c ; print ((x.m).invoke ["Invoked as a pre-defined method\n"]);
print (new c).n ["invoked in a usual way\n"]; // x->m->a
print ((x.n).invoke ["invoked as a normal method\n"]);
![Page 12: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/12.jpg)
Side Effect and Evaluation Order
var a := "Evaluated as an argument";
var c := class Value {
var dynamic y;
var m := method [z] {print z}};
var env := class Value { var x := new c; };
env . ( (print "Evaluate x in env\n"; x). (print "Evaluate m in x\n"; m) [ (print "Evaluate a in the defined environment.\n"; a) ] )
![Page 13: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/13.jpg)
Language Reflection
print quote (1 + "A quoted exp is not evaluated.");
var c:= class Value {
var v:="\nA value in a class\n";
var b:= body (print v) };
print (c.b).eval [ ];
![Page 14: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/14.jpg)
Methods in Different “Shapes”
var c:= class Method {var dynamic msg:= "together with a document of the method.\n";
var init:= method x {print msg; return x}};
var m:= new c[quote (y), body (print y)];
print m["Invoking a user-defined kind of method.\n"]
![Page 15: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/15.jpg)
Colored Variables (att:var)
var P := class Value {var type :="Type of Persons\n";
var returnType := method [] {return att:type}; };
var S := class P {var type := "Type of Staff\n"} ;
print (new P).returnType[]; // or (new P).att:returnType[]
print (new S).returnType[];
![Page 16: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/16.jpg)
Colored Variables (def:var)var SimpleAccount := class Value {
var dynamic private deposit:=200;
var dynamic private withdrawal:=100;
var getTotal := method [] return (deposit - withdrawal);
var payable := method [payment] return (payment< def:getTotal[])};
var Account := class SimpleAccount {
var dynamic private savings:= 400;
var getTotal := method [] return (super.getTotal[] + savings); };
var sa := new SimpleAccount;
print sa.payable[200]; // not payable
var a := new Account;
print a.payable[200]
![Page 17: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/17.jpg)
The Default Rule
y . ( x . m ! a )
y --- def variable (evaluated in defined env)
x --- att variable (evaluated in y)
m --- att variable (evaluated in x)
a --- def variable (evaluated in defined env)
The default rule implies dynamic binding.
![Page 18: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/18.jpg)
Colored Variables (gen/raw:var)var Account := class Value {
var dynamic deposit:=200;
var dynamic withdrawal:=100;
var gen:balance((deposit - withdrawal),
method b { deposit := b + withdrawal}) };
var account := new Account;
print account.balance;
account.balance := 300; // updation
print account.balance;
print account.raw:balance // return the expressions
![Page 19: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/19.jpg)
Types and Run-time Checking
print "This must be a string according to the type constraint.\n":String;
print Int + Float - Int; // This is used for user-defined type checking algorithm.
print "This string is wrongly typed!" : Int
![Page 20: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/20.jpg)
User-defined Types
var YType := class Value { var dynamic type;
var init := method [ t ] { type:= t ; return this};
var check := method t {return type <= t.getType[]}; };
var Persons := class Value {var msg := "I am a person.\n"};
var Staff := class Persons {var msg := "I am a staff.\n"};
var YStaff := new YType[Staff];
var s:YStaff; // Upwards-closure type
s := new Persons; print s.msg;
var p:Staff; // Normal type requires exact match.
p := new Persons; print s.msg;
![Page 21: F LEXIB O Language Design Work-in-Progress Yifeng Chen University of Leicester 7 May 2004 UNU/IIST, Macau](https://reader035.vdocuments.us/reader035/viewer/2022062407/56649e865503460f94b89345/html5/thumbnails/21.jpg)
Future Work
Client-side HCI (using Java RMI). From FlexibO to C++. Exploring the new mechanisms. Integration of UML. Predicative semantics and proof of
development non-monotonicity.