I am writing a Scheme-like in interpreter. It seems natural that the Scheme-like interpreter ought to work well with any object that implements IEnumerable.
The interpreter does not allow for mutation - no functions with side effects are exposed.
Because IEnumerable is not cloneable, (see here ), I can't implement iteration over the list efficiently using car and cdr.
In order to allow any "higher order" stuff to be efficient then, I've had to implement some primitives as C# builtins for the interpreter.
So far I have implemented the following "primitives" as C# builtin functions:
- filter
- map (the full map, not just mapcar)
- foldr
But I suspect, for example, that I could probably implement "filter" using a combination of map and foldr.
What is the minimal set of primitives I would need to expose as "builtins" such that I can implement any other functionality over IEnumerable instances without excess runtime or space costs, and without having to introduce mutation?