Impossible to convert a program without meta logic.

Junk edit

Imperative programs allow the modification of state. State consists of many state variables. A state variable is the name which identifies different values at different points in the execution of a program.

For each state variable, a statement has an input value and an output value. The input value and the output value may be the same, or the statement may calculate a new output value from the input value.

To represent this mathematically, a statement has an input i, parameters p, and output r, and an output o. An imperative statement,

actually means,

The return value and the output state are calculated from the input state and the parameter. In a series of statements the outputs of proceeding statements need to be connected to the inputs of proceeding statements. An imperative statement does not explicitly represent this input.

The input state is not explicitly represented. One possibility is that the function should be represented as a lambda expression

State passed by function composition edit

[1] In many languages the ; is used to separate statements. For example.

 

An assignment statement is represented as a lambda expression as,

 

If the statement separator is regarded as function composition,

 

Then the series of statements becomes,

 
 
 
 
 
 
 
 
 
 

Another approach is to regard the assignment statement as a lambda expression,

 
 

Then by use of bracketing,

 
 
 
 
 

However both these approach only work for a series of statements. For imperative functions with side effects returning results that are combined using other operators this approach does not give the right structure.


State under function application edit

In the relational programming model it is not necessary to consider the output as being calculated from the input. The state holder notation includes the input as part of a triple returned by the function.

 

In this representation the state holder does not actually behave like a mathematical object. It does not obey the substitution rule,

 

But is a good fit for an assignment statement, which is also not mathematical.

For example,

 

The assignment statement here is interpreted as returning the value true if it is successful. Note that this is not the interpretation in the C language, but it allows the ; to be interpreted as conjunction,

 

Using state holders this expression is equivalent to,

 

As the output of the first statement is the input to the next statement then,

 

and the statement simplifies to,

 

which is equivalent to,

 

The triple of input, result, and output is called a state holder.

  1. ^ Abdali, S. Kamal (27 May 1975). "A LAMBDA-CALCULUS MODEL OF PROGRAMMING LANGUAGES-I. SIMPLE CONSTRUCTS" (PDF). Journal of Computer Languages. 1: 287–301.