4 ms·
Peculiar Self-References
- malf 5y agoThis is the first true “PHPism” I’ve seen in a “real language”. (Is there a name for “we didn’t want the general thing (e.g. assignment expressions) but we wanted one narrow subset of it (serial assignment), so we implemented that, but with different semantics for no good reason”?)
- oxson 5y agoPython does have assignment expressions these days, too. They have some restrictions though, they’re not allowed in all positions that a ”standard” expression would be.
- cecilpl2 5y agoNeat idea! Seems like the following less-confusing assignment also works: a = [0] a[0] = a
- tshaddox 5y agoYeah, this article is more about the chained assignment syntax in Python which might not be on the radar for a lot of Python coders. There’s nothing particularly interesting about the self-reference. You can do the same thing with bog-standard idiomatic code: just make an empty list and append it to itself.