The type/object distinction and possible synthesis of OOP and imperative programming languages

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Apr 17 02:40:42 EDT 2013


On Tue, 16 Apr 2013 15:38:29 -0700, Mark Janssen wrote:

> On Mon, Apr 15, 2013 at 3:32 PM, Chris Angelico <rosuav at gmail.com>
> wrote:
>> On Tue, Apr 16, 2013 at 8:12 AM, Rotwang <sg552 at hotmail.co.uk> wrote:
>>> Traceback (most recent call last):
>>>   File "<pyshell#2>", line 1, in <module>
>>>     class C(type(lambda: None)):
>>> TypeError: type 'function' is not an acceptable base type
>>>
>>>
>>> and I don't think that FunctionType would be considered an "internal
>>> detail", would it? Not that I'd cite the fact that not all types can
>>> be inherited from as evidence that types and classes are not synonyms,
>>> mind.
>>
>> Actually, I'm not sure how you'd go about inheriting from a function.
>> Why not just create a bare class, then assign its __call__ to be the
>> function you're inheriting from?
> 
> I think his point remains valid, from a theoretical pov.  Python prides
> itself on the idea of "first-class functions" and such, but unlike the
> world of lambda calculus, this selling point is a bit invalid.


Python functions are first-class functions, which is short-hand for 
saying "functions which are also capable of being treated as values, 
which means they can be created at run-time, returned from functions, 
passed around as arguments, and assigned to variables".

Python's function type is not a first-class object-type, because it 
cannot be subclassed in at least three of the main implementations. But 
this has nothing to do with whether or not functions are first-class 
functions, which is an unrelated meaning. One can conceive of a language 
where FunctionType is a first-class type capable of being subclasses, but 
functions are *not* first-class values capable of being passed around as 
arguments.



> Because for Python (and any C-based language), 

Python-the-language is not C-based, or at least, very little of Python is 
C-based. It's main influences are, according to GvR, Lisp and ABC, with 
Pascal, Haskell and of course C also having some influence. Syntax-wise, 
it is much more of an Algol-inspired language than a C-inspired language.



> it is roots squarely in the
> Turing machine and its real-word implementation.

Python is certainly not inspired by Turing machines. Since a Turing 
machine is a simple device with an infinitely long paper tape which can 
have marks added and deleted from it, very few real programming languages 
are based on Turing machines.

It is, however, Turing-complete. Just like every programming language 
worthy of the name, whether it has syntax like Python, C, Lisp, Forth, 
INTERCAL, Oook, Applescript, Inform-7, Java, PHP, or x86 assembler.


>   (Note this contrasts starkly with Java(script), which doesn't seem
> to be based on anything -- can anyone clarify where Java actually comes
> from?)

C.



-- 
Steven



More information about the Python-list mailing list