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

2019-05-22 Thread Ricky Teachey
Can I offer an alternative suggestion? How about these arrow operators, which despite being 3 characters, look pretty nice, and are not currently valid python: a <== b <== c a ==> b ==> c Perhaps __larrow__ and __rarrow__ for the dunders. And they would not be the only 3 character operators in

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

2019-05-22 Thread Cody Piersall
On Wed, May 22, 2019 at 4:32 AM Yanghao Hua wrote: > I have experimented by adding two new python operators, left arrow: <- > and right arrow ->, which users can define their behaviors. and it > still looks like kind of the non-blocking assignment operators in > hardware description languages (e.

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

2019-05-22 Thread Yanghao Hua
> You might also want to look at macropy > https://github.com/lihaoyi/macropy/blob/master/readme.rst , although I don’t > know if it supports new operators. Thanks for the pointer, I am also not sure how to apply it after a quick going through of its documentation. So far the quickest thing to

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

2019-05-22 Thread Yanghao Hua
> Perhaps you might be able to do what you want using an import hook. I have > done some experiments with introducing some new operators that way: > https://github.com/aroberge/experimental/blob/master/experimental/transformers/readme.md Thanks for the link, it is a very interesting module. I h

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

2019-05-22 Thread Yanghao Hua
> If you are proposing to add "<-" and "->" to the fundamental Python > grammar, then it could work as PEP465 does. But if you are proposing > that classes can define new lexical operators, it would have to work > very very differently. You started with "operators as first class > citizens," but I

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

2019-05-22 Thread Yanghao Hua
On Wed, May 22, 2019 at 2:54 PM Rhodri James wrote: > > On 22/05/2019 13:29, Yanghao Hua wrote: > > Problem is python do not allow you to define new operators in the > > language itself, except those pre-defined you can modify their > > behavior. Even in case, if python would have been able to all

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

2019-05-22 Thread Eric V. Smith
> On May 22, 2019, at 10:51 AM, Andre Roberge wrote: > > > >> On Wed, May 22, 2019 at 9:57 AM Yanghao Hua wrote: >> > > And this is something I have in mind for a Python DSL for HDL: > > Perhaps you might be able to do what you want using an import hook. I have > done some experiments with

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

2019-05-22 Thread Andre Roberge
On Wed, May 22, 2019 at 9:57 AM Yanghao Hua wrote: > > > And this is something I have in mind for a Python DSL for HDL: > Perhaps you might be able to do what you want using an import hook. I have done some experiments with introducing some new operators that way: https://github.com/aroberge/exp

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

2019-05-22 Thread Ned Batchelder
On 5/22/19 8:56 AM, Yanghao Hua wrote: And this is something I have in mind for a Python DSL for HDL: def combinational_or_sequential_logic(in: Signal, out: Signal): local_signal = Signal() local_signal <- in << 10 # read as: local_signal <- (in << 10) out <- local_signal + 5 #

Re: [Python-ideas] DB-API support for sets?

2019-05-22 Thread Random832
On Wed, May 22, 2019, at 09:58, Inada Naoki wrote: > Placeholders may be substituted by server. > So we can't force to allow multiple values in one placeholder. Can the placeholder be substituted for multiple placeholders by the client side, which are then further individually substituted by the

Re: [Python-ideas] DB-API support for sets?

2019-05-22 Thread Chris Angelico
On Wed, May 22, 2019 at 11:47 PM Skip Montanaro wrote: > > The DB-API doesn't support sets directly, so you wind up having to > manually expand them: > > >>> curs.execute("select count(*) from sometable where somecol in ?", > >>> ({4126,11638},)) > Traceback (most recent call last): > File "",

Re: [Python-ideas] DB-API support for sets?

2019-05-22 Thread M.-A. Lemburg
Hi Skip, On 22.05.2019 15:46, Skip Montanaro wrote: > The DB-API doesn't support sets directly, so you wind up having to > manually expand them: > curs.execute("select count(*) from sometable where somecol in ?", ({4126,11638},)) > Traceback (most recent call last): > File "", line 1

Re: [Python-ideas] DB-API support for sets?

2019-05-22 Thread Inada Naoki
Placeholders may be substituted by server. So we can't force to allow multiple values in one placeholder. (For example, MySQL allow only single value for one ?, while MySQLdb doesn't use MySQL's prepared statement at the moment.) DB-API is low level interface. Higher level library (like SQLAlchem

[Python-ideas] DB-API support for sets?

2019-05-22 Thread Skip Montanaro
The DB-API doesn't support sets directly, so you wind up having to manually expand them: >>> curs.execute("select count(*) from sometable where somecol in ?", >>> ({4126,11638},)) Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: near "?": syntax error >>> curs.e

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

2019-05-22 Thread Yanghao Hua
> > And this is something I have in mind for a Python DSL for HDL: > > > > def combinational_or_sequential_logic(in: Signal, out: Signal): > > local_signal = Signal() > > local_signal <- in << 10 # read as: local_signal <- (in << 10) > > out <- local_signal + 5 # read as out <- (loca

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

2019-05-22 Thread Rhodri James
On 22/05/2019 13:29, Yanghao Hua wrote: Problem is python do not allow you to define new operators in the language itself, except those pre-defined you can modify their behavior. Even in case, if python would have been able to allow me to redefine the behavior of "=", e.g. by checking if the left

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

2019-05-22 Thread Ned Batchelder
On 5/22/19 8:29 AM, Yanghao Hua wrote: Yes, it does make sense. Forgive my lack of Scala knowledge, but is it possible for 'b' in your example to be the one that handles the addition? Specific case: class Seven: def __add__(self, other): return other + 7 def __radd__(self, other): retu

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

2019-05-22 Thread Yanghao Hua
> Yes, it does make sense. Forgive my lack of Scala knowledge, but is it > possible for 'b' in your example to be the one that handles the > addition? Specific case: > > class Seven: > def __add__(self, other): return other + 7 > def __radd__(self, other): return 7 + other > > seven = Seven

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

2019-05-22 Thread Chris Angelico
On Wed, May 22, 2019 at 10:03 PM Yanghao Hua wrote: > > To be first-class citizens, operators would have to be able to be > > passed to functions - for instance: > > > > def frob(x, y, oper): > > return x oper y > > assert frob(10, 20, +) == 30 > > assert frob(10, 20, *) == 200 > > > > The nea

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

2019-05-22 Thread Chris Angelico
On Wed, May 22, 2019 at 7:32 PM Yanghao Hua wrote: > The .next could have been saved by using python descriptors but now > you have to type something like "obj.signal = 5" instead of "signal = > 5", and it does not work if you want a local signal, where signal = 5 > will always make signal to be 5

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

2019-05-22 Thread Yanghao Hua
I see python3.5 accepted PEP465 adding a new infix operator for matrix (@, @=), which made matrix formula's much less painful to read in Python. There are still more use cases like this in other areas. While looking at Chisel (a hardware construction language build on top of scala), where you can