From: Jean-Michel Pichavant on
Jabapyth wrote:
> At least a few times a day I wish python had the following shortcut
> syntax:
>
> vbl.=func(args)
>
> this would be equivalent to
>
> vbl = vbl.func(args)
>
> example:
>
> foo = "Hello world"
> foo.=split(" ")
> print foo
> # ['Hello', 'world']
>
> and I guess you could generalize this to
>
> vbl.=[some text]
> #
> vbl = vbl.[some text]
>
> e.g.
>
> temp.=children[0]
> # temp = temp.children[0]
>
> thoughts?
>
Useless if you use meaningful names for your variables & attributes.

It may happen that one object attribute refer to an object of the same
type, but it is quite rare that both can share the same name anyway.

Possible use cases:

1/
car = Car()
car = car.wheel # ???

2/
wheel = Car() # ???
wheel = wheel.wheel # ???

3/
currentCar = Car()
currentCar = currentCar.nextCar

The syntax you prose will be applicable on very little assignements (use
case 3). I'm not sure it's worth it.

JM
From: John Bokma on
"D'Arcy J.M. Cain" <darcy(a)druid.net> writes:

> On Fri, 30 Apr 2010 09:04:59 -0700 (PDT)
> Jabapyth <jabapyth(a)gmail.com> wrote:
>> foo = "Hello world"
>> foo.=split(" ")
>
> Isn't;
>
> foo = "Hello world"
> bar = foo.split() # side note - split() splits on whitespace by default
>
> so much clearer? Do you really want to see Python turn into Perl?

Oh, boy, there we go again. Can you and your buddies please refrain from
using Perl as a kind of uber-argument? Just write why you think it's
wrong. Bonus points if you can use Python in your arguments.

Why I am asking this is that most "Oh, like Perl" statements I've seen
the past months were made by people who either haven't used Perl
themselves or have very little skill in the language. This is a Python
group.

On top of that, it's not possible in Perl (heh, no surprise there). The
only thing that comes close is:

for ( $a_very_long_variable_name ) {

s/foo/bar/g;
s/baz/woot/g;
s/o+/i/g;
}

Which makes $_ an alias for $a_very.... and since s/// defaults to $_
this works.

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
From: Chris Rebert on
On Fri, Apr 30, 2010 at 10:05 AM, John Bokma <john(a)castleamber.com> wrote:
> "D'Arcy J.M. Cain" <darcy(a)druid.net> writes:
>> On Fri, 30 Apr 2010 09:04:59 -0700 (PDT)
>> Jabapyth <jabapyth(a)gmail.com> wrote:
>>> foo = "Hello world"
>>> foo.=split(" ")
>>
>> Isn't;
>>
>> foo = "Hello world"
>> bar = foo.split() # side note - split() splits on whitespace by default
>>
>> so much clearer?  Do you really want to see Python turn into Perl?
>
> Oh, boy, there we go again. Can you and your buddies please refrain from
> using Perl as a kind of uber-argument? Just write why you think it's
> wrong. Bonus points if you can use Python in your arguments.
>
> Why I am asking this is that most "Oh, like Perl" statements I've seen
> the past months were made by people who either haven't used Perl
> themselves or have very little skill in the language. This is a Python
> group.
>
> On top of that, it's not possible in Perl (heh, no surprise there). The
> only thing that comes close is:

Actually/ironically, it does appear to be in Perl 6:
"""
Mutating method call
$obj.=meth
The .= operator does inplace modification of the object on the left.
""" -- Synopsis 3: Perl 6 Operators (http://feather.perl6.nl/syn/S03.html)

Cheers,
Chris
--
One phrase: "Periodic Table of the Operators"
http://blog.rebertia.com
From: D'Arcy J.M. Cain on
On Fri, 30 Apr 2010 12:05:49 -0500
John Bokma <john(a)castleamber.com> wrote:
> "D'Arcy J.M. Cain" <darcy(a)druid.net> writes:
> > so much clearer? Do you really want to see Python turn into Perl?
>
> Oh, boy, there we go again. Can you and your buddies please refrain from
> using Perl as a kind of uber-argument? Just write why you think it's
> wrong. Bonus points if you can use Python in your arguments.

I think I was clear that the problem was obfuscation which Perl is very
good at. Haven't you ever had a Perl programmer show you a snippet of
code and say "I bet you can't guess what this does"?

> On top of that, it's not possible in Perl (heh, no surprise there). The
> only thing that comes close is:
>
> for ( $a_very_long_variable_name ) {
>
> s/foo/bar/g;
> s/baz/woot/g;
> s/o+/i/g;
> }
>
> Which makes $_ an alias for $a_very.... and since s/// defaults to $_

I hope that this example wasn't supposed to be a proof of Perl's
readability.

Anyway, you are right. I just happen to be dealing with some Perl and,
even worse, PHP issues on a new server and I am feeling a little
battered. I'll be better in a day or two.

By the way, to get back to the original topic, I don't really mind if
this makes it into the language because I won't be forced to use it.

--
D'Arcy J.M. Cain <darcy(a)druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
From: Lie Ryan on
On 05/01/10 02:50, Jean-Michel Pichavant wrote:
> Jabapyth wrote:
>> At least a few times a day I wish python had the following shortcut
>> syntax:
<snip>
> currentCar = Car()
> currentCar = currentCar.nextCar
>
> The syntax you prose will be applicable on very little assignements (use
> case 3). I'm not sure it's worth it.


And for the last use case, isn't iterator better?