Skip to content

Instantly share code, notes, and snippets.

@MaddyGuthridge
Created May 11, 2025 14:50
Show Gist options
  • Select an option

  • Save MaddyGuthridge/c535fe55b1cdbc04c403a1cfe6822548 to your computer and use it in GitHub Desktop.

Select an option

Save MaddyGuthridge/c535fe55b1cdbc04c403a1cfe6822548 to your computer and use it in GitHub Desktop.
Arrow operator in Python
import ctypes
class ArrowInt(int):
def __neg__(self) -> int:
prev = int(self)
self_addr = id(self)
int_addr = self_addr + ctypes.sizeof(ctypes.c_size_t) + 2 * ctypes.sizeof(ctypes.c_void_p)
ctypes.c_int.from_address(int_addr).value = self - 1
# Return previous value so it loops a sensible number of times
return prev
x = ArrowInt(5)
while 0 <- x:
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment