On Tue, May 26, 2020 at 4:12 PM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > > Wild idea: Instead of sentinels, have a way of declaring optional > arguments with no default, and a way of conditionally assigning a > value to them if they are not bound. > > E.g. > > def order(eggs = 4, spam =): > spam ?= Spam() > > Here the '?=' means "if spam is not bound, then evaluate the > rhs and assign it, otherwise do nothing." >
That's interesting. I suppose the semantics would be the same as any other unbound local, then? That would actually be useful in other contexts, like where you conditionally assign in a loop, and then might not have it assigned at the end. I don't know of any current way to say "if spam is unset". It definitely needs good syntax though. The loose equals sign would be too confusing, and there's no good keyword available. It'd be kinda elegant to surround the name in square brackets: def order(eggs=4, [spam]): spam ?= Spam() but that would be confusing for other reasons. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6ZBEBI6Y7ZFDB7GSJ23V5QNGY7WF2ZT3/ Code of Conduct: http://python.org/psf/codeofconduct/