Anyway, if you found this interesting, you might enjoy Eli Bendersky's blog post from nearly 15 years ago where he adds an "until ... do" statement to Python.
https://eli.thegreenplace.net/2010/06/30/python-internals-ad...
I suspect that’s mostly because the `until` statement is more complex - but another factor seems to be Python’s change in parsing technology from LL(1) to PEG.
I have worked on a similar series of CPython customization articles that you might find interesting:
I would say it's a good thing, I don't want to see a hundred of half baked, badly tested and vaguely document DSL with no decent tooling support.
The reason we don't have such metaprogramming available everywhere is mostly because you have to subscribe to a particular ideology to allow it. If you think programmers are generally intelligent and responsible, you put macros and metaclasses in your language. If, on the other hand, you think most programmers are dumb code monkeys (with a few exceptions, maybe) your language becomes like early Java or early Go.
Since you mention it, Python does have a fairly elaborate metaclass system, but it seems like it's only really used for implementing the language and rarely if ever wielded by "users". I guess that's a reflection of the language ideology you're talking about.
Also for what it's worth, I know myself to be a dumb code monkey, but being in the CRUD gutter doesn't preclude me from looking at the metasyntactic stars.
pyhton-dev is a corporate shark tank where only personalities and employer matter (good code or ideas are optional).
Incidentally this turns out to be super hard to search for without asking an LLM, since "python coding" is so overloaded, and using the feature this way is intentionally undocumented because it's not really what it's for, and not something I think most python users really want to encourage. So, forbidden python knowledge!
spam = eggs if bar
# vs
spam = eggs if bar else None
Let's say you hate significative spaces, here is a (very fragile) PoC for your pain:
https://0bin.net/paste/42AQCTIC#dLEscW0rWQbE70cdnVCCiY72VuJw...
Import that into a *.pth file in your venv, and you can then do:
# coding: braces_indent
def main() {
print("Hello, World!")
if True {
print("This is indented using braces.")
}
}
You also can use import hooks (python ideas does that), bytecode manipulations (pytest does that) or use the ctypes module (forbiddenfruit does that).Still, I'm very happy it stays limited to super specific niches. Big power, big responsibilities, and all that.
Rust for example has a solution for this in std, there's a `bool::and_some` method (and `bool::then` that takes a closure to avoid eagerly evaluating the value), but `if { ... }` isn't an expression like `if { ... } else { ... }` is, probably to avoid coupling the language to `Option`.
When this comes up I usually link to the work of Alan Kay and others (the very mystical sounding STEPS project at VPRI)
""" The big breakthrough is making it easy to create new DSLs for any situation. Every area of the OS has its own language (and you can just add more if you feel the need) so that the whole OS including networking and GUI is very compact, understandable, and hackable. This particular project focused on compactness, just to prove that it is quantitatively more expressive. """
comment by sp332 https://news.ycombinator.com/item?id=11687952
final report from 2016 https://news.ycombinator.com/item?id=11686325
x = func1() if something else func2()
In this example, only func1() or func2() is being called, but not both. Above all the wonders of Lisp's pantheon stand its metalinguistic tools; by their grace have
Lisp's acolytes been liberated from the rigid asceticism of lesser faiths. Thanks to Macro and
kin, the jolly, complacent Lisp hacker can gaze through a fragrant cloud of setfs and defstructs
at the emaciated unfortunates below, scraping out their meager code in inflexible notation, and
sneer superciliously. It's a good feeling.
-- iterate manual, A.1 Introduction
do..while is also the example used here https://www.tcl-lang.org/man/tcl9.0/TclCmd/uplevel.html x = if something:
func1()
else:
func2()
Would not work. At least that is what I imagine when it is said "make if an expression".The members occupy different chairs in the PSF, Steering Council and the all-powerful CoC troika. They rotate, sometimes skip one election and then come back.
Their latest achievement is the banning of Tim Peters and others:
https://news.ycombinator.com/item?id=41234180
https://news.ycombinator.com/item?id=41385546
Tim Peters is just the tip of the iceberg. Many bans are private, intimidation is private.
Steering council members can insult, bully and mock others without any CoC consequences for themselves and keep getting elected. That is how you know that they are in the inner circle.
Python is intended to enforce a strong distinction between statements and expressions (`:=` notwithstanding :/) because it sidesteps a lot of questions that one might otherwise ask about how it's intended to be parsed (including by humans).
Being able to write something like your example makes it harder to figure out where the end is, figure out what happens if there's more than one statement inside an `if` (do we only consider the result of the last expression? What if the last thing isn't an expression?), etc. By the time you get to the end of understanding what's happening inside the block, you can lose the context that the result is being assigned to `x`.
At the other extreme, everything is an expression, and you have Lisp with funky syntax. But Python holds that this syntactic structure is important for understanding the code. I sense that this is part of what "Flat is better than nested" is intended to mean.
We could have done that in the v3 switch, but we decided to spend man-centuries of effort on chasing already deprecated legacy Windows Unicode semantics instead.
(spam := eggs) if bar
I think that seems reasonable? It would act just the same as it already does with an explicit `else None`, if I'm not mistaken. I don't find it beautiful though.
I'm not advocating for this feature to be added to Python, just explaining why it's not confusing in Ruby.
for line in open("python_yacc.py"):
if line =~ m/def (\w+)/:
print repr($1)
See http://www.dalkescientific.com/writings/diary/archive/2008/0...I started by writing a Python grammar definition based on PLY (see http://www.dabeaz.com/ply/) , then tweaked it to handle the new feature and emit the right AST. It's when I discovered the following was valid Python:
>>> a=b=c=d=e=1
>>> del a, (b, (c, (((((d,e)))))))
I don't think PLY can handle the newest Python grammar, but I haven't looked into it.For what it's worth, my Python grammar was based on an older project I did called GardenSnake, which still available as a PLY example, at https://github.com/dabeaz/ply/tree/master/example/GardenSnak... .
I've been told it's was one of the few examples of how to handle an indentation-based grammar using a yacc-esque parser generator.
Being nice to new people is a standard tactic for any divide-and-conquer organization. The politicians get more followers and get free positive comments on the internet that drown out criticism. The politicians don't have to work (some of them literally never did in CPython) and can pose as leaders and managers.
For the other 60, if someone was friendly to them 30 years ago, they still think he is a awesome chap even if he is now a venomous bureaucrat.
Approval voting is used, and SC members often sail through with just 30 of 90 votes. The pool of candidates is limited due to lack of interest and the perception that only the inner circle will somehow get the required low bar of around 30 votes. Also, people are intimidated since the SC ruins careers and gets away with lying.
The whole thing has the dynamics of a high school party where somewhat popular people dominate the scene and a handful of intelligent people stand in the corner and wonder where the popularity comes from.
It is all a deeply unprofessional setup.
It seems that the active developers are either in "the group", don't care (because they can get their work done), or care and now suffer the consequences.
And it seems the majority strictly doesn't care. Which is strange, but ... Python is old, and has its conservative-ish status quo, so it kind of makes sense (at least in my interpretation) that most eligible voters basically represent Python's "past" and doesn't really want much to do with its "future" (and present, apparently).
Do core devs lose their vote if they don't contribute for some time? Is there some kind of publish-or-perish thing?