[Python-Dev] (name := expression) doesn't fit the narrative of PEP 20 (original) (raw)
Steven D'Aprano steve at pearwood.info
Thu Apr 26 08:31:53 EDT 2018
- Previous message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Next message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Apr 26, 2018 at 10:34:29PM +1200, Greg Ewing wrote:
Antoine Pitrou wrote: >Well, how do languages where assignment is an expression returning the >assigned value make their REPLs work? I'm sure they don't inflict that >on their users, so it's certainly a solvable problem.
I can't think of any such language that has a REPL offhand, but here's a possible solution:
Here's the Rhino Javascript REPL:
[steve at ando ~]$ rhino Rhino 1.7 release 0.7.r2.3.el5_6 2011 05 04 js> x = (a = 99) + 1 100
Here's the standard Ruby REPL:
[steve at ando ~]$ irb irb(main):001:0> x = (a = 99) + 1 => 100
So both of these REPLs do print the result of the expression.
R, on the other hand, doesn't print the results of assignment expressions:
x <- (a <- 99) + 1 c(x, a) [1] 100 99
Rhino, however, does suppress printing if you prefix the variable with "var" or "const".
-- Steve
- Previous message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Next message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]