Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby bug in +=?

Reply
Thread Tools

Ruby bug in +=?

 
 
zarawesome@gmail.com
Guest
Posts: n/a
 
      06-01-2007
def addToList(x)
$list += [x];
end

def function()
addToList("a");
addToList("b");
addToList("c");
return "d";
end

$list = [];
addToList(function()); # $list = ["a","b","c","d"]

$list = [];
$list += [function()]; # $list = ["d"]!

 
Reply With Quote
 
 
 
 
james.d.masters@gmail.com
Guest
Posts: n/a
 
      06-01-2007
On May 31, 10:40 pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> $list = [];
> $list += [function()]; # $list = ["d"]!


Rewrite this longhand as:

$list = [];
$list = $list + [function()];

Which really means:

$list = [] + ["d"]

 
Reply With Quote
 
 
 
 
zarawesome@gmail.com
Guest
Posts: n/a
 
      06-01-2007
On Jun 1, 3:00 am, (E-Mail Removed) wrote:
> Rewrite this longhand as:
>
> $list = [];
> $list = $list + [function()];
>
> Which really means:
>
> $list = [] + ["d"]


Yeah, figured. It's just odd, and allows for some nice obfuscated
coding.


 
Reply With Quote
 
Harry Kakueki
Guest
Posts: n/a
 
      06-01-2007
On 6/1/07, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> On Jun 1, 3:00 am, (E-Mail Removed) wrote:
> > Rewrite this longhand as:
> >
> > $list = [];
> > $list = $list + [function()];
> >
> > Which really means:
> >
> > $list = [] + ["d"]

>
> Yeah, figured. It's just odd, and allows for some nice obfuscated
> coding.
>
>
>
>

Are you expecting ["a","b","c","d"] ?
Something to look at....

$list = $list + [function()]; # ["d"]
but
$list = [function()] + $list; # ["d","a","b","c"]



Harry
--

A Look into Japanese Ruby List in English
http://www.kakueki.com/

 
Reply With Quote
 
dblack@wobblini.net
Guest
Posts: n/a
 
      06-01-2007
Hi --

On Fri, 1 Jun 2007, (E-Mail Removed) wrote:

> On Jun 1, 3:00 am, (E-Mail Removed) wrote:
>> Rewrite this longhand as:
>>
>> $list = [];
>> $list = $list + [function()];
>>
>> Which really means:
>>
>> $list = [] + ["d"]

>
> Yeah, figured. It's just odd, and allows for some nice obfuscated
> coding.


I'm not sure how you'd obfuscate anything using +=. As far as I know,
it's completely consistent in the way it's parsed, and thoroughly
documented. Once you know how it works, the obfuscation mysteriously
vanishes


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      06-01-2007
On 01.06.2007 09:15, Michael Hollins wrote:
> (E-Mail Removed) wrote:
>> On Jun 1, 3:00 am, (E-Mail Removed) wrote:
>>> Rewrite this longhand as:
>>>
>>> $list = [];
>>> $list = $list + [function()];
>>>
>>> Which really means:
>>>
>>> $list = [] + ["d"]

>>
>> Yeah, figured. It's just odd, and allows for some nice obfuscated
>> coding.
>>
>>

>
> I'd suggest what's making for the obfuscated code here is not +=, but
> the use of a global variable and a function that has side effects.
>
> The behavior of += doesn't seem odd to me. I'd say it's well defined.


Absolutely agree! The code presented is pretty weird and far from
straight forward IMHO.

Kind regards

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[BUG] Ruby 1.9.0: possible bug when subclassing BasicObject Michael Fellinger Ruby 3 12-27-2007 04:05 PM
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
bug in ruby or bug in my brain? ngoc Ruby 3 08-09-2006 02:16 PM
#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1... anne001 Ruby 1 04-23-2006 03:02 PM
Bug in mmap or ruby with ruby-1.8.0 Han Holl Ruby 2 09-01-2003 03:17 PM



Advertisments