Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Overriding function and adding a bit Date: Sun, 14 May 2017 03:07:16 +0100 Organization: A noiseless patient Spider Lines: 115 Message-ID: <87fug8cht7.fsf@bsb.me.uk> References: <5178377.MhkbZ0Pkbq@PointedEars.de> <20479369.6Emhk5qWAg@PointedEars.de> <579d836f-190f-488b-859a-2d1320aa8242@googlegroups.com> <878tm0edlc.fsf@bsb.me.uk> <87wp9kcqh8.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="4567f39464f93982416bb7b5de1a8617"; logging-data="14558"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8zUc47nW6dXhItt4vGad1lkEPGiQIeqQ=" Cancel-Lock: sha1:dQuL5p0Ewjbs5lDTz2rbLFYXLNs= sha1:yUfnOzUcLTVBmrwows2tMlKNXOI= X-BSB-Auth: 1.a6f044511048f03906cd.20170514030716BST.87fug8cht7.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:33313 ram@zedat.fu-berlin.de (Stefan Ram) writes: > Ben Bacarisse writes: >>ram@zedat.fu-berlin.de (Stefan Ram) writes: >>>Ben Bacarisse writes: >>>>There can be no reasonable doubt that ECMAScript is an object-oriented >>>>language >>>Alan Kay coined the term »object-oriented« in 1967, >>>and he wrote to me in an e-mail in 2003: >>Wikipedia says he coined it with others when at Xerox PARC, but he >>joined PARC in 1970 (again, just Wikipedia as the source). I'm not >>saying you're wrong, just curious about the various sources. > > He also wrote to me: > > |>When and where was the term "object-oriented" used first? > | > |At Utah sometime after Nov 66 when, influenced by Sketchpad, Simula, > |the design for the ARPAnet, the Burroughs B5000, and my background in > |Biology and Mathematics, I thought of an architecture for > |programming. It was probably in 1967 when someone asked me what I was > |doing, and I said: "It's object-oriented programming". > > (see the web for the complete e-mail) > >>That's because in Smalltalk (the archetype for "Kay object-oriented" >>programming) the classes (to which objects belong) are themselves are >>objects, so you have direct access to what is essentially a prototype in >>JS. > > JavaScript is also inspired by Scheme, which is a kind of LISP. Ah but, critically, not the sort that Kay was talking about. Scheme does not have the sort of late binding of earlier LISPs. Obviously, some late-binding mechanism could be implemented if an object-oriented structure were built on top of Scheme, but it's not there at the core. But JavaScript does have late binding of the sort in question. > Kay wrote »LISP«, which is the classical spelling. Today, »Lisp« > is used to refer to modern Lisps with CLOS. I am not sure whether > Kay was referring to classical LISPs without CLOS, which would not > make a lot of sense to me. He was writing in 2003 so he was very likely reffering to Common Lisp (but not, I think, to the cleaner Lisps). Whether CLOS itself meets his strict definition, I'm not sure. I think it does, but an object system that did could surely be written in Common Lisp. > In Smalltalk, blocks of codes are objects too. This was missing in > Java, C++, and JavaScript in 2003. But today all of these languages > have lambda-like expression which can be use somewhat like > smalltalk code blocks. Right, though I don't think they are central to anyone's view of object-oriented programming. > Stefan Matthias Aust wrote a post in 2004 where he explained > something like this: In Smalltalk, we can create a class > »Boolean« and two subclasses »True« and »False«. In »True« > we can define: > > ifTrue: aBlock > ^aBlock value > > and in »False« > > ifTrue: aBlock > ^nil > > . Now we have implemented an if statement using polymorphism. > It can be used as > > a > 0 ifTrue: [a := 0] > > . »a > 0« will create an object of class »True« or of class > »False«. This object then will receive the message »ifTrue: > [a := 0]«. If the object has the class »True«, the block > will be evaluated, otherwise »nil« will be returned. (End of > what Stefan Matthias Aust explained, here given in my wordings. > All errors in the explanation are mine [Stefan Ram's], not > Stefan Matthias Aust's.) > > So in Smalltalk, even the control structures conceptually > are implemented in terms of messages and polymorphism > (while an implementation might not actually implement them > this way for reasons of efficiency). Yes. Something similar can be done (without classes) in the lambda calculus. In JavaScript you could do this with True = x => y => x False = x => y => y and then, if Boolean constructs gave True or False rather than JavaScript's true or false, a conditional would be written test (()=> then-code) (()=> else-code) () JavaScript's blocks are rather ugly since they require and empty parameter list. Now, Boolean expressions don't yield True or False so we'd have to write the if function like this: If = Cond => Then => Else => (Cond ? True : False)(Then)(Else)() so, finally, we can write If (a > 0) (()=> a = 0) (()=> null) It's not the same, of course, but I thought it would be useful to show how one really does not need control structures at all! -- Ben.