3 ms·
Functional Programming in C# 3.0: How Map/Reduce/Filter can Rock your World
- ajross 18y agoI think the author is a little confused on terminology. The list management he's talking about, while a core part of the LISP metaphor, isn't normally considered part of "functional programming", which exploits more subtle stuff like lexical closures instead of "code-only" function/method references (a lambda is much more than just a function pointer!). Now, I'm not up on my .NET these days, but I'm all but certain a C# function is still a classic CPU call, with its data living on a normal CPU stack and not stashed into the heap somewhere where it can be found by a closure. Am I wrong?
- olavk 18y agoC# anonymous functions are true lexical closures, if that is what you are asking.
- ajross 18y agoHunh. Yuck. So how does that work at the instruction level? It seems like the generated code needs to take one of two wildly divergent paths depending on whether or not a scope includes a lambda or not. Either that, or you need to malloc the stack frame of every function that gets called, which is equally a mess.
- orib 18y agohttp://people.debian.org/~aaronl/Usenix88-lexic.pdf http://people.debian.org/~aaronl/Usenix88-lexic.pdf ddescribes non-escaping lexical closures for C++. With a bit of work (automated clone-env-on-escape, for example) you can have efficient closures that don't totally suck.