
On 31/10/2021 08:05, Steven D'Aprano wrote:
On Tue, Oct 26, 2021 at 08:59:51AM +0100, Rob Cliffe via Python-ideas wrote:
And I don't understand what point you're making here. Yes, the walrus operator can appear in various places, how is that relevant? You could write def f(a := (b := c)): which might be a tad confusing but would be unambiguous and legal, just as def f(a = (b := c)): is currently legal (I tested it). I don't see a clash. If we have a choice between a dozen syntax variants that are not confusing, and one which is confusing, why would we prefer to pick the one that is confusing over any of the others?
"confusing" is a subjective term. So is "evocative" - see below. Consider the colon. Currently it has various meanings, including - introducing an indented suite - slicing - dictionary displays - use in annotations (I think) and others I don't remember right now, probably half-a-dozen in all. But we don't get confused when we (very commonly) see it used in 2 different ways in the same line: if not sys.argv[1:]: # 1st example I came across in the stdlib nor would we if it were used in 3 or more ways in the same line. Because we're familiar with it. Now def f(a := (b := c)): might be a tad confusing AT FIRST, until we got used to it. But - this would be very uncommon, and IMO in most cases bad code - there would never be *more* than 2 meanings for `:=` in the same line, because there would only BE two meanings for it. (I refrain from calling it `the walrus operator` here because the first one would be better called `the late default assignment operator` or some such.) Meanwhile, BEFORE we got used to it, I maintain that the similarity of `:=` to the early default assignment operator, viz. `=`, not to mention to the real walrus operator, is definitely evocative of some sort of (default?) value being given (somehow, sometime) to the parameter. Whereas adding (somewhere) a symbol such as '@' or '?' conveys nothing to me. YMMV, naturally. And of course it keeps that symbol free for another future use. Best wishes Rob Cliffe