On Thu, Aug 6, 2020 at 2:52 AM Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 6/08/20 6:42 am, David Mertz wrote:
>>>> @unit("meter") a = 3  # a = unit("meter")("a", 3)
>>>> @unit("foot") b = 4   # b = unit("foot")("b", 4)

This still doesn't explain why the decorator syntax would be
significantly better than just calling the function directly.

meters = unit("meter")
feet = unit("foot")

a = meters(3)
b = feet(4)

The only difference is that in the usual existing style, 'a' doesn't know that it's called "a".  You and Steven have both, basically, said "Why would you possibly care about that?"  And honestly, I don't actually disagree.  I was just trying to make a *plausible* case for wanting it to try to extrapolate from the suggestion.

I think in the fairly rare case the (original) name matters, attaching it manually is every bit as good.

N_a = mol(6.02214076e23)
N_a.name = "Avogadro"

I think in the oddball corner cases where we might care about the "binding name" inside the object itself, __set_name__() gets us enough.  Yes, it's not for globals or locals.  But putting that funny extra stuff inside an instance seems like a low burden.
 

--
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.