Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #33313

Re: Overriding function and adding a bit

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
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> (permalink)
References <RJGdnYVKAvCI6Y_EnZ2dnUU7-SXNnZ2d@westnet.com.au> <oevbsf$61c$1@dont-email.me> <5178377.MhkbZ0Pkbq@PointedEars.de> <of05sh$85g$1@dont-email.me> <20479369.6Emhk5qWAg@PointedEars.de> <of2n22$f1d$1@dont-email.me> <579d836f-190f-488b-859a-2d1320aa8242@googlegroups.com> <of7abv$1h6k$1@csiph.com> <878tm0edlc.fsf@bsb.me.uk> <OOP-20170513214952@ram.dialup.fu-berlin.de> <87wp9kcqh8.fsf@bsb.me.uk> <OOP-20170514004600@ram.dialup.fu-berlin.de>
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

Show key headers only | View raw


ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>>Ben Bacarisse <ben.usenet@bsb.me.uk> 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!

<snip>
-- 
Ben.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Overriding function and adding a bit Andrew Poulos <ap_prog@hotmail.com> - 2017-05-10 11:59 +1000
  Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-10 15:33 +0000
    Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-10 19:14 +0200
      Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-10 22:57 +0000
        Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-11 01:49 +0200
          Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-11 17:03 +0200
            Re: Overriding function and adding a bit Andrew Poulos <ap_prog@hotmail.com> - 2017-05-12 08:32 +1000
              Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-12 22:12 +0200
            Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-12 03:13 +0200
          Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-11 16:33 +0100
            Re: Overriding function and adding a bit Tim Streater <timstreater@greenbee.net> - 2017-05-11 18:54 +0100
          Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-11 22:02 +0000
            Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-12 01:53 +0200
              Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-12 10:05 +0100
              Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-12 21:43 +0000
                Re: Overriding function and adding a bit Tim Streater <timstreater@greenbee.net> - 2017-05-12 23:03 +0100
                Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-12 17:28 -0700
                Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-13 14:39 +0100
                Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 07:17 -0700
                Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-13 16:25 +0100
                Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 08:30 -0700
                Re: Overriding function and adding a bit Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2017-05-13 17:56 +0200
                Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 09:04 -0700
                Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-13 20:55 +0100
                Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 00:00 +0100
                Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 03:07 +0100
                Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 18:39 -0700
                Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-14 11:23 +0100
                Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-14 11:36 +0100
                Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 12:34 +0100
                Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-14 14:11 +0200
                Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 15:37 +0100
                Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-14 17:16 +0200
                Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-14 15:40 +0200
          Re: Overriding function and adding a bit Gene Wirchenko <genew@telus.net> - 2017-05-11 15:39 -0700
        Re: Overriding function and adding a bit Tim Streater <timstreater@greenbee.net> - 2017-05-11 10:39 +0100
    Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-11 10:05 -0700
  Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-10 19:13 +0200
    Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-10 19:22 +0200
    Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-11 10:08 -0700
  Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-11 09:56 -0700

csiph-web