osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

About the implementation of del in Python 3


Steve D'Aprano <steve+python at pearwood.info>:

> On Fri, 7 Jul 2017 08:56 am, Marko Rauhamaa wrote:
>
>> Google finds a Dutch master's thesis from 2009 that gives formal
>> semantics to a subset of Python. I was interested in seeing how it
>> treated identity. Lo and behold:
>> 
>>    The is operator determines whether its operands are the same object.
>>    This is achieved by comparing the addresses of the operands.
>
> Well, that's a fail, because the author fails to distinguish between
> an implementation detail of one specific Python interpreter with a
> language feature.

It is not a fail. The author defines Python's semantics by mapping
("compiling") its syntax to an idealized mathematical computer. IOW, you
need to "implement" Python somehow to define its semantics.

The author chose to use the word address. He defined "address" as a
natural number:

   The heap is a mapping of addresses to values. Addresses are
   represented by natural numbers. Values include integers, strings,
   functions and objects. [p. 15/91]

Feel free to define alternative semantics for Python. You don't even
have to use the word "address". However, your semantics will be
equivalent in that they generate the same observed behavior as this
master's thesis.

BTW, this appendix to a Scheme standard gives semiformal semantics to
Scheme: <URL http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-15.html>. It
uses concepts such as "store", "location" and "pointer".

> But you know that, because you've been around to hear us say so
> probably a dozen or fifty times. So I wonder what on earth you think
> this proves except that the thesis author *got it wrong*.

The author would have gotten it wrong only if his semantics misbehaved.


Marko