Prev: Thread error "undefined method `keys' for nil:NilClass"
Next: Getting version from PE executables
From: Marnen Laibow-Koser on 4 Nov 2009 09:31 Rick Denatale wrote: [...] > Certainly it could be implemented in an extension to the language as > syntactic sugar much as += and it's family. > > But I maintain, that it can't be implemented as a method, any more > than += or ||= could be. I believe you are quite wrong. If a destructive function like gsub! can be implemented as a method, then I see no reason that +=, |=, or postfix ++ couldn't be. > > If Matz deigned to do such a language change, I'd certainly feel free > to ignore it. <G> Well, as others have pointed out, Ruby's preference for iterators rather than loops makes ++ a lot less useful. I use it a lot in PHP, but I really haven't missed it in Ruby. > > I can't help but think of Alan Perlis' quip that "syntactic sugar > causes cancer of the semicolons" Cute. Of course, at some level, every programming language is syntactic sugar... > > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale Best, -- Marnen Laibow-Koser http://www.marnen.org marnen(a)marnen.org -- Posted via http://www.ruby-forum.com/.
From: Seebs on 4 Nov 2009 09:37 On 2009-11-04, Marnen Laibow-Koser <marnen(a)marnen.org> wrote: > I believe you are quite wrong. If a destructive function like gsub! can > be implemented as a method, then I see no reason that +=, |=, or postfix > ++ couldn't be. gsub! is implemented as a method on objects which contain data. ++ would have to be implemented as a method on objects which ARE their data -- which have no distinction between the object and its "contents". gsub! can work because somewhere inside the object there is a hunk of storage which is separate from the object itself. Fixnum has no such storage to refer to. -s -- Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: lith on 4 Nov 2009 09:56 > gsub! can work because somewhere inside the object there is a hunk of storage > which is separate from the object itself. Fixnum has no such storage to > refer to. I don't think ruby makes the distinction between native types & objects à la java. I don't know the ruby source but from a glance at numeric.c[1], I'd say it is handled as VALUE/ruby object like any other object. All those numeric methods seem to convert the VALUE to c numbers, do what they are supposed to do and then convert them back again. Please correct me if I'm wrong and if you know the ruby source code. I don't think ruby is in need of such an operator but I don't see why ruby shouldn't have macros to let people fake such a thing if they deem it necessary. [1] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/numeric.c?view=markup
From: Yukihiro Matsumoto on 4 Nov 2009 10:59 Hi, In message "Re: Ruby doesn't implement x++ for Fixnum's because ???" on Wed, 4 Nov 2009 23:31:46 +0900, Marnen Laibow-Koser <marnen(a)marnen.org> writes: |I believe you are quite wrong. If a destructive function like gsub! can |be implemented as a method, then I see no reason that +=, |=, or postfix |++ couldn't be. Only if you accept the language that can change the value of 1 to 2. I don't. matz.
From: Seebs on 4 Nov 2009 11:49
On 2009-11-04, lith <minilith(a)gmail.com> wrote: >> gsub! can work because somewhere inside the object there is a hunk of storage >> which is separate from the object itself. �Fixnum has no such storage to >> refer to. > I don't think ruby makes the distinction between native types & > objects � la java. Everything is an object. Not every object contains separate storage. When you write "a = 1; b = 1;", a and b do not refer to two separate objects which happen to have the same numeric value; they refer to a single object which has an immutable numeric value. You can't increment that value. -s -- Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! |