frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Elliptical Python Programming

https://susam.net/elliptical-python-programming.html
184•sebg•1y ago

Comments

benob•1y ago
TIL that in python, 1--2==3
seplox•1y ago
It's not a python thing. 1-(-2), distribute the negative.
qsort•1y ago
In most C-like languages that would be a syntax error. E.g. in C and C++ as a rule you tokenize "greedily", "1--2" would be tokenized as "1", "unary decrement operator", "2", which is illegal because you're trying to decerment an rvalue.

Python doesn't have "--", which allows the tokenizer to do something else.

nyrikki•1y ago
In C, that is really because Unary minus (negation) has precedence over binary operations.

    +a - b; // equivalent to (+a) - b, NOT +(a - b)
    -c + d; // equivalent to (-c) + d, NOT -(c + d)

https://en.cppreference.com/w/cpp/language/operator_arithmet...

    +-e; // equivalent to +(-e), the unary + is a no-op if “e” is a built-in type
     // because any possible promotion is performed during negation already
The same doesn't apply to, !! Which is applied as iterated binary operations (IIRC)

I am pretty sure the decriment operator came around well after that quirk was established.

seanhunter•1y ago
Peter van der Linden’s book “Expert C Programming” (which is awesome btw) says that one of them (Kernighan, Richie or maybe Ken Thompson I forget) realised early on that the c compiler had the wrong operator precedence for bit twiddling and unary and boolean operators but “at that stage we had a few thousand lines of C code and thought it would be too disruptive to change it”
j2kun•1y ago
Also worth noting that `1 - -2` works and produces 3 in C because the space breaks the operator.
plus•1y ago
For those who are curious, `...` is a placeholder value in Python called Ellipsis. I don't believe it serves any real purpose other than being a placeholder. But it is an object and it implements `__eq__`, and is considered equal to itself. So `...==...` evaluates to `True`. When you prefix a `True` with `-`, it is interpreted as a prefix negation operator and implicitly converts the `True` to a `1`, so `-(...==...)` is equal to `-1`. Then, you add another prefix `-` to turn the `-1` back into `1`.

`--(...==...)--(...==...)` evaluates to `2` because the first block evaluates to 1, as previously mentioned, and then the next `-` is interpreted as an infix subtraction operator. The second `-(...==...)` evaluates to `-1`, so you get `1 - -1` or `2`.

When chaining multiple together, you can leave off the initial `--`, because booleans will be implicitly converted to integers if inserted into an arithmetic expression, e.g. `True - -1` -> `1 - -1` -> `2`.

> There should be one-- and preferably only one --obvious way to do it.

This article is obviously completely tongue-in-cheek, but I feel the need to point out that this sentence is not meant to be a complete inversion of the Perl philosophy of TIMTOWTDI. The word "obvious" is crucial here - there can be more than one way, but ideally only one of the ways is obvious.

pletnes•1y ago
Numpy actively uses … to make slicing multidimensional arrays less verbose. There are also uses in FastAPI along the lines of «go with the default».
abuckenheimer•1y ago
excellent explanation, to add to this since I was curious about the composition, '%c' is an integer presentation type that tells python to format numbers as their corresponding unicode characters[1] so

'%c' * (length_of_string_to_format) % (number, number, ..., length_of_string_to_format_numbers_later)

is the expression being evaluated here after you collapse all of the 1s + math formatting each number in the tuple as a unicode char for each '%c' escape in the string corresponding to its place in the tuple.

[1] https://docs.python.org/3/library/string.html#format-specifi...

elijahbenizzy•1y ago
Ok do this but for JavaScript
voidUpdate•1y ago
https://en.wikipedia.org/wiki/JSFuck
mariocesar•1y ago
If you're curious, the code in ellipsis results in executing:

    print('hello, world')
mturmon•1y ago
Thank you!

I noticed some ** and * in the thing sent to eval(), which (given that the building blocks are small integers) seemed related to prime factorizations.

The initial %c is duplicated 21 times (3*7, if I read correctly), and then string-interpolated (%c%c%c...) against a long tuple of integers. These integers themselves are composed of products of factors combined using * and **.

There is also one tuple "multiplication" embedded within that long tuple of integers -- (a,b)*2 = (a,b,a,b). That is for the 'l' 'l' in "hello".

It's all very clever and amusingly mathy, with a winking allusion to the construction of natural numbers using sets. It made me Godel.

callamdelaney•1y ago
I think we're really starting to over crowd pythons syntax and I'm not a fan.
noddleah•1y ago
you're telling me you never program in python elliptically??
acbart•1y ago
Pretty sure this would have been possible in Python 2.6. The Ellipsis object has been around for a very long time.
MadVikingGod•1y ago
This behavior can be replicated with any class that has two special methods: __neg__ that returns -1 and __sub__ that accepts ints and returns 1-other.

For example if you make this class:

  class _:
       def __neg__(self):
           return -1
       def __sub__(self, other):
           return 1-other
You get similar behavior:

  >>> --_()
  1
  >>> _()--_()
  2
