3 ms·
You golf a lambda and then deride walrus in the same comment? Please explain yourself. And if you really want to make the perfect lambda, you can do that with
by sitkack 5y ago
You golf a lambda and then deride walrus in the same comment? Please explain yourself.
And if you really want to make the perfect lambda, you can do that with code generation and frame walking/patching.
http://farmdev.com/src/secrets/framehack/index.html http://farmdev.com/src/secrets/framehack/index.html
- wnoise 5y agoThe example lambda isn't "golfing". It's just plain more readable than naming the function. Introducing side-effects in the middle of expressions with the walrus operator is weird semantics, though admittedly sometimes very convenient.
- xigoi 5y agoI like the walrus operator for working with the regex module. if match := re.search(r"Score = (\d+)", data): print(match[1]) else: print("Not found")
- klyrs 5y agoThat wasn't golf. Are you going to tell me that this is more legible? lambda i, t: t[0][i] + t[1][i] edit: and... that frame hack thing is fun, but what does it have to do with anything? Also, note that I don't "deride" the walrus operator. But it does smack of inconsistency. Are we aiming for clean notation or not?
- sitkack 5y agoYou want tuple params back into an inlined function declaration? You can do that with a framehack. One of the examples from the link is Ruby style string interpolation, f-strings in Python, before f-string support. You can fight Python on lambda support, or you can build the language you want. It gives you the tools. I am not arguing about lambda legibility, but tilting at windmills rather than just walking around them. They can't move.
- abecedarius 5y agoDo you really use framehacks in production for the sake of syntactic sugar like this? It's fair that Python can do this sort of thing[0], but it seems like begging for trouble to make it load-bearing without a very strong reason. [0] That level of access was essential when I was working on https://codewords.recurse.com/issues/seven/dragon-taming-with-tailbiter-a-bytecode-compiler https://codewords.recurse.com/issues/seven/dragon-taming-wit...
- sitkack 5y agoIf the local sugar leads to a lower incidence of diabetes, then yes. I have never had a framehack spontaneously break. Self proclaimed Pythonistas of course make a sour face, like their God was offended, but that isn't a logical argument against. I really enjoy your compiler art, please keep it up. Are you doing anything with Wasm these days?
- abecedarius 5y agoThank you! I dislike style nazis too, e.g. carping when Peter Norvig's code won't pass PEP 8. I'm just leery of the expected cost in this kind of case. It can go on working for years until some new complication or some change in the ecosystem makes it suddenly create a really weird problem. Or when you want to try moving to a fancy new Python implementation, you find you have this friction. Matter of judgement where some chance of such messes is paid for by what it can do for you. (Of course when it's less "load bearing" the balance shifts.) With https://coverage.readthedocs.io/en/stable/ https://coverage.readthedocs.io/en/stable/ for example, it used bytecode hacks to do something you couldn't do otherwise, and that's unlikely to mess you up. I have had old C programs go crazy years later in a really hard to debug way because newer compilers may interpret your code like your ex-wife's divorce lawyer (as Kragen put it). Back in the day a lot of us thought we had a different kind of relationship with C compilers, and it'd be fine to code to that informal social contract. (Just a loose analogy.) I'm piddling away at https://github.com/darius/cant https://github.com/darius/cant these days. (Some of the motivation was feeling too confined by Python, actually.) No Wasm, but I'm happy it exists! I tried to make a system like it 20 years ago (Idel) and gave up too soon.