4 ms·
Implementing a C-like for loop in Python
- throwayay93849 3y ago[flagged]
- ragestorm 3y ago[flagged]
- WaffleIronMaker 3y ago(2022)
- version_five 3y agoI'm almost certain this was already posted, but cannot find it in the history. I've definitely read it before. It's a bit disappointing, he ends up writing a preprocessor that translates his code into python, which doesn't really feel like a legitimate claim on implementing c-like loop syntax. The context manager stuff is interesting though.
- armanboyaci 3y agoYou are right. https://news.ycombinator.com/item?id=34643811 https://news.ycombinator.com/item?id=34643811
- behnamoh 3y agoTo me this article really shows the power of Lisp more than anything else. I’ve recently started learning about Racket and the freedom it gives you to make your own DSLs on the go with minimal effort is just mind blowing. Whether we actually want people’s custom macros and DSLs in production is another question, tho.
- oplaadpunt 3y agoYeah, the difference between manipulating the syntax being the intendend way, and it being possible only through hacking and dark magic is rather stark. It's fun to know that it is basically possible to do though, and I didn't know python had these obscure parts (ast manipulation and codecs)
- rob74 3y agoWhether manipulating the syntax is encouraged or only possible through black magic, the basic problem which GP was (I think) referring to stays the same: "modified" syntax may look more elegant to whoever wrote it, but probably makes the code harder to read and understand for whoever has to work with it later (and that may be yourself, a few years down the line). Plus of course this makes it easier for bugs to hide in unexpected places...