4 ms·
I actually tend to think that this kind of shows the folly of single-dispatch OO in general (prototypical or not), in particular its focus on privileging the fi
by lomnakkus 12y ago
I actually tend to think that this kind of shows the folly of single-dispatch OO in general (prototypical or not), in particular its focus on privileging the first parameter syntactically. The problem here is essentially that a freestanding function looks and thus (subjectively) "feels" different from a method. The syntax is obviously slightly different: "myArray.last()" vs. "last(myArray)". The latter stands out as slightly "alien" when compared to the other methods on Array.
Why should the first parameter be privileged? Why isn't it possible to add a new method to, say, Array which is scoped to your lexical context?
Even classic procedural programming didn't have this problem (as long as you don't need access to private data): Just add a function that does what you want and it'll look and behave just as the other functions on Array.
EDIT: Maybe the focus shouldn't be on adding a few convenience methods here and there, but rather on making the language itself more "pliable" or "growable" as Steele would probably say.
- jkrems 12y agoNothing prevents you from using a function (`last(myArray)`). In a dynamically typed language what you are proposing makes only very limited sense.
- lomnakkus 12y agoI'm not saying functions are bad or anything. They just "feel" wrong since they don't look like the built-ins. Regarding "dynamically typed": CLOS[1] got this right. Common Lisp is dynamically typed. In short: Dynamic/static typing has very little to do with this. [1] http://en.wikipedia.org/wiki/Common_Lisp_Object_System http://en.wikipedia.org/wiki/Common_Lisp_Object_System
- aikah 12y agoscoped monkey would be quite usefull? One could mess with prototypes yet keep them clean in the global scope. last(array) feels to much like C style OOP.
- underwater 12y agoI agree. C# has this feature. They call them extension methods. They alive the scoping issue quite nicely: http://msdn.microsoft.com/en-us/library/bb383977.aspx http://msdn.microsoft.com/en-us/library/bb383977.aspx