3 ms·
Smalltalk has always had lambdas in the form of block objects. It uses them everywhere and for everything, even implementing control flow constructs like if/the
by uname-s 11y ago
Smalltalk has always had lambdas in the form of block objects. It uses them everywhere and for everything, even implementing control flow constructs like if/then/else and while. It also uses them to implement Lisp-style higher-order iterators like mapcar (collect:), reduce (inject:into:), and remove-if-not (select:), which though possible in JavaScript (see Prototype.js), is generally uncommon because JavaScript's lambda syntax has historically been the most verbose of any dynamic language.
Anyone who claims lambdas are somehow new to or incompatible with OOP clearly doesn't understand OOP, since lambdas have been an integral part of the most influential pure OO language (Smalltalk) for 40 years.
- jwdunne 11y agoI've also seen very simple object systems built purely using closures in Lisp. I can't remember where I've seen it, but it usually involves the bank account example. Since no other Lisp features were involved,until you start glossing over with macros, this could be replicated in JS. It'd look strange but it's certainly possible, e.g: var savings = account(200); savings('deposit')(200); console.log(savings('amount')); // should print 400 savings('withdraw')(200); console.log(savings('amount')); // should print 200 If you can build an OO system in terms of lambdas and closures, does it mean the two are incompatible? I don't think so.
- spdegabrielle 11y agoI think it's this one http://okmij.org/ftp/Scheme/oop-in-fp.txt http://okmij.org/ftp/Scheme/oop-in-fp.txt
- spdegabrielle 11y agoBetter link http://okmij.org/ftp/Scheme/#pure-oo http://okmij.org/ftp/Scheme/#pure-oo
- lispm 11y agoThough it does not have lexical scope / closures for 40 years.