Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created December 18, 2013 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/8019922 to your computer and use it in GitHub Desktop.
Save einarwh/8019922 to your computer and use it in GitHub Desktop.
Default f-function for consumers, given pops and pushes.
public Func<EvalStack, EvalStack> CreateConsumerF(int pops, int pushes)
{
Func<EvalStack, EvalStack> pop = stack => stack.Pop();
Func<EvalStack, EvalStack> push = stack => stack.Push(false);
Func<EvalStack, EvalStack> result = stack => stack;
for (int i = 0; i < pops; i++)
{
var fresh = result;
result = stack => pop(fresh(stack));
}
for (int i = 0; i < pushes; i++)
{
var fresh = result;
result = stack => push(fresh(stack));
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment