frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

John Carmack on Updating Variables

https://twitter.com/ID_AA_Carmack/status/1983593511703474196
5•birdculture•6h ago

Comments

timonoko•4h ago
Hey @grok, there was something wrong with exec("a=1"), maybe the "a" turned into global or something?

Thought for 45s

Yes, you're spot on that there's a gotcha with exec("a=1")—it behaves unexpectedly (and frustratingly) when used inside a function, and it often feels like the assignment "disappears" or ends up in the wrong scope. This isn't a bug, but a deliberate (if quirky) design choice in Python tied to how local variables are optimized for speed. Let me break it down with examples, explain why it happens, and suggest workarounds.The Issue in a NutshellAt the global/module level (e.g., in a script or interactive shell outside a function), exec("a=1") works fine: it assigns a=1 to the global namespace, and you can access it directly. Inside a function, things go sideways:If a is already declared as a local (e.g., a = 0 before the exec), the assignment updates the locals() dictionary temporarily, but direct references to a in the function still see the old value. The change is "lost" for the rest of the function. If a hasn't been declared locally yet, exec("a=1") sets it in locals(), but trying to access a directly raises a NameError (Python treats it as a global lookup, which fails).

In neither case does it automatically become a global unless you explicitly tell it to (more on that below). Your hunch about "global or something" is close but not quite—it ends up in limbo in the locals() dict without affecting normal variable access.

This stems from Python's bytecode optimization: Local variables in functions are stored in fast-access "slots" compiled at function-definition time. exec runs dynamic code that doesn't know about those slots, so it can't update them. Instead, it fiddles with the locals() dict (a proxy/snapshot), which the interpreter ignores for direct access.

Claude Pirate: Abusing Anthropic's File API for Data Exfiltration

https://embracethered.com/blog/posts/2025/claude-abusing-network-access-and-anthropic-api-for-dat...
1•ianrahman•1m ago•0 comments

RISC-V takes first step toward international ISO/IEC standardization

https://riscv.org/blog/risc-v-jtc1-pas-submitter/
1•jrepinc•1m ago•0 comments

Building implementation capacity (across states) in K-12 education

https://www.governance.fyi/p/can-you-actually-build-implementation
1•toomuchtodo•2m ago•1 comments

Front-Panel Booting an ATmega88 Microcontroller [video]

https://www.youtube.com/watch?v=S-2adBkW7Xo
1•ruik•3m ago•0 comments

Ruby Community Reflections

https://ryanbigg.com/2025/10/ruby-community-reflections
1•speckx•4m ago•0 comments

State of ClojureScript 2025 Survey is live

https://state-of-clojurescript.com/
1•roman01la•4m ago•0 comments

Equinix revealed as occupant of £3.9B UK datacenter campus

https://www.theregister.com/2025/10/30/equinix_datacenter_hertfordshire/
1•Bender•6m ago•0 comments

3Dfx Voodoo2 on a Modern PC (FAQs Answered) [video]

https://www.youtube.com/watch?v=91sEpXHnCOk
1•mariuz•6m ago•0 comments

France jacks into the Matrix for state messaging – and pays too

https://www.theregister.com/2025/10/30/france_matrix/
4•Bender•6m ago•0 comments

Fault Diagnosis of Ball Bearing Induction Motors for Predictive Maintenance

https://www.mdpi.com/2075-1702/13/10/902
1•PaulHoule•7m ago•0 comments

Security hole can crash billions of Chromium browsers Google hasn't patched

https://www.theregister.com/2025/10/29/brash_dos_attack_crashes_chromium/
2•Bender•8m ago•0 comments

Show HN: Aye Chat: AI-First development in your terminal

https://github.com/acrotron/aye-chat
1•acro-v•9m ago•1 comments

Most Questions Asked Online

https://www.guinnessworldrecords.com/world-records/65971-most-questions-asked-online
1•bariumbitmap•10m ago•0 comments

AG's billboards show tools to 'discipline' kids: ear pinching, zori, broom, belt

https://www.guampdn.com/news/ags-new-billboards-show-tools-to-discipline-kids-from-ear-pinching-t...
2•sipofwater•10m ago•1 comments

Compassion at the Frontier – Buddhism and AI

https://buddhismai.substack.com/p/compassion-at-the-frontier
1•weishuhn•11m ago•0 comments

Japan's Anime Industry Grows 15% to a Record 25B Driven by Overseas Sales

https://deadline.com/2025/10/japan-animation-industry-overseas-sales-chao-godzilla-1236602700/
2•Marshferm•11m ago•1 comments

What Palantir Sees

https://www.nytimes.com/2025/10/30/opinion/palantir-shyam-sankar-military.html
1•Doches•11m ago•1 comments

International Criminal Court to ditch Microsoft for EU open source alternative

https://www.euractiv.com/news/international-criminal-court-to-ditch-microsoft-office-for-european...
4•lorinab•12m ago•1 comments

Vibe-Spec: Generate Specifications from Coding Agent Logs

https://marmelab.com/blog/2025/10/30/vibe-spec-generate-specifications-from-coding-agent-logs.html
1•fzaninotto•13m ago•0 comments

SolidGoldMagikarp

https://www.bryanbraun.com/2025/10/28/SolidGoldMagikarp/
1•speckx•13m ago•0 comments

Google Analytics 4 Bot Traffic Increase from China / Singapore

https://support.google.com/analytics/thread/378622882/google-analytics-4-bot-traffic-increase-fro...
1•nsoonhui•15m ago•0 comments

Extropic claims its new AI chip (TSU) is 10,000x more energy-efficient than GPUs

https://extropic.ai/writing/inside-x0-and-xtr-0
2•SweetSoftPillow•16m ago•1 comments

The Crunchbase Tech Layoffs Tracker

https://news.crunchbase.com/startups/tech-layoffs/
1•wslh•18m ago•0 comments

Another nuisance Facebook pixel lawsuit threat

1•jayess•20m ago•0 comments

ICE and the Smartphone Panopticon

https://www.newyorker.com/culture/infinite-scroll/ice-and-the-smartphone-panopticon
2•pseudolus•20m ago•1 comments

Estimating the Perceived 'Claustrophobia' of New York City's Streets

http://mfranchi.net/posts/claustrophobic-streets/
4•jxmorris12•22m ago•0 comments

Linkify.cool - One Link to Rule Them All

https://linkify.com
1•waxo-tech•23m ago•1 comments

Why Novels Matter

https://www.theatlantic.com/ideas/archive/2025/10/journalism-literature-media-trump/684752/
2•FinnLobsien•24m ago•1 comments

Germany bets billions on nuclear fusion for energy future

https://www.dw.com/en/nuclear-fusion-germany-bets-billions-on-technology-for-energy-future/a-7452...
3•doener•27m ago•0 comments

Why do AI models use so many em-dashes?

https://www.seangoedecke.com/em-dashes/
1•ingve•28m ago•0 comments