2 + 2 = 5

Cameron Simpson cs at zip.com.au
Wed Jul 4 22:06:07 EDT 2012


On 04Jul2012 19:39, Evan Driscoll <driscoll at cs.wisc.edu> wrote:
| On 7/4/2012 14:37, Paul Rubin wrote:
| > I just came across this (https://gist.github.com/1208215):
| > 
| >     import sys
| >     import ctypes
| >     pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
| >     five = ctypes.cast(id(5), pyint_p)
| >     print(2 + 2 == 5) # False
| >     five.contents[five.contents[:].index(5)] = 4
| >     print(2 + 2 == 5) # True (must be sufficiently large values of 2 there...)
| > 
| > Heh.  The author is apparently anonymous, I guess for good reason.
| 
| Probably just nostalgic for old Fortran, which, supposedly, allowed you
| to change the values of literals by passing them to a function by
| reference and then modifying the value.

Yeah, I was thinking that too. Because all parameters were pass-by-reference
in early fortran IIRC. You could, for example, set pi to 3.
-- 
Cameron Simpson <cs at zip.com.au>

If I have seen farther than others, it is because I was standing on the
shoulders of giants.    - Isaac Newton

If I have not seen as far as others, it is because giants were standing on my
shoulders.              - Hal Abelson

In computer science, we stand on each other's feet.     - Brian K. Reed



More information about the Python-list mailing list