Fun python for everyone.
maxloh•1y ago
You can do this on JavaScript too.

  alert(1)
  // equals to:
  [][(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[+!+[]+[+!+[]]]+[+!+[]]+([]+[]+[][(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[!+[]+!+[]]])()
https://jsfuck.com/
nomel•1y ago
Expanding on this a little, I will be replacing all occurrences of 2 with two blobs fighting, with shields:

    >>> 0^((...==...)--++--(...==...))^0
    2
rmah•1y ago
>> There should be one-- and preferably only one --obvious way to do it.

Except for package management, of course. There, we need lots and lots of ways.

blooalien•1y ago
And apparently string formatting which should have an ever growing number of ways to handle it. :shrug:

Run Qwen 3.8 Flash Next (125B) on consumer hardware (RTX 4090) at 100T/s

https://github.com/Niko1221/Strata
407•snehesht•6h ago•218 comments

A map of every lighthouse

https://mapped.earth/lighthouses/world
102•karakoram•2d ago•48 comments

'Neanderthals Among Us' review

https://www.historytoday.com/archive/review/neanderthals-among-us-peter-sahlins-review
16•pepys•22h ago•7 comments

Show HN: Glashütte Trash Clock – A 30-minute pendulum clock made from trash

https://niklasroy.com/gtc/
133•r0r0•2d ago•16 comments

Tell HN: Bob Cringely has died

741•paveworld•18h ago•154 comments

Results from the Jane Street hardware puzzle

https://blog.janestreet.com/asic-puzzle-results/
15•eru•2d ago•0 comments

Show HN: AI search for every photo and every frame of video on macOS

https://github.com/allenv0/SCM
97•allenleee•10h ago•54 comments

A Minsky machine in ncurses terminfo

https://seriot.ch/computation/terminfo/
21•beefburger•2d ago•4 comments

Building a RAG pipeline for semantic code search

https://blog.jetbrains.com/ai/2026/09/building-a-rag-pipeline-for-semantic-code-search-a-develope...
21•saikatsg•1h ago•3 comments

Why don't more developers “use the platform”?

https://nolanlawson.com/2026/10/03/why-dont-more-developers-use-the-platform/
251•vinhnx•15h ago•250 comments

VGHF Digital Archive passes 5000 magazines. Here's what's next

https://gamehistory.org/5k-magazines/
89•rdmuser•10h ago•16 comments

The work by Valve's Timur Kristóf on improving old AMD GPUs on Linux

https://www.phoronix.com/news/XDC-2026-Valve-Timur-AMDGPU
426•speckx•1d ago•81 comments

The Heilbronn Problem

https://math.tejstead.com/heilbronn/
49•tejstead•1d ago•9 comments

Emitting metadata early makes building/checking Rust up to twice as fast

https://github.com/PowderworksCode/headstart
101•knuckleheads•12h ago•26 comments

Agents don't need memory, they need documentation

https://liao.gg/blog/agents-dont-need-memory
314•kmeh•1d ago•192 comments

Surely you have ultra-wideband radios on your bins too?

https://sjg.io/writing/binrange-have-you-actually-put-the-bins-out/
106•simonjgreen•22h ago•59 comments

Treachery in the Rodin Museum 3D scan verdict

https://cosmowenman.substack.com/p/rodin-museum-3d-scan-verdict
289•CosmoWenman•1d ago•159 comments

Former SR-71 engineer talks NASA's Blackbird revival program

https://www.twz.com/air/former-sr-71-engineer-talks-nasas-blackbird-revival-program
90•rkagerer•1d ago•62 comments

LeCun has "zero concerns" about AI wiping out humanity, recent "rogue" incidents

https://fortune.com/2026/10/01/ai-godfather-yann-lecun-has-zero-concerns-about-human-extinction-s...
333•Anon84•1d ago•598 comments

Magic Switch: Share Apple Magic keyboard/track-pad/mouse between two Macs

https://joshua.hu/magic-switch-easily-switch-magic-keyboard-trackpad-mouse-between-mac-macbook-macos
69•chanux•2d ago•35 comments

What's the future for pure math research in the age of AI?

https://writings.stephenwolfram.com/2026/09/whats-the-future-for-pure-math-research-in-the-age-of...
46•6bitquant•11h ago•33 comments

L-systems generate weevils, pizza toppings, and matriarchal lineages

https://blog.plover.com/2026/09/25/
11•surprisetalk•2d ago•3 comments

Blindsight (Watts Novel)

https://en.wikipedia.org/wiki/Blindsight_(Watts_novel)
55•mooreds•3h ago•42 comments

Hole Punch: Sling your spaceship around gravitational fields

https://notoriousbfg.com/hole-punch/
343•trwhite•1d ago•85 comments

Celebrating the 100th birthday of the kidney donated to him as a teenager

https://www.whec.com/top-news/webster-man-celebrating-the-100th-birthday-of-the-kidney-his-mom-do...
257•gscott•3d ago•58 comments

I quit OpenAI because its culture is broken

https://www.theatlantic.com/technology/2026/10/openai-safety-team-resignation/688881/?gift=v5U_Uz...
429•Brajeshwar•1d ago•705 comments

Reasons I didn't become an EMT, ranked

https://ben.stolovitz.com/posts/reasons-not-emt-ranked/
216•citelao•22h ago•103 comments

We want you to build the next Git platform on Cloudflare

https://blog.cloudflare.com/next-git-platform-on-cloudflare/
205•geoffbp•23h ago•172 comments

We're going to need default hard budget caps on pretty much everything

https://simonwillison.net/2026/Oct/3/default-hard-budget-caps/
572•elffjs•19h ago•290 comments

Dirty Optimization Secrets (C for Playdate)

https://devforum.play.date/t/dirty-optimization-secrets-c-for-playdate/23011
66•ibobev•2d ago•7 comments