Friday, November 27, 2020


 A state is a sequence of values in time that contains the intermediate results of a desired computation.

Implicit (declarative) State

The sequence need only exist in the mind of the programmer. It does not need any support from the computation model. This kind of state is called implicit state or declarative state. 

For example, if we write a recursive program to compute the sum of these numbers: [1,2,3,4], we will have two arguments to the recursive method, one that consists of the unexamined rest of the input list and  the other for sum, which is the sum of the examined part of the input list. While calculating the sum of a list, the method calls itself many times. If we print the values of these variables in each call:

[1,2,3,4] # 0

[2,3,4] # 1

[3,4] # 3

[4] # 6

[] #10

This sequence is a state. When looked at in this way, the method calculates with state. The state is completely in the mind of the programmer.