Changes between Version 15 and Version 16 of PIL
- Timestamp:
- 10/06/24 09:14:29 (19 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PIL
v15 v16 16 16 1. Program order: 17 17 1. A program is a set of variable, function, and type definitions. 18 1. The order is totally irrelevant. 18 1. The order is totally irrelevant. [NOTE: except for initializers?] 19 19 1. A variable can be used anywhere it is in scope. 20 20 1. A function can be called anywhere it is in scope. … … 50 50 - `$set<T>` : finite set of `T` 51 51 - `$map<T1,T2>` : finite map from `T1` to `T2`. A map is a set of ordered pairs `(x,y)` with the property that if `(x,y)` and `(x,z)` are in the map, then `y`=`z`. 52 - `$tuple<T ,...>` : tuples of specified type. This is similar to `struct`, but there is no tag and the fields do not have names.52 - `$tuple<T1,...>` : tuples of specified type. This is similar to `struct`, but there is no tag and the fields do not have names. 53 53 - Type definitions have the form: `typedef typename ID;` 54 54 … … 56 56 57 57 There are two kinds of functions in PIL: 58 1. Imperativefunctions = "procedures". A procedure has a type of the form `R(T1,...,Tn)` where `R` is the return type and the `Ti` are the input types.58 1. Procedural functions = "procedures". A procedure has a type of the form `R(T1,...,Tn)` where `R` is the return type and the `Ti` are the input types. 59 59 1. Logic functions. One of these has a type of the form `$fun<R,T1,...,Tn>`. 60 60 … … 96 96 A logic function can be defined as follows: 97 97 {{{ 98 $logic R f(T1 x1, ..., xn) = expr;98 $logic R f(T1 x1, ..., Tn xn) = expr; 99 99 }}} 100 100 where `expr` is a side-effect-free expression of type `R` and can refer to any variables in scope. … … 121 121 A lambda expression that specifies a procedure closure has the form: 122 122 {{{ 123 $lambda [U1 v1=init1; ... Um vm=initm;] R (T1 x1, ..., Tn xn) { S1; ...}123 $lambda [U1 v1=init1; ... Um vm=initm;] R (T1 x1, ..., Tn xn) { stmts } 124 124 }}} 125 125 where … … 132 132 * the only variables that can occur free in the block are the `xi` and `vj`. 133 133 134 The type of this expression is `R(T1, ..., Tn)`. The resulting value of this is typeis a procedure which can be called or assigned to a variable, etc., just like any other procedure value.134 The type of this expression is `R(T1, ..., Tn)`. The resulting value is a procedure which can be called or assigned to a variable, etc., just like any other procedure value. 135 135 136 136 Note that the definition can only use the specified variables. Evaluating this expression yields a closure, which is a pair consisting of a dyscope and the body of the procedure. The dyscope has variables `vj`, which are initialized by evaluating the `initj` when the lambda expression is evaluated. The body of the procedure may read and write to the `vj`. That dyscope has no parent and will live as long as the procedure is around. Hence a function may return a closure and that closure may still be called at any time, anywhere in the program, regardless of whether the original lambda expression is in scope. … … 208 208 Expressions: 209 209 - `a1 == a2` 210 * the two arrays have the same type and length and corresponding elements are equal210 * the two sequences have the same type and length and corresponding elements are equal 211 211 - `a[i]` 212 * the `i`-th element of `a` 212 * the `i`-th element of `a`. Here `a` is an expression of type `T[]` and `i` is an expression of type `$int`. 213 213 - `a[i:=x]` 214 * the sequence which is the same as `a`, except ion in position `i`, where it has value `x`214 * the sequence which is the same as `a`, except in position `i`, where it has value `x`. Here `a` is an expression of type `T[]`, `i` is an expression of type `$int`, and `x` is an expression of type `T` 215 215 - `(T[]){ expr1, ... }` 216 * the sequence obtained by evaluating the given expressions, each of which has type `T` 216 217 217 218 Logic functions: 218 219 - `$pure $logic T[] $seq_fun($int len, $fun<$int,T> f);` 220 * the sequence of length `len` whose value at position `i` is `f(i)` 219 221 - `$pure $logic T[] $seq_uniform($int n, T val);` 220 - `$pure $logic $int $length(T[] a);` // length of a 221 - `$pure $logic T[] $seq_subseq(T[] a, int i, int n);` // a[i..i+n-1] 222 - `$pure $logic T[] $seq_without(T[] a, int i);` // a with position i removed 223 - `$pure $logic T[] $seq_with(T[] a, int i, T x);` 222 * the sequence of length `n` in which every component is `val` 223 - `$pure $logic $int $length(T[] a);` 224 * the length of `a` 225 - `$pure $logic T[] $seq_subseq(T[] a, int i, int n);` 226 * the sequence of length n, a[i..i+n-1] 227 - $pure $logic T[] $seq_with(T[] a, int i, T x);` 228 * the sequence obtained from `a` by inserting `x` at position `i` and shifting the subsequent elements up 229 - `$pure $logic T[] $seq_without(T[] a, int i);` 230 * the sequence obtained from `a` by deleting the element in position `i` and shifting subsequent elements down 224 231 - `$pure $logic T[] $seq_concat(T[] a1, T[] a2);` 232 * the sequence obtained by concatenating the two given ones 225 233 - `$pure $logic U[] $seq_map(T[] a, $fun<T,U> f);` 234 * the sequence obtained by applying `f` to every element of `a` 226 235 - `$pure $logic T[] $seq_filter(T[] a, $fun<T,$bool> f);` 236 * the sequence obtained from `a` by removing every element for which `f(a[i])` is `$false` 227 237 - `$pure $logic U $seq_foldl(T[] a, $fun<$tuple<T,U>,U> f, U init);` 238 * the sequence b which has the same length as `a`, and where b[0]=f(init, a[0]), b1=f(b[0], a[1]), b2=f(b[1], a[2]), etc. 228 239 - `$pure $logic U $seq_foldr(T[] a, $fun<$tuple<T,U>,U> f, U init);` 240 * the sequence b which has the same length as `a`, and where b[n-1]=f(a[n-1], init), b[n-2]=f(a[n-2], b[n-1]), etc. 229 241 230 242 Mutating expressions: 231 243 - `a[i]=x;` 244 * assigns value of `x` to `a[i]` and returns value of `x`. Here `a` has array type, say `T[]`, `x` is an expression of type `T`, and `i` is an expression of type `$int` 232 245 233 246 Mutating procedures: … … 240 253 Side-effect-free expressions: 241 254 - `m1 == m2` 255 * the two maps have the same type and the same entries 242 256 - `($map<K,V>)$empty` 257 * the empty map from `K` to `V` 243 258 244 259 Logic functions:
