4 ms·
You can fake objects and subclassing with closures, in addition to making it trivial to implement the "one method interface" (aka "functor"). http://roboprogs.
by Roboprog 14y ago
You can fake objects and subclassing with closures, in addition to making it trivial to implement the "one method interface" (aka "functor").
http://roboprogs.com/devel/2010.06.html http://roboprogs.com/devel/2010.06.html (example using a subset of JavaScript, rather than a language likely to be unfamiliar to most)
TODO: edit example someday to get rid of "useless use of local variables" (in place of original formal parameters), fix where I call the outer functions "closures" instead of the inner functions.
Of course, it's easier to work with both real objects AND real functions/closures/lambdas -- I can use a hammer and a screwdriver :-)
- daxelrod 14y agoI always thought this koan summed up this concept best: http://stackoverflow.com/a/501053/580947 http://stackoverflow.com/a/501053/580947
- seanmcdirmid 14y ago> Of course, it's easier to work with both real objects AND real functions/closures/lambdas -- I can use a hammer and a screwdriver :-) But do you hit your screwdriver with the hammer, or do you twist your hammer with the screwdriver? This can be a real problem if one programs in Scala.
- Roboprog 14y agoNot too often, but I find myself using the screwdriver for a chisel, and the hammer for a plumb bob. I probably need to buy more tools :-)