Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Stephen J. Turnbull
Steven D'Aprano writes: > You might be right, but then the first post in this thread talked > about it: > > I realize there is no way to overload the behavior of the > assignment operator in python > > ... where signal = 5 will always make signal to be 5, instead of >

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Steven D'Aprano
On Thu, May 30, 2019 at 11:00:41AM +1200, Greg Ewing wrote: > Steven D'Aprano wrote: > > >The obvious solution to customising assignment is to use a dotted > >target: > > > >obj.x = value > > Another problem with this is that we don't want to customise *all* > assignments. Sometimes we just

Re: [Python-ideas] Implement POSIX ln via shutil.link and shutil.symlink

2019-05-29 Thread Steven D'Aprano
On Wed, May 29, 2019 at 10:22:31PM +0100, Barry wrote: > Serhiy, I think, is conflating two things. > 1. How to write software robust aginst attack. > 2. How to replace a symlink atomically. I don't have an opinion on whether Serhiy is right or wrong. > The only reason 1 is a problem is that th

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Greg Ewing
Steven D'Aprano wrote: The obvious solution to customising assignment is to use a dotted target: obj.x = value Another problem with this is that we don't want to customise *all* assignments. Sometimes we just want a regular Python assignment. (See my previous post about two different kin

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Greg Ewing
Steven D'Aprano wrote: Yanghao Hua wants to customise the behaviour of assignment. I believe that he wants to emulate the behaviour of some hardware description languages, where the equals sign = doesn't mean assignment (if I have understood correctly, which I may not have), but Something Else.

Re: [Python-ideas] Implement POSIX ln via shutil.link and shutil.symlink

2019-05-29 Thread Barry
> On 29 May 2019, at 16:48, Steven D'Aprano wrote: > >> On Wed, May 29, 2019 at 10:07:38PM +0700, Tom Hale wrote: >> They say silence is golden... But I'm still looking for some feedback on >> the below. > > I think the first thing you need to do is respond to Serhiy's objection: > >Sor

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 9:34 PM Ricky Teachey wrote: > Seems to me that namespace collisions are a possibility no matter what > namespace you are working in, right? If you are in the global (module) > namespace, and use up a, b, and c, that doesn't seem any different to me than > using up ns.a,

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Ricky Teachey
> This means, for a > middle-sized class implementation, you will start to worry about name > space collisions pretty quickly among all the class methods. > Information is no longer perfectly localized but spreading across all > over your class (and its parents ... which probably in a different > f

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 4:51 PM Ricky Teachey wrote: > > Another approach is to abandon the idea of HDL namespace parent class, and > just create a HDL (or hdl) decorator: > > @hdl # decorator adds a custom __setattr__ > class C: ... > > The decorator would modify the __setatrr__ method of the

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Ricky Teachey
> > With a bit modification it can work, e.g. the last setattr(self, attr, > value) should explicitly invoke SignalBehavior().__set__() instead. > You're absolutely right. For whatever reason I was thinking .__set__ gets called first anyway (I am probably confusing this behavior with .__get__ and

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 4:43 PM Ricky Teachey wrote: > > Seems like this would do it (note: `in` can't actually be a variable): > > class A(HDL): > # A is now an HDL namespace - all members have signal behavior > def __init__(self, in, o1, o2): > self.in = in # descriptor >

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 2:57 PM Ricky Teachey wrote: > class HDL: > """Every new member of this namespace has signal behavior""" > def __setattr__(self, attr, value): > # note: if attr existed already, > # SignalBehavior.__set__ was called > > # add attr as signal b

Re: [Python-ideas] Implement POSIX ln via shutil.link and shutil.symlink

2019-05-29 Thread Steven D'Aprano
On Wed, May 29, 2019 at 10:07:38PM +0700, Tom Hale wrote: > They say silence is golden... But I'm still looking for some feedback on > the below. I think the first thing you need to do is respond to Serhiy's objection: Sorry, but I do not understand what problem do you try to solve. If s

Re: [Python-ideas] Implement POSIX ln via shutil.link and shutil.symlink

2019-05-29 Thread Tom Hale
They say silence is golden... But I'm still looking for some feedback on the below. Cheers! -- Tom Hale On 16 May 2019 21:13:50 Tom Hale wrote: Thanks to all who have contributed to the discussion so far. I've noticed that the documentation[1] for both os.link and os.symlink doesn't mentio

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Ricky Teachey
Another approach is to abandon the idea of HDL namespace parent class, and just create a HDL (or hdl) decorator: @hdl # decorator adds a custom __setattr__ class C: ... The decorator would modify the __setatrr__ method of the class so that members of the class have signal behavior. You could ev

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Ricky Teachey
Seems like this would do it (note: `in` can't actually be a variable): class A(HDL): # A is now an HDL namespace - all members have signal behavior def __init__(self, in, o1, o2): self.in = in # descriptor self.o1 = o1 ; self.o2 = o2 # descriptors def process(self):

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 3:47 PM Ricky Teachey wrote: > > I look forward to seeing the working example. Hopefully it's clear already, > but: I don't think anybody is yet claiming the descriptor approach is the > "correct" or "best" answer for you. But it will help a lot to demo what you > want,

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 3:34 PM Steven D'Aprano wrote: > > On Tue, May 28, 2019 at 05:45:54PM -0400, Ricky Teachey wrote: > > > As things stand right now, it seems like you don't understand what we are > > saying about using descriptors to accomplish this. However it is certainly > > possible I si

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Ricky Teachey
> > but that doesn't really work. I know in my previous message I said the > problem was the aesthetics, but on further thought there are more > problems with it. > I thought about those problems myself, but are they not solved by doing all assigning of cuntion results within some "HDL namespace"?

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Steven D'Aprano
On Wed, May 29, 2019 at 08:56:58AM -0400, Ricky Teachey wrote: > For the understanding of all, it would help tremendously for you to > implement a WORKING TOY example showing exactly the behavior you want in > real (not theoretical) python, maybe something like this as a starting > point: I don't

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Ricky Teachey
I look forward to seeing the working example. Hopefully it's clear already, but: I don't think anybody is yet claiming the descriptor approach is the "correct" or "best" answer for you. But it will help a lot to demo what you want, and it also allows you to use your first choice operator, which is

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Steven D'Aprano
On Tue, May 28, 2019 at 05:45:54PM -0400, Ricky Teachey wrote: > As things stand right now, it seems like you don't understand what we are > saying about using descriptors to accomplish this. However it is certainly > possible I simultaneously don't understand what you are really trying to do > in

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 2:57 PM Ricky Teachey wrote: > > For the understanding of all, it would help tremendously for you to implement > a WORKING TOY example showing exactly the behavior you want in real (not > theoretical) python, maybe something like this as a starting point: > > class Signal

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Ricky Teachey
For the understanding of all, it would help tremendously for you to implement a WORKING TOY example showing exactly the behavior you want in real (not theoretical) python, maybe something like this as a starting point: class SignalBehavior: A descrip

Re: [Python-ideas] [Python-Dev] Overloading comparison operator for lists

2019-05-29 Thread Steven D'Aprano
Hi Montana, As Cameron Simpson already pointed out, your query is off-topic for the Python-Dev mailing list and should be taken to the Python-Ideas mailing list, which is for speculative discussion of new designs. Like Cameron, I've CCed Python-Ideas. Please send any follow-ups to that list an

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 9:46 AM Greg Ewing wrote: > > Yanghao Hua wrote: > > If I use python to do > > something and I have to type more chars it doesn't make sense for me. > > If you shorten it to "n" you get > >x.n = 4 > > which is exactly the same number of characters as your "<==" proposal

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Greg Ewing
Yanghao Hua wrote: If I use python to do something and I have to type more chars it doesn't make sense for me. If you shorten it to "n" you get x.n = 4 which is exactly the same number of characters as your "<==" proposal: x <== 4 Getting a bit more creative, you could use the little-kn

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 3:15 AM Eric V. Smith wrote: > Yes, I’ve read every one of the emails in this thread, many of them multiple > times. > > Python does not know what “a delta cycle of zero virtual time has passed” > means, so there’s no way of implementing this feature. If indeed you’re >

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-29 Thread Yanghao Hua
On Wed, May 29, 2019 at 3:45 AM Greg Ewing wrote: > > Yanghao Hua wrote: > > a different assignment behavior in HDL is your assignment does not > > take effect until a delta cycle of zero virtual time has passed. (did > > you really looked at the previous postings? :) > > You need to understand th