Featured

# Issues in Evaluating Expressions

It is easy to generate a tree from a given expression but then a implementing executable sequence of primitive operations.

#### 1. Uniform evolution rules :->

i)  Eager :- Evaluates the operands as soon as they appears (e.g parallel processing ).
ii) Lazy Rules :- This means delay evaluation of operands as late as possible (e.g LISP ).

For example First evaluate to its operands and then apply the operations to the operands
( a + b ) * ( c - a )
First it will fetch the data values of a, b, c then subtract a from c and obtain 'e', then add a to b and obtain 'd' and ultimately multiply 'd' with 'c' and obtain 'f' as d*e.
Now consider a example which has condition in it.
We do not have every value at initial stage thus we can not apply eager rule to such an expression this means we can't apply this method to every expression.  So, there is a need to find  newer method.
The newest method is known as lazy, means never evaluate operands before applying the operations.  Instead pass the operands unevaluated and let the operation decide whether evaluation is needed.
This method is sometimes come out to be practical, how to pass unevaluated operands to operation.

# Issue 2.  Side Effect :->

a * foo(x) + a ;

say a = 1, foo(x) generates 4 and change value of a to 2.
Here we have three types of possibilities depend upon order of execution.
* If we evaluate each term in sequence i.e
a = 1
then calculate foo(x) which is 4 and change value of a to 2, thus expression becomes
1 + 4 + 2 = 7
* If we evaluate each value before the expression i.e
a = 1 and foo(x) = 4
then expression will become
1 + 4 + 1 = 6
and if we calculate a  after foo(x), then the values are foo(x) = 4 & a = 2 and the expression becomes
2 + 4 + 2 = 8.
Here, we can see that changing the sequence will change the final result and all the values are correct according to some sequence.
In general, we have two options to deal with side effects :
-> disallowing function which have side effects.
-> or let the user to use function with side effects and let the language to define the proper sequence, but unfortunately many language ignore this feature.
We can't say that which method is better but sometimes one is better and sometimes the other one is better.
If optimization is not necessary, then it is valuable to allow side effects.

#  Issue 3 :
Error Condition :-> It is  special kind of side effect that may fail and generate an error condition like overflow and there only solution is exceptional statements
try------- catch block.

# Issue 4 :
Short-circuit expression :->  We are using Boolean operation and or, to combine relational expressions (&& in C) ( // in C )

# Co-routines :-> They are program components that generalize subroutines i.e co-routines have multiple entry point rather than single entry point in subroutines.  So it will be used for execution of some statements.
Subroutines is a piece of program that will be called by a subprogram.
Subroutines are last in first out.  Where as lifespan of co-routines are dectated entirely by their use and need.
The multiple entry points will be called yield and yield returns the result to the calling co-routine.

# Generator :-> It is also like co-routine but have less expressive.
In this yielding will not call the other generator but will only pass the final result to parent generator.
They are generally used to define multitasking, pipelining.