[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-06-15 Thread Eric V. Smith
Changes by Eric V. Smith : -- pull_requests: +2277 ___ Python tracker ___ ___

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-06-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Thank you for your review Eric. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-06-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset 570b1c971c31cd08dbf060f4e21636c40aa47786 by Serhiy Storchaka in branch '3.6': [3.6] bpo-30529: Fix errors for invalid whitespaces in f-string subexpressions. (GH-1888) (#2013) https://github.com/python/cpython/commit

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-06-08 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +2078 ___ Python tracker ___ ___

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-06-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset 2e9cd5825c5ccdbb6f65a57c0c7941078e003c14 by Serhiy Storchaka in branch 'master': bpo-30529: Fix errors for invalid whitespaces in f-string subexpressions. (#1888) https://github.com/python/cpython/commit

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-06-08 Thread Eric V. Smith
Eric V. Smith added the comment: Sorry, I've been busy. I'll get to this soon, though. -- ___ Python tracker ___

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-06-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Could you please look at the patch Eric? -- ___ Python tracker ___ ___

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-05-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: PR 1888 makes error messages for f-string subexpressions consistent with error messages for expressions out of f-strings, simplifies and speeds up the parsing code. -- ___ Python tracker <rep...@bugs.python.

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-05-31 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- stage: -> patch review ___ Python tracker ___

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-05-31 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +1966 ___ Python tracker ___ ___

[issue30529] Incorrect error messages for invalid whitespaces in f-string subexpressions

2017-05-31 Thread Serhiy Storchaka
New submission from Serhiy Storchaka: Python parser supports only ' ', '\t', '\x0c' and '\r' as whitespaces. The parser of f-strings raises incorrect error messages for subexpressions consistent only from whitespaces, if they contain whitespaces out this set. >>> eval("\xa0&quo

[issue25845] _ctypes\cfield.c identical subexpressions in Z_set

2015-12-11 Thread Martin Panter
Martin Panter added the comment: History is good for understanding how things became the way they are. :) Thanks Alexander and Random! -- nosy: +martin.panter resolution: -> fixed stage: -> resolved status: open -> closed type: -> enhancement versions: +Python 3.5, Python 3.6

[issue25845] _ctypes\cfield.c identical subexpressions in Z_set

2015-12-11 Thread random832
random832 added the comment: Looks like a result of searching and replacing PyInt with PyLong - the diff can be found here, if anyone cares. https://hg.python.org/cpython-fullhistory/rev/f324631462a2. Oddly, there was _another, older_ revision that fixed this correctly:

[issue25845] _ctypes\cfield.c identical subexpressions in Z_set

2015-12-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset 26859a7e385c by Martin Panter in branch '3.5': Issue #25845: Drop redundant checks leftover from int to long conversion https://hg.python.org/cpython/rev/26859a7e385c New changeset 9be59ad8af80 by Martin Panter in branch 'default': Issue #25845:

[issue25845] _ctypes\cfield.c identical subexpressions in Z_set

2015-12-11 Thread Alexander Riccio
nosy: Alexander Riccio, amaury.forgeotdarc, belopolsky, meador.inge priority: normal severity: normal status: open title: _ctypes\cfield.c identical subexpressions in Z_set ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.o

[issue25845] _ctypes\cfield.c identical subexpressions in Z_set

2015-12-11 Thread random832
random832 added the comment: Sorry, my mistake, I was looking at z_set instead of Z_set. The earlier fix had left Z_set out for some reason. Anyway, just some historical interest anyway. -- ___ Python tracker

Re: attaching names to subexpressions

2012-10-29 Thread Neil Cerutti
On 2012-10-28, Devin Jeanpierre jeanpierr...@gmail.com wrote: The 'canonical way' while True: line = complex_expression if not line: break do_something_with(line) avoids this problem, but I was never really convinced about the beauty / readbility of this construct.

Re: attaching names to subexpressions

2012-10-28 Thread Chris Angelico
On Sun, Oct 28, 2012 at 4:57 PM, Devin Jeanpierre jeanpierr...@gmail.com wrote: What if he wants to avoid both downsides A and B? What solution does he use then? He switches to a language whose BDFL is not Steven D'Aprano. :) No offense meant Steven... ChrisA --

Re: attaching names to subexpressions

2012-10-28 Thread Steven D'Aprano
On Sun, 28 Oct 2012 01:57:45 -0400, Devin Jeanpierre wrote: We have a problem, and two solutions. Solution 1 has downside A, and solution 2 has downside B. If he complains about downside A, you say, well, use solution 2. If he complains about downside B, you say, well, use solution 1. What

Re: attaching names to subexpressions

2012-10-28 Thread F.R.
On 10/28/2012 06:57 AM, Devin Jeanpierre wrote: line = function(x, y, z) while line: do something with(line) line = function(x, y, z) How about: line = True while line: line = function(x, y, z) do something with(line) ? Frederic --

Re: attaching names to subexpressions

2012-10-28 Thread Chris Angelico
On Sun, Oct 28, 2012 at 6:12 PM, F.R. anthra.nor...@bluewin.ch wrote: How about: line = True while line: line = function(x, y, z) do something with(line) ? That's going to go through the body of the loop with a false line before breaking out. In some situations that's

Re: attaching names to subexpressions

2012-10-27 Thread Gelonida N
On 10/27/2012 04:42 AM, Steve Howell wrote: I have been reading the thread while expression feature proposal, and one of the interesting outcomes of the thread is the idea that Python could allow you to attach names to subexpressions, much like C allows. In C you can say something like

Re: attaching names to subexpressions

2012-10-27 Thread rusi
On Oct 28, 5:49 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: It's sure as hell more beautiful and readable than assignment as an expression. If we are going to judge code on the ability of people to take a quick glance and immediately understand it, then pretty much

attaching names to subexpressions

2012-10-26 Thread Steve Howell
I have been reading the thread while expression feature proposal, and one of the interesting outcomes of the thread is the idea that Python could allow you to attach names to subexpressions, much like C allows. In C you can say something like this: tax_next_year = (new_salary = salary * (1

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Gary Herron wrote: The radian is defined as the ratio of an arc of circumfence of a circle to the radius of the circle and is therefore *dimensionless*. End of story. http://en.wikipedia.org/wiki/Radian and esp. http://en.wikipedia.org/wiki/Radian#Dimensional_analysis The

Re: subexpressions (OT: math)

2007-06-04 Thread stef
Gary Herron wrote: Wildemar Wildenburger wrote: Gary Herron wrote: Of course not! Angles have units, commonly either degrees or radians. However, sines and cosines, being ratios of two lengths, are unit-less. To understand it: sin() can't have dimensioned

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote: if you are discordant read more :P : sine is a dimensionless value. if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 etc. you can see that sin can be dimensionless only if x is dimensionless too. I am a professional physicist and a know about

Re: subexpressions (OT: math)

2007-06-04 Thread Erik Max Francis
Wildemar Wildenburger wrote: So in each term of the sum you have a derivative of f, which in the case of the sine function translates to sine and cosine functions at the point 0. It's not like you're rid of the function just by doing a polynomial expansion. The only way to *solve* this is

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Erik Max Francis wrote: Wildemar Wildenburger wrote: So in each term of the sum you have a derivative of f, which in the case of the sine function translates to sine and cosine functions at the point 0. It's not like you're rid of the function just by doing a polynomial expansion.

Re: subexpressions (OT: math)

2007-06-04 Thread Peter Otten
[EMAIL PROTECTED] wrote: sine is a dimensionless value. if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 etc. you can see that sin can be dimensionless only if x is dimensionless too. With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...) area is

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Peter Otten wrote: With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...) area is dimensionless, too, I suppose. Ehr, ... maybe this is obvious, but I don't see it: Please explain the second equality sign. /W -- http://mail.python.org/mailman/listinfo/python-list

Re: subexpressions (OT: math)

2007-06-04 Thread Peter Otten
Wildemar Wildenburger wrote: Peter Otten wrote: With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...) area is dimensionless, too, I suppose. Ehr, ... maybe this is obvious, but I don't see it: Please explain the second equality sign. I know not much more about Fourier

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Peter Otten wrote: [EMAIL PROTECTED] wrote: sine is a dimensionless value. if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 etc. you can see that sin can be dimensionless only if x is dimensionless too. With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 +

Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell
Fourier Series make a better example of a situation where you end up repeating subexpressions: lambda t: a[0]/2 + sum(a[n]*cos(n*f*t) + b[n]*sin(n*f*t) \ for n in range(1,101)) Pinpoint customers

Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell
--- Wildemar Wildenburger [EMAIL PROTECTED] wrote: Oh my, remember when we used to discuss murderous snakes and silly British comedians on this group? I hardly do ... /W Although all of us are mere amateurs in this business of making parameters when it's circles in question I have a

Re: subexpressions (OT: math)

2007-06-03 Thread Hendrik van Rooyen
Steve Howell sh[EMAIL PROTECTED] wrote: --- Steven D'Aprano [EMAIL PROTECTED] wrote: Angles are real numbers (in the maths sense), so sqrt(pi/4) radians is just as reasonable an angle as pi/4 radians. Both are irrational numbers (that is, can't be written exactly as the

Re: subexpressions (OT: math)

2007-06-03 Thread Leonhard Vogt
Yes, I understand that, but what is the geometrical meaning of the square root of an arc length? That's a different question to your original question, which was asking about the square root of an angle. And what would the units be? Angles are a ratio of two lengths, and are

Re: subexpressions (OT: math)

2007-06-03 Thread Steven D'Aprano
On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote: Angles are a ratio of two lengths, and are therefore dimensionless units. So the square root of an angle is just another angle, in the same units, and it requires no special geometric interpretation: the square root of 25 degrees (just

Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 14:05, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote: bla-bla Hmmm... perhaps that's why the author of the units program doesn't treat angles as dimensionless when taking square roots. Given that, I withdraw my claim that the

Re: subexpressions (OT: math)

2007-06-03 Thread Gary Herron
[EMAIL PROTECTED] wrote: On 3, 14:05, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote: bla-bla Hmmm... perhaps that's why the author of the units program doesn't treat angles as dimensionless when taking square roots.

Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 21:43, Gary Herron [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: angle is dimensionless unit. Of course not! Angles have units, commonly either degrees or radians. However, sines and cosines, being ratios of two lengths, are unit-less. To understand it: sin() can't have

Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 22:07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: angle is a ratio of two length and dimensionless.http://en.wikipedia.org/wiki/Angle#Units_of_measure_for_angles only dimensionless values can be a argument of a sine and exponent! Are you discordant? if you are discordant read

Re: subexpressions (OT: math)

2007-06-03 Thread Cameron Laird
In article [EMAIL PROTECTED], Leonhard Vogt [EMAIL PROTECTED] wrote: Yes, I understand that, but what is the geometrical meaning of the square root of an arc length? That's a different question to your original question, which was asking about the square root of an angle. And what

Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell
What's the square root of -1 radians? :) Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center. http://autos.yahoo.com/green_center/ --

Re: subexpressions (OT: math)

2007-06-03 Thread Steven D'Aprano
On Sun, 03 Jun 2007 11:26:40 -0700, [EMAIL PROTECTED] wrote: if you are discordant read more :P : sine is a dimensionless value. if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 etc. you can see that sin can be dimensionless only if x is dimensionless too. I am a

Re: subexpressions (OT: math)

2007-06-03 Thread Wildemar Wildenburger
Gary Herron wrote: Of course not! Angles have units, commonly either degrees or radians. However, sines and cosines, being ratios of two lengths, are unit-less. To understand it: sin() can't have dimensioned argument. It is can't to be - sin(meters) No it's sin(radians) or

Re: subexpressions (OT: math)

2007-06-03 Thread Gary Herron
Wildemar Wildenburger wrote: Gary Herron wrote: Of course not! Angles have units, commonly either degrees or radians. However, sines and cosines, being ratios of two lengths, are unit-less. To understand it: sin() can't have dimensioned argument. It is can't to be -

Re: subexpressions (OT: math)

2007-06-03 Thread Lloyd Zusman
Steven D'Aprano [EMAIL PROTECTED] writes: On Sun, 03 Jun 2007 11:26:40 -0700, [EMAIL PROTECTED] wrote: if you are discordant read more :P : sine is a dimensionless value. if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 etc. you can see that sin can be dimensionless only

Re: subexpressions (OT: math)

2007-06-03 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On 3, 22:07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: angle is a ratio of two length and dimensionless.http://en.wikipedia.org/wiki/Angle#Units_of_measure_for_ang les only dimensionless values can be a argument of a sine and exponent!

Re: subexpressions (OT: math)

2007-06-03 Thread Erik Max Francis
Gary Herron wrote: Of course not! Angles have units, commonly either degrees or radians. ... I don't know of any name for the units of sqrt of angle, but that doesn't invalidate the claim that the value *is* a dimensioned quantity. In lieu of a name, we'd have to label such a

Re: subexpressions (OT: math)

2007-06-03 Thread Erik Max Francis
Gary Herron wrote: No, not end-of-story. Neither of us are being precise enough here. To quote from your second link: Although the radian is a unit of measure, it is a dimensionless quantity. But NOTE: Radians and degrees *are* units of measure., however those units are

Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell
--- Alex Martelli [EMAIL PROTECTED] wrote: I blame the Babylonians for that confusion just as much as for the clunky base-60 that intrudes in our ordinary time reckoning...! I apologize for helping to start this whole ridiculous thread, although I hope some people have been entertained

Re: subexpressions

2007-06-02 Thread Stef Mientki
Check the two alternatives: def f(x): y = x*x return sin(y) + cos(y) 44 key presses, including tabs and newlines and a blank line after the function, but excluding counting the shift key separately. lambda x: (lambda y: sin(y) + cos(y))(x*x) 42 key presses. Apart

Re: subexpressions

2007-06-02 Thread Steve Howell
def f(x): y = x*x; return sin(y)+cos(y); Although I know valid trigonometry is not the point of this exercise, I'm still trying to figure out why anybody would ever take the square of an angle. What's the square root of pi/4 radians?

Re: subexpressions

2007-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2007 05:54:51 -0700, Steve Howell wrote: def f(x): y = x*x; return sin(y)+cos(y); Although I know valid trigonometry is not the point of this exercise, I'm still trying to figure out why anybody would ever take the square of an angle. What's the square root of pi/4

Re: subexpressions

2007-06-02 Thread Stef Mientki
Steve Howell wrote: def f(x): y = x*x; return sin(y)+cos(y); Although I know valid trigonometry is not the point of this exercise, I'm still trying to figure out why anybody would ever take the square of an angle. What's the square root of pi/4 radians? Maybe he meant sin(x)^2 +

Re: subexpressions (OT: math)

2007-06-02 Thread Steve Howell
--- Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 02 Jun 2007 05:54:51 -0700, Steve Howell wrote: def f(x): y = x*x; return sin(y)+cos(y); Although I know valid trigonometry is not the point of this exercise, I'm still trying to figure out why anybody would ever take

Re: subexpressions

2007-06-02 Thread Steve Howell
--- Stef Mientki [EMAIL PROTECTED] wrote: Maybe he meant sin(x)^2 + cos(x)^2 which is well known demodulation technique if you create two signals 90 degrees out of phase. There's a shorter way to phrase that expression, of course. :) 1

Re: subexpressions (fourier example)

2007-06-02 Thread Steve Howell
--- Steve Howell [EMAIL PROTECTED] wrote: --- Stef Mientki [EMAIL PROTECTED] wrote: Maybe he meant sin(x)^2 + cos(x)^2 which is well known demodulation technique if you create two signals 90 degrees out of phase. A more realistic subexpression where you might repeat

Re: subexpressions (OT: math)

2007-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2007 08:29:59 -0700, Steve Howell wrote: --- Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 02 Jun 2007 05:54:51 -0700, Steve Howell wrote: def f(x): y = x*x; return sin(y)+cos(y); Although I know valid trigonometry is not the point of this exercise,

Re: subexpressions

2007-06-01 Thread Peter Otten
Sergey Dorofeev wrote: Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sergey Dorofeev wrote: Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to

subexpressions

2007-06-01 Thread Sergey Dorofeev
Hello all! Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once? -- http://mail.python.org/mailman/listinfo/python-list

Re: subexpressions

2007-06-01 Thread Sergey Dorofeev
Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once? (lambda x: [sin(x2) +

Re: subexpressions

2007-06-01 Thread A.T.Hofkamp
On 2007-06-01, Sergey Dorofeev [EMAIL PROTECTED] wrote: Hello all! Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once? lambda x: (lambda y: sin(y) +

Re: subexpressions

2007-06-01 Thread Sergey Dorofeev
Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sergey Dorofeev wrote: Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once?

Re: subexpressions

2007-06-01 Thread Peter Otten
Sergey Dorofeev wrote: Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once?

Re: subexpressions

2007-06-01 Thread Peter Otten
Sergey Dorofeev wrote: Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once? (lambda x: [sin(x2) + cos(x2) for x2 in [x*x]][0])(.5) == sin(.5*.5) +

Re: subexpressions

2007-06-01 Thread Steve Howell
--- A.T.Hofkamp [EMAIL PROTECTED] wrote: lambda x: (lambda y: sin(y) + cos(y))(x*x) Elegant. I find the use of y confusing there (thinking about the unit circle), so I'd amend it to this: lambda x: (lambda x2: sin(x2) + cos(x2))(x*x) But I like the overall idea.

Re: subexpressions

2007-06-01 Thread Sergey Dorofeev
Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] What syntax would you suggest for a lambda enhanced to cover your use case? I suppose you will end up with roughly the same number of characters, all crammed in one line -- or broken into lines at a random position as it

Re: subexpressions

2007-06-01 Thread Steve Holden
Sergey Dorofeev wrote: Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once?

Re: subexpressions

2007-06-01 Thread Tijs
Steve Howell wrote: FWIW there's the possibility that even without a subexpression syntax, some Python implementations would detect the duplication of x*x and optimize that for you. It would have to know that x*x had no side effects, which I think is a safe assumption even in a dynamic

Re: subexpressions

2007-06-01 Thread Bruno Desthuilliers
Steve Holden a écrit : (snip) Stop thinking of three lines as extensive coding and your problem disappears immediately. Lol ! +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: subexpressions

2007-06-01 Thread Paul Boddie
On 1 Jun, 12:55, Steve Howell [EMAIL PROTECTED] wrote: FWIW there's the possibility that even without a subexpression syntax, some Python implementations would detect the duplication of x*x and optimize that for you. It would have to know that x*x had no side effects, which I think is a

Re: subexpressions

2007-06-01 Thread Diez B. Roggisch
Steve Howell wrote: --- Sergey Dorofeev [EMAIL PROTECTED] wrote: What syntax would you suggest for a lambda enhanced to cover your use case? I suppose you will end up with roughly the same number of characters, all crammed in one line -- or broken into lines at a random position as it

Re: subexpressions

2007-06-01 Thread Steve Holden
Sergey Dorofeev wrote: Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sergey Dorofeev wrote: Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Sergey Dorofeev [EMAIL PROTECTED] wrote: What syntax would you suggest for a lambda enhanced to cover your use case? I suppose you will end up with roughly the same number of characters, all crammed in one line -- or broken into lines at a random position as it happens with

Re: subexpressions

2007-06-01 Thread Steve Howell
is a safe assumption even in a dynamic language like Python. No, x may be an object that has the __mul__ special method, and it may have side effects. Ok, I stand corrected. Duplicate subexpressions are pretty easy to avoid in Python, so though an optimization would not be impossible

Re: subexpressions

2007-06-01 Thread Diez B. Roggisch
Ok, I stand corrected. Duplicate subexpressions are pretty easy to avoid in Python, so though an optimization would not be impossible here (checking for immutability of builtins, etc., which still assumes the idea that multiplication is more expensive than checking for immutability even

Re: subexpressions

2007-06-01 Thread Terry Reedy
Sergey Dorofeev [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | How to make x*x to be evaluated once? Addendum to the answers already posted: In Python, lambda params: expression is an inline abbreviation for def lambda(params): return expression except that there is no external

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Diez B. Roggisch [EMAIL PROTECTED] wrote: The elegance of that solution very much depends on the cost of the duplicate operation vs. the additional function call. And for the usecase at hand, that's exactly the point not to do it: [EMAIL PROTECTED]:/tmp$ python -m timeit '(lambda x:

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Paul Boddie [EMAIL PROTECTED] wrote: On 1 Jun, 12:55, Steve Howell [EMAIL PROTECTED] wrote: FWIW there's the possibility that even without a subexpression syntax, some Python implementations would detect the duplication of x*x and optimize that for you. It would have to know that

Re: subexpressions

2007-06-01 Thread Kay Schluehr
On Jun 1, 9:51 am, Sergey Dorofeev [EMAIL PROTECTED] wrote: Hello all! Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) How to make x*x to be evaluated once? lambda x: (lambda y=x*x:

Re: subexpressions

2007-06-01 Thread Steven Bethard
Sergey Dorofeev wrote: Please help, is there way to use sub-expressions in lambda? For example, if I want to calculate sin(x^2)+cos(x^2) I must code: lambda x: sin(x*x)+cos(x*x) [and later] This code is needed once in a map, Peter Otten wrote: Perhaps you like [sin(y)+cos(y) for y in (x*x

Re: subexpressions

2007-06-01 Thread Paul Boddie
Steve Howell wrote: The compiler doesn't know the types up front, but if you wanted to do this kind of optimization (and you believed that 95% of x*x cases would benefit from it, and you're willing to sacrifice performance for the 5% of folks that overload multiply), then the compiler could

Re: subexpressions

2007-06-01 Thread Steven D'Aprano
On Fri, 01 Jun 2007 07:09:50 -0400, Steve Holden wrote: The real answer is of course: Use a function. But what about something like lambda x: sin(y)+cos(y) where y=x*x ? May be this could be a PEP? If there is no straight way to do this. def f(x): y = x*x return sin(y) + cos(y)

Re: subexpressions

2007-06-01 Thread Cousin Stanley
After years of discussion, Guido has decided to leave lambda alone for 3.0. It will not be neither expanded, nor removed, nor renamed. But it still will be as ugh, ugh, ugh-lee as a mule walking backwards . ;-) -- Stanley C. Kitching Human Being Phoenix, Arizona ==

Re: subexpressions

2007-06-01 Thread Terry Reedy
Cousin Stanley [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | | | After years of discussion, Guido has decided | to leave lambda alone for 3.0. | | It will not be neither expanded, nor removed, nor renamed. | | But it still will be as ugh, ugh, ugh-lee | as a mule