On Sep 22, 2019, at 02:08, Nutchanon Ninyawee <m...@nutchanon.org> wrote:
> 
> Link is a language feature that allows multiple variable names to always 
> refer to the same underlying object define in a namespace.
> For now, if the variable a link with b. I will denote as a >< b or link('a', 
> 'b')
> 
> a = 2
> a >< alpha # link 'a' with 'alpha'
> b = 3
> print(b**alpha) # print 9
> alpha = 3
> print(b**a) # print 27

How would this work? I can think of a few options, but they all either badly 
slow down every variable use, don’t work with locals, or require >< to be 
handled at compile time. Do you have at least a sketch of how this works?

Also, do you have a real-life use case? Usually when you want the equivalent of 
“variable references” in Python, you just stick the value in a list or an 
explicit namespace; why isn’t that sufficient here? Also, usually you’re doing 
it to share a reference with a function, not just using another name in the 
same namespace; why do you need actual references here but not in the more 
general and more often-desired case?

And finally, a whole bunch of questions on behavior:

What happens if you `del a`?

Is there a syntax to unlink variables? It seems like you’d want that at least 
at the interactive REPL.

Is there any way to discover whether two names are linked?

If you link `a >< b` and then link `b >< c`, does that make a three-way link, 
or unlink a from b?

If you link two locals and capture them both in a closure, are the closures a 
single cell, or two cells that reference captured names that happen to be 
linked?

What if you link two names in a class body? 

What if it’s inside code passed to eval or exec with normal locals and globals? 
Or with a custom dict subclass or Mapping class for one or the other?

Can you link arbitrary targets (e.g., self.a >< self.b, or even a >< b[10]), or 
just bare names?

If you call globals(), do you get back some kind of dict-like object that knows 
about the links (and can be inspected), or something that looks like a 
plain-old dict but if you assign to its `a` you also change `b`, or something 
that looks like a plain-old dict but if you assign to its `a` you unlink it?

_______________________________________________
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/2DEKB4H4JQAH4EQQGTJKSEZ36C2KQQX7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to