News for hackers. Stuff that matters.
Re:Hyperpolyglot: PHP, Perl, Python, Ruby by petercooper on Saturday August 13, 2011 @06:01PM (#2882112)
x.succ is not the Ruby equivalent of ++$x in PHP (or Perl). x.succ returns x + 1 (by default, on integers) but does not increment x as ++$x does (since numbers are immutable and that's what "x" is giving us in Ruby). The closest match would be x += 1 (shorthand for x = x + 1). I don't see x = x.succ in common usage but that would work too.
Re:Hyperpolyglot: PHP, Perl, Python, Ruby by jfarmer on Saturday August 13, 2011 @08:35PM (#2882405)
Yeah, #succ is something else. For example, if your object supports #succ then you can use it in ranges.

e.g., (1..10), but also ("apple".."kiwis") or ('A'..'Z').

In this case, String#succ returns a string with the last alphanumeric character transformed into its successor, e.g., "apple".succ == "applef".

The only time I've used it is implementing the range interface; I've never called it directly, let alone to increment an integer.

Re:Hyperpolyglot: PHP, Perl, Python, Ruby by neutronicus on Saturday August 13, 2011 @08:44PM (#2882418)
I assume you mean "apple".succ == "applf" ?
Re:Hyperpolyglot: PHP, Perl, Python, Ruby by jfarmer on Monday August 22, 2011 @02:49PM (#2913582)
Yes
Re:Hyperpolyglot: PHP, Perl, Python, Ruby by gb on Saturday August 13, 2011 @06:16PM (#2882133)
I don't disagree with what you're saying, but it does mention in the comment that x is not mutated.
Re:Hyperpolyglot: PHP, Perl, Python, Ruby by petercooper on Saturday August 13, 2011 @06:23PM (#2882139)
I totally didn't notice that note but the page doesn't seem to have been updated since then :-)

I still don't see why it doesn't just use the common syntax though that does the same thing. It's intriguing that the Python one has no example for that row. Perhaps they are specifically looking for idiomatic techniques, even if they're not commonly used.

I note that the page is on a wiki so I could fix it, but given it's been there for years, I suspect there's a good reason no-one has already made the change.

Re:Hyperpolyglot: PHP, Perl, Python, Ruby by adyus on Saturday August 13, 2011 @08:22PM (#2882371)
As a Ruby noob and without researching too much, here's my question: would x.succ! do it?
Re:Hyperpolyglot: PHP, Perl, Python, Ruby by petercooper on Saturday August 13, 2011 @11:10PM (#2882674)
Not if x were a regular old Fixnum.

The reason is that x would be referring to a number like 1, 42, or whatever, and numbers are immutable in Ruby. You can't "change" a number in-place. If you could change Ruby's concept of 1 into 2, then 1 would cease to exist and that would be a Bad Thing™ :-)