Hello, is there any way how to return lambda from another lambda recursively?
All I want to do is finite state machine, implemented as lambda, which returns lambda implementing another state (or null).
nesting Func<> won't work as I want.
C#, .NET 3.5
Example:
machine, 3 states, pseudolanguage
private Lambda State1()
{
if (SomeConditionIsMet)
return State2;
else
return State1;
}
private Lambda State2()
{
while (SomeConditionIsMet)
return State2;
else
return State3;
}
private Lambda State3()
{
LogEnd();
return NULL;
}
public void FSM()
{
Lambda _currentState = State1;
while(_currentState != NULL)
{
_currentState = _currentState();
}
}
I know, that I can workaround this using enum+switch, for example, but I'm just curious if I can do this.