frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

OpenCiv3: Open-source, cross-platform reimagining of Civilization III

https://openciv3.org/
624•klaussilveira•12h ago•182 comments

The Waymo World Model

https://waymo.com/blog/2026/02/the-waymo-world-model-a-new-frontier-for-autonomous-driving-simula...
926•xnx•18h ago•548 comments

What Is Ruliology?

https://writings.stephenwolfram.com/2026/01/what-is-ruliology/
32•helloplanets•4d ago•24 comments

How we made geo joins 400× faster with H3 indexes

https://floedb.ai/blog/how-we-made-geo-joins-400-faster-with-h3-indexes
109•matheusalmeida•1d ago•27 comments

Jeffrey Snover: "Welcome to the Room"

https://www.jsnover.com/blog/2026/02/01/welcome-to-the-room/
9•kaonwarb•3d ago•7 comments

Unseen Footage of Atari Battlezone Arcade Cabinet Production

https://arcadeblogger.com/2026/02/02/unseen-footage-of-atari-battlezone-cabinet-production/
40•videotopia•4d ago•1 comments

Show HN: Look Ma, No Linux: Shell, App Installer, Vi, Cc on ESP32-S3 / BreezyBox

https://github.com/valdanylchuk/breezydemo
219•isitcontent•13h ago•25 comments

Monty: A minimal, secure Python interpreter written in Rust for use by AI

https://github.com/pydantic/monty
210•dmpetrov•13h ago•103 comments

Show HN: I spent 4 years building a UI design tool with only the features I use

https://vecti.com
322•vecti•15h ago•143 comments

Sheldon Brown's Bicycle Technical Info

https://www.sheldonbrown.com/
370•ostacke•18h ago•94 comments

Microsoft open-sources LiteBox, a security-focused library OS

https://github.com/microsoft/litebox
358•aktau•19h ago•181 comments

Hackers (1995) Animated Experience

https://hackers-1995.vercel.app/
477•todsacerdoti•20h ago•232 comments

Show HN: If you lose your memory, how to regain access to your computer?

https://eljojo.github.io/rememory/
272•eljojo•15h ago•160 comments

An Update on Heroku

https://www.heroku.com/blog/an-update-on-heroku/
402•lstoll•19h ago•271 comments

Dark Alley Mathematics

https://blog.szczepan.org/blog/three-points/
85•quibono•4d ago•20 comments

Vocal Guide – belt sing without killing yourself

https://jesperordrup.github.io/vocal-guide/
14•jesperordrup•2h ago•6 comments

Delimited Continuations vs. Lwt for Threads

https://mirageos.org/blog/delimcc-vs-lwt
25•romes•4d ago•3 comments

PC Floppy Copy Protection: Vault Prolok

https://martypc.blogspot.com/2024/09/pc-floppy-copy-protection-vault-prolok.html
56•kmm•5d ago•3 comments

Start all of your commands with a comma

https://rhodesmill.org/brandon/2009/commands-with-comma/
3•theblazehen•2d ago•0 comments

Was Benoit Mandelbrot a hedgehog or a fox?

https://arxiv.org/abs/2602.01122
12•bikenaga•3d ago•2 comments

How to effectively write quality code with AI

https://heidenstedt.org/posts/2026/how-to-effectively-write-quality-code-with-ai/
244•i5heu•15h ago•188 comments

Introducing the Developer Knowledge API and MCP Server

https://developers.googleblog.com/introducing-the-developer-knowledge-api-and-mcp-server/
52•gfortaine•10h ago•21 comments

I spent 5 years in DevOps – Solutions engineering gave me what I was missing

https://infisical.com/blog/devops-to-solutions-engineering
140•vmatsiiako•17h ago•63 comments

Understanding Neural Network, Visually

https://visualrambling.space/neural-network/
280•surprisetalk•3d ago•37 comments

I now assume that all ads on Apple news are scams

https://kirkville.com/i-now-assume-that-all-ads-on-apple-news-are-scams/
1058•cdrnsf•22h ago•433 comments

Why I Joined OpenAI

https://www.brendangregg.com/blog/2026-02-07/why-i-joined-openai.html
132•SerCe•8h ago•117 comments

Show HN: R3forth, a ColorForth-inspired language with a tiny VM

https://github.com/phreda4/r3
70•phreda4•12h ago•14 comments

Female Asian Elephant Calf Born at the Smithsonian National Zoo

https://www.si.edu/newsdesk/releases/female-asian-elephant-calf-born-smithsonians-national-zoo-an...
28•gmays•8h ago•11 comments

Learning from context is harder than we thought

https://hy.tencent.com/research/100025?langVersion=en
176•limoce•3d ago•96 comments

FORTH? Really!?

https://rescrv.net/w/2026/02/06/associative
63•rescrv•20h ago•22 comments
Open in hackernews

Show HN: Tacopy – Tail Call Optimization for Python

https://github.com/raaidrt/tacopy
95•raaid-rt•2mo ago

Comments

anilakar•2mo ago
> This eliminates the risk of stack overflow errors

When you get stack overflows anywhere from a thousand down to fifty(!) frames in the stack it's not a risk, it's an inevitability in anything more complex than a programming tutorial.

Yeah, I've been bitten by this in production. Writing the functionality in a clean iterative style was just too much of a hassle.

phplovesong•2mo ago
TCO can be implemented easily in non TC optimized langauges with a trampoline wrapper.

Why do i need a fully fledged library for something that is basically a few lines of code?

srean•2mo ago
There's quite a bit of overhead.

I believe Clojure does it with trampoline as JVM does not (as far as I know) does not support tail call optimization. Ironic, given Guy Steele.

ndr•2mo ago
Yes, Clojure doesn't have TCO either.

You get `(loop ... (recur ...))` or `trampoline`.

Naive recursion will consume the stack.

https://clojuredocs.org/clojure.core/loop

https://clojuredocs.org/clojure.core/recur

https://clojuredocs.org/clojure.core/trampoline

pfdietz•2mo ago
Nor can you count on Common Lisp to have TCO. People who are new to CL and treat it like Scheme run into this constantly. Basically never recur down a list, since the list could be long.

This problem also shows up in cases where TCO is not possible. For example, suppose we have a syntax tree for some program and need to traverse the tree. Nodes that represent lists of things might have a long list of children, and in a sufficiently large program recursing down that list can blow out the stack. Just recurse on list elements, which one can reasonably assume don't nest too deeply.

srean•2mo ago
> Tacopy is a Python library that provides a decorator to optimize tail-recursive functions by transforming them into iterative loops.

Can this handle mutually recursive calls ? Because those are mostly the only place I use tail calls, rest I translate to iterative loops, list comprehension, maps and reduces.

pansa2•2mo ago
> Limitations […] No mutual recursion: Only direct self-recursion is optimized
srean•2mo ago
Oh! slapping head. How did I miss that. Thanks
javierbg95•2mo ago
Really cool project, fairly succinct and to the point :)

I would love to see support for arbitrarily nested functions, as it is common to wrap these into a public API function without the iteration parameters.

ndr•2mo ago
Yes, it is quite surprised they're not allowed. I wonder what's the likely limitation, any ideas?
ndr•2mo ago
Found out

> Nested function definitions with @tacopy decorators are not supported. Functions decorated with @tacopy must be defined at module level. This constraint exists because inspect.getsource() on nested functions returns the source of the entire enclosing function, making it impossible to reliably extract and transform just the nested function's code. The decorator detects nested functions by checking for '<locals>' in the function's __qualname__ attribute and raises a clear error message instructing users to extract the function to module level.

https://github.com/raaidrt/tacopy/blob/8f5db70da2b7bbfafc41b...

raaid-rt•2mo ago
Have some ideas on getting around this - stay tuned...
dkersten•2mo ago
Once upon a time I tried to write such a decorator too in python 2.x and the byteplay bytecode disassembler library. I was trying to do the conversion at the bytecode level instead of transforming the AST. I believe I got as far as detecting simple self recursive functions, but never actually managed to implement the actual transformation.
lioeters•2mo ago
That is an ambitious idea, and I applaud anyone who attempts such heights even if it turned out to be impractical.

OP's approach is surprisingly straight forward, only a few hundred lines.

https://github.com/raaidrt/tacopy/blob/main/src/tacopy/trans...

jagged-chisel•2mo ago
Taco Py. No Ta Copy. Took my brain a minute or so …
upghost•2mo ago
Really impressive! For anyone who's not a pythonista, trying to implement TCO is something akin to solving the Collatz conjecture but for Python. It's often just an exercise in madness. So seeing an elegant solution to this is really cool, I myself was a victim of this madness and was unable to do it so very cool to see someone nail it! This will be a goto tool for sure.
busfahrer•2mo ago
Fun fact: In Scheme, TCO is required by the spec
debugnik•2mo ago
EcmaScript too, but most browser JS runtimes don't (didn't?) support it. It's also part of .NET CIL but only F# uses it so support for it has historically been flakey outside the CLR's main JIT mode.
monster_truck•2mo ago
Safari's JSC (and much more recently, WebAssembly) are the only ones that actually implement it. In practice I don't think it actually ends up being any better than V8, which I believe has some amount of logic to replace them with iterators or trampolines when it can.

IIRC ES6 introduced PTC (Proper Tail Calls), Chrome had an experimental flag for a while but it introduced more issues than it solved (stack traces became a mess and the stack inspection changes came with realistic security concerns). Microsoft and Firefox refused to implement it. Safari refused to un-implement it, and also refused to adopt an opt-in per function flag.

It's crazy how fast javascript has gotten. Ported a classic game earlier this year using all of the new stuff in ES5/6/onwards, the benchmarks are within a couple of percent of what the perf would be were it a standalone game. Runs with 250x monsters at 30x the original tick rate, or >1000x as many monsters at the original tick rate.

artemonster•2mo ago
Can someone give some real world examples for TCO? Every time I see this I only see fibonacci and gcd and I really want to encounter this one in the wild on something real and applicable
threeducks•2mo ago
Tail calls can be used for parsing very efficiently: https://news.ycombinator.com/item?id=41289114
spapas82•2mo ago
For tco to be really useful you need to think in a non procedural way. Imagine that you don't have loops in your language so you need recursion to do stuff multiple times.

Also even in procedural languages there are some problems that are easier to understand and model if you use recursion, for example tree or graph like structures.

artemonster•2mo ago
traversing graph or a tree is not a TCO case because it would involve a stack/queue for DFS/BFS, whatever. I dont want to think in non procedural way, I reserve this nonsense to haskellers, please provide me a valid python use case for TCO :)
bfffbgfdcb•2mo ago
Traversing a graph and inspecting each node can definitely make good use of tail call optimization.

For instance: you have a large graph and you are traversing a particular path through it — say a R/B tree seeking a node. You can write it iteratively or recursively. Neither needs to hold more than 1 node reference at a time, the choice is which you prefer to read and write.

I prefer to write that recursively. Sounds like you may not. Observing “well I can write it iteratively so why do I need TCO” is obvious and uninteresting; that’s the point.

upghost•2mo ago
A really simple one is traversing a linked list (or any naturally recursive data structure, such as a dictionary or tree). It is very natural to traverse a recursive data structure recursively.
jhgb•2mo ago
It gives you arbitrarily complex control flow even in presence of modularity. A tail call is a state transition. Without them, you'd have to resort to a big loop (which breaks modularity), or some sort of trampoline (which works but it's a bit clumsy).
artemonster•2mo ago
this whole thing is equivalent to a goto at the beginning of a function.
jhgb•2mo ago
Yes, except without all the known disadvantages of goto. That's the whole point.
artemonster•2mo ago
huh? what is the disadvantage? i am very tired of people parroting some non-arguments. goto is awesome. solves TCO, multiloop breaks, switches and whole lot more
dragonwriter•2mo ago
This is true in the same sense that function calls are equivalent to gotos at the beginning and end of the function.
tpoacher•2mo ago
I don't know about real world "examples", but the beauty of tail-call recursion specifically is the theoretical insight that they have a one-to-one mapping with an loop-based equivalent formulation, and vice versa (which is generally not necessarily true of all recursion).

But, for languages that don't have loop constructs and you need to rely on recursion, all you need to do is write your recipe in standard loop form, and then map back to a tail-call syntax. This is often a LOT easier than trying to think of the problem in a recursive mindset from scratch. (though occasionally, the reverse is also true.)

So the only constraint for re-implementing such looped logic onto tailcalls is that this relies on the stack, which may overflow. By providing TCO you are effectively removing that restriction, so it's a very useful thing for a language to support (especially if they don't provide low-level loops).

The title "tail call optimisation" in the package above is a bit of a misnomer, since this is more of a "transformation" than an "optimisation", but effectively the whole loop-tailcall equivalence is exactly what the package mentioned above relies on to work; it uses decorators to transform tail-call recursive functions to their equivalent loop-based formulations, and thus passing the need to create multiple stacks for the recursion (and risk stack overflow), since the translated loop will now take place in a single stack frame.

artemonster•2mo ago
I know what TCO is. Screw the "beauty", honestly. I want to see at least one real world use case
creata•2mo ago
There isn't a killer use case, because tail calls (to yourself or to siblings) can always be easily converted to a loop, and the loop is more idiomatic in most mainstream languages.
jhgb•2mo ago
...and that costs you code modularity and separate compilation. Why lose them when you don't have to?
creata•2mo ago
Got an example?

Because it's hard to imagine real "modularity" between a bunch of functions that can cyclically call each other.

tpoacher•2mo ago
but i suspect you're talking about tail-recursion rather than TCO specifically. Otherwise the only sensible answer is, why on earth wouldn't you want that if you could have it for free?

so as for tail recursion examples, one nice example i had in the past which made thinking about the problem a lot easier than loops, was when I was designing a 3D maze-like game. The recuraion allowed me to draw each subsequent "step" visible on the screen without having to kniw in advance hiw many steps should be visible. you just draw the "next" room at increasing vanishing distance, until you hit a "wall" (the base case). It was a very simple, elegant result for minimal code; where the equivalent loop would have been long and horrible.

chuckadams•2mo ago
State machines come to mind: a transition is just a function call. Unfortunately that's a general tail call, not always a recursive one, so no love from this library, and that's where "proper" TCO wins (or trampolines if $your_language lacks TCO)

Also it wouldn't help with Fibonacci, since while it's recursive, it's not tail-recursive (yes, it can be written that way, but I'm talking about the idiomatic naive definition).

mwkaufma•2mo ago
Lua has mandatory TCO and several games I've been on which use it for a scripting use TCO for a state machine. Easy to debug - just look at the stack!
lukasnxyz•2mo ago
what is this, why is 95% of the file useless comments: https://github.com/raaidrt/tacopy/blob/main/src/tacopy/unpar...

you're calling a built in function, why make obfuscate this in an "llm way"

stingraycharles•2mo ago
I also don’t think it’s actually tail call optimization, but rather an “unrecurser”.

I’m also not convinced that this actually is worth the effort, considering it’s doing runtime rewriting of Python using Python.

throwaway81523•2mo ago
It's a suboptimal implementation but it's interesting for the purpose of transpiling something like Scheme or ML or maybe Purescript to Python.

Historically, suggestions to make Python tail recursive were rejected on the theory that the added stack frames helped debugging, and that Python was supposed to be an imperative language. But it has been dragged into supporting some FP idioms over the years and that has seemed like a good thing.

raaid-rt•2mo ago
Certain function calls that were unable to be run in Python can now be run. From that perspective, my thinking was that this was a net good since one can preserve the "clean syntax" from recursion while still being able to access the performance benefits of an iterative solution.
jasonjmcghee•2mo ago
It's very llm-y. But, kudos to them for preserving the commit history / being honest about it.
raaid-rt•2mo ago
Haha this is my first attempt at making an open-source tool - I don't really know what kind of comment hygiene we want here.
denys_potapov•2mo ago
Cool. Recursion in python is common bottleneck in competitive programming. Will give it a try. I created a similar tool for recursion [1]. But ended with rewriting AST and emulating stack. Pros - no need for accumulator, cons - almost unusable in real world.

[1] https://dev.to/denyspotapov/callonce-python-macro-for-unlimi...

qsort•2mo ago
Do you frequently use Python for competitive programming puzzles? I've done it a bit in the past, and everyone always used C++.
denys_potapov•2mo ago
Always. Probably you can't get in top 100 with python[1]. But I like dicts with tuple keys, bigints, all the list things.

[1] My best is around 1300 place in HackerCup.

btilly•2mo ago
I have to wonder how much better you'd do if they made pypy an option.
simonw•2mo ago
OK this is fun. I knocked up a quick browser-based playground to try it out: https://tools.simonwillison.net/tacopy-playground
raaid-rt•2mo ago
thanks for making this! - curious to hear if you had any suggestions for what else you'd want supported by this tool
hencq•2mo ago
From the description, it doesn't really seem to be full Tail Call Optimization, but only optimizes tail recursion. At least all the examples are about tail recursion, where the function calls itself in tail position, which can indeed easily be changed to a loop. Tail Call Optimization would mean it optimizes any function call in tail position. Typically you'd implement that with a trampoline, but it doesn't seem like this does that.

Edit: It's actually called out under limitations "No mutual recursion: Only direct self-recursion is optimized"

nonameiguess•2mo ago
It's always amusing to see what Python has become thanks to NumPy and Django and how widely deployed it became when its intended purpose was always to be easy to understand, not performant. But just like JavaScript, people are going to hack it to death to make it fast anyway.

Guido on tail calls 16 years ago: https://neopythonic.blogspot.com/2009/04/final-words-on-tail...

skylurk•2mo ago
It was not exactly the final word:

https://blog.reverberate.org/2025/02/10/tail-call-updates.ht...

spyc•1mo ago
The current implementation breaks semantics of functions with tail recursion from within loops: https://github.com/raaidrt/tacopy/issues/1