Changes between Version 4 and Version 5 of PIL
- Timestamp:
- 10/03/24 20:42:43 (20 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PIL
v4 v5 47 47 48 48 There are two kinds of functions in PIL: 49 1. Imperative functions = "procedures" 50 1. Logic functions 49 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. 50 1. Logic functions. One of these has a type of the form `$fun<R,T1,...,Tn>`. 51 51 52 52 === Procedures 53 53 54 Like in C. These can be nested. Obviously they can have side-effects, be nondeterministic, and the behavior can depend on non-local state. A procedure call `f(x1,...,xn)` is an expression that can be used anywhere an expression with side-effects is allowed. Imperative procedures are not values and cannot be assigned to anything. However, as in C, a pointer to a procedure is a first-class value that can be assigned, used as an argument, returned, etc. There is a procedure type, exactly likeC's function type, e.g.,54 Like in C. These can be nested. Obviously they can have side-effects, be nondeterministic, and the behavior can depend on non-local state. A procedure call `f(x1,...,xn)` is an expression that can be used anywhere an expression with side-effects is allowed. Imperative procedures are not values and cannot be assigned to anything. However, as in C, a pointer to a procedure is a first-class value that can be assigned, used as an argument, returned, etc. There is a procedure type, similar to C's function type, e.g., 55 55 {{{ 56 56 typedef int(int) i2i; … … 60 60 typedef int(int)* i2ip; 61 61 }}} 62 defines the type "pointer to procedure from int to int". As in C, a pointer to a procedure can be used in a procedure call. 62 defines the type "pointer to procedure from int to int". As in C, a pointer to a procedure can be used in a procedure call. It is an error to call a procedure f when f is not in scope. (This is similar to Gnu C.) In other words, if the call takes place in dyscope d, then the definition of f must be in d's static scope, or in the parent of d's static scope, or its parent, etc. 63 63 64 64 A procedure definition can be templated: … … 70 70 === Logic functions 71 71 72 Typically specified by a $lambda expression. These are first-class objects in PIL: they can be assigned to variables, passed as an argument in a function call (including a procedure call), and can be returned by a function. Each has a type of the form `$fun<U,T1,...,Tn>` (functions from `T1` x ... x `Tn` to `U`). They are side-effect-free. An application of a logic function `f(x1,...,xn)` is anexpression that can be used anywhere an expression is allowed. A logic function is not necessarily pure, i.e., the value of an application may depend on any part of the state, not just the arguments.72 Typically specified by a $lambda expression. These are first-class objects in PIL: one can be assigned to a variable, passed as an argument in a function call (including a procedure call), and can be returned by a function. Each has a type of the form `$fun<U,T1,...,Tn>` (functions from `T1` x ... x `Tn` to `U`). They are side-effect-free. An application of a logic function `f(x1,...,xn)` is a side-effect-free expression that can be used anywhere an expression is allowed. A logic function is not necessarily pure, i.e., the value of an application may depend on any part of the state, not just the arguments. 73 73 74 74 === Lambda expressions
