Andrew Barnert wrote: > 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(balpha) # print 9 > > alpha = 3 > > print(ba) # 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?
Q: Do you have at least a sketch of how this works? A: I have no idea how to make this work in c/kernel level. I have no experience in implementing the core language before. Q: What happens if you `del a`? A: `del a` would unbind all linked names. Q: Is there a syntax to unlink variables? It seems like you’d want that at least at the interactive REPL. Q: Is there any way to discover whether two names are linked? A: Yes, there is. It is currently open for design and discussion. Q: If you link `a >< b` and then link `b >< c`, does that make a three-way link, or unlink a from b? A: That makes a three-way link. Q: 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? Q: What if you link two names in a class body? Q: 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? A: I don't understand the "single cell, or two cells" concept. I bet it relates to inner representation like [this](http://code.activestate.com/recipes/439096-get-the-value-of-a-cell-from-a-closure/). I don’t know much about the implementation. Q: Can you link arbitrary targets (e.g., self.a >< self.b, or even a ><b[10]), or just bare names? A: I would like to limit this to bare names at first for the sake of simplification. Q: 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? A: I thinks there should be a `links()` function to inspect linked variables. globals() should behave like a plain-old dict but if you assign to its `a` you also change `b`. _______________________________________________ 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/T563KGULNKXAVQZ7LPJBDBKYQUYEAA6S/ Code of Conduct: http://python.org/psf/codeofconduct/