On Fri, Oct 29, 2021 at 4:37 AM Avi Gross via Python-list
<python-list@python.org> wrote:
> Now for a dumb question. Many languages allow a form of setting a variable to 
> a value like:
>
>                 assign(var, 5+sin(x))
>
> If we had a function that then returned var or the value of var, cleanly, 
> then would that allow an end run on the walrus operator?
>
> if (assign(sign, 5+sin(x)) <= assign(cosign, 5+cos(x))) …
>
> Not necessarily pretty and I am sure there may well be reasons it won’t work, 
> but I wonder if it will work in more places than the currently minimal walrus 
> operator.

For that to work, the language needs one of three things:

1) A way to pass an lvalue to a function, which it can then change
2) A form of pointer or reference (same thing, but you'd adorn it at
the call site - eg in C, you can write &var)
3) Magical compiler support for the assign function, so it isn't
really a function, just something that looks like one.

(Are there any other ways? I can't think of any.)

Python currently doesn't have any of those, so you'd have to pick
which one you're advocating for and show how it would be beneficial.
Personally, I'm dubious of all three, but I would be most interested
in the second option and its consequences.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to