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:

Ultramarine 1 Flash

https://www.paperinstruments.com/ultramarine
85•i_rush_carriers•1d ago•20 comments

Tesla Roadster

https://www.tesla.com/roadster
1301•shekhar101•1d ago•2312 comments

Llama.cpp on a jailbroken PS5: run any GGUF model natively on the console

https://github.com/cobanov/PS5LM
231•Anon84•10h ago•62 comments

Claude reveals ECDSA curve origins

https://www.anthropic.com/research/ecdsa-curve-origins
769•ahlCVA•9h ago•293 comments

You could have invented transformers from memory

https://alexwang.ai/posts/associative-memory/
193•speckx•9h ago•57 comments

FLUX 3 Image Klein

https://bfl.ai/blog/flux-3-image-klein
137•gmays•9h ago•39 comments

Butlerian Jihad

https://dune.fandom.com/wiki/Butlerian_Jihad
127•wetwater•2h ago•69 comments

California is building a $400M shield for Yosemite's most dangerous highway

https://www.sfchronicle.com/california/article/yosemite-national-park-highway-140-22463847.php
19•danso•2d ago•6 comments

Show HN: Fakeipedia – Wikipedia for worlds that don't exist

https://fakeipedia.org
15•darajava•5h ago•4 comments

eBay Restricts Listings of Radio Equipment, but Exempts Ham-Band-Only Gear

https://www.arrl.org/arrlletterissue?issue=2026-10-15#eBay-Restricts-Listings-of-Radio-Equipment_...
195•7402•10h ago•153 comments

Apple ML Research: Muse Spark Open with MLX on Mac Studio

https://machinelearning.apple.com/research/mlx-distributed-inference
287•antipaul•15h ago•138 comments

A story of WiFi secrets, UART lockdowns and a damaged flash memory chip

https://adepts.of0x.cc/eufy-homestation2-firmware/
27•michidk•13h ago•2 comments

Designing more efficient quantum circuits with Claude

https://www.anthropic.com/research/designing-efficient-quantum-circuits
119•pretext•10h ago•24 comments

Flexport Is Hiring a Biz Ops Leader in Office of CEO

https://www.flexport.com/company/careers/
1•thedogeye•3h ago

JPEG XL vs. AVIF for web use-cases

https://jakearchibald.com/2026/jpeg-xl-vs-avif/
221•farlight•12h ago•156 comments

Wireless magnetic millirobots that deliver medicine inside the beating heart

https://hub.jhu.edu/2026/10/12/magnetic-millirobots-cardiac-treatment/
83•giuliomagnifico•2d ago•10 comments

C++26: The New Debugging Header

https://www.sandordargo.com/blog/2026/09/30/cpp26-debugging
83•jandeboevrie•10h ago•14 comments

90% of US working hours are spent on tasks not covered well by AI benchmarks

https://www.mercor.com/research/labor-index/benchmark-map/
445•speckx•11h ago•389 comments

Monte-Carlo Simulations

https://eli.thegreenplace.net/2026/monte-carlo-simulations/
82•ibobev•3d ago•18 comments

How the Claude Code team does code review

https://claude.dev/blog/solving-code-review-at-anthropic/
280•pretext•9h ago•258 comments

Compiler bootstrapping depends on more than you might think

https://utcc.utoronto.ca/~cks/space/blog/programming/CompilerBootstrappingVsOSChanges
3•gavinhoward•2d ago•0 comments

Show HN: Gemini 4 Argon plays StarCraft

https://starskirmish.com/bench/v0-2/
201•__cayenne__•14h ago•90 comments

Nine-Inch Snails

https://www.theatlantic.com/science/2026/10/giant-african-snails-florida-invasion/688850/
41•zdw•6h ago•20 comments

New 'super ice' 10 times stronger, bringing it close to the strength of concrete

https://www.sciencealert.com/a-new-super-ice-is-10-times-stronger-bringing-it-close-to-the-streng...
90•andrewl•3d ago•64 comments

"In every study that considered the question"

https://unsung.aresluna.org/in-every-study-that-considered-the-question/
7•zdw•44m ago•3 comments

I built the RealWorld app in Lean 4

https://leangineer.com/blog/realworld-in-lean/
25•saviorand•2d ago•3 comments

I love software rendering

https://www.jamesfmackenzie.com/2026/10/13/i-love-software-rendering/
311•speckx•16h ago•196 comments

Big Fish: Exploiting a 37-Year-Old Kernel Bug in OpenBSD

https://calif.io/research/big-fish
172•rs_rs_rs_rs_rs•14h ago•48 comments

Stolen Renoir paintings found hidden, and damaged, behind cinder block wall

https://www.cbsnews.com/news/stolen-renoir-paintings-found-behind-wall-france/
113•ohjeez•3d ago•69 comments

Show HN: Wonderhop – A daily game: guess what most people say, or what none do

https://wonderhop.io/en/
80•mtlduo•3d ago•72 comments