Changes between Version 15 and Version 16 of PIL


Ignore:
Timestamp:
10/06/24 09:14:29 (19 months ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PIL

    v15 v16  
    16161. Program order:
    1717 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?]
    1919 1. A variable can be used anywhere it is in scope.
    2020 1. A function can be called anywhere it is in scope.
     
    5050- `$set<T>` : finite set of `T`
    5151- `$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.
    5353- Type definitions have the form: `typedef typename ID;`
    5454
     
    5656
    5757There are two kinds of functions in PIL:
    58 1. Imperative 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.
     581. 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.
    59591. Logic functions.  One of these has a type of the form `$fun<R,T1,...,Tn>`.
    6060
     
    9696A logic function can be defined as follows:
    9797{{{
    98   $logic R f(T1 x1, ..., xn) = expr;
     98  $logic R f(T1 x1, ..., Tn xn) = expr;
    9999}}}
    100100where `expr` is a side-effect-free expression of type `R` and can refer to any variables in scope.
     
    121121A lambda expression that specifies a procedure closure has the form:
    122122{{{
    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 }
    124124}}}
    125125where
     
    132132* the only variables that can occur free in the block are the `xi` and `vj`.
    133133
    134 The type of this expression is `R(T1, ..., Tn)`.   The resulting value of this is type is a procedure which can be called or assigned to a variable, etc., just like any other procedure value.
     134The 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.
    135135
    136136Note 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.
     
    208208Expressions:
    209209- `a1 == a2`
    210  * the two arrays have the same type and length and corresponding elements are equal
     210 * the two sequences have the same type and length and corresponding elements are equal
    211211- `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`.
    213213- `a[i:=x]`
    214  * the sequence which is the same as `a`, exception 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`
    215215- `(T[]){ expr1, ... }`
     216 * the sequence obtained by evaluating the given expressions, each of which has type `T`
    216217
    217218Logic functions:
    218219- `$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)`
    219221- `$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
    224231- `$pure $logic T[] $seq_concat(T[] a1, T[] a2);`
     232 * the sequence obtained by concatenating the two given ones
    225233- `$pure $logic U[] $seq_map(T[] a, $fun<T,U> f);`
     234 * the sequence obtained by applying `f` to every element of `a`
    226235- `$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`
    227237- `$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.
    228239- `$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.
    229241
    230242Mutating expressions:
    231243- `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`
    232245
    233246Mutating procedures:
     
    240253Side-effect-free expressions:
    241254- `m1 == m2`
     255 * the two maps have the same type and the same entries
    242256- `($map<K,V>)$empty`
     257 * the empty map from `K` to `V`
    243258
    244259Logic functions: