From: Anders Borch Date: 2003-07-18T02:59:00+09:00 Subject: Re: Keyword "with" Hal E. Fulton wrote: > ----- Original Message ----- > From: "Anders Borch" > Newsgroups: comp.lang.ruby > To: "ruby-talk ML" > Sent: Thursday, July 17, 2003 6:15 AM > Subject: Re: Keyword "with" > > > >>def loadpp(l) >> s = '' >> f = File.new(l,'r') >> f.each_line do |line| >> s += line.gsub(/(\w)\+\+)/,'\1=\1.succ') + "\n" >> end >> eval(s) >>end > > > I haven't played with this at all... but let me > remind you that the ++ operator comes in both > pre and post forms. > > Until these code fragments both work, I'd say > you haven't actually implemented it, even as a > preprocessor kind of thing: > > x = 5 > y = x++ > puts y # 5 > > y = ++x > puts y # 6 > > Cheers, > Hal > I was merely showing a proof of concept (implementing pre-increment since that was the easy one), but if you like, I shall implement both pre- and postincrement. I saw the flaw you pointed out shortly after posting, but saw no need to complicate my implementation unless someone actually made the explicit distinction between the two forms of incrementation. I am personally against using these tricks in any serious form (remember ruby goto in an earlier post?) or have you ever looked at the AND, OR, NOT macros defined for C? I feel no need to change the language merely for the sake of change. Especially when the change does not add to readability. AND, OR, and NOT are not very readable IMHO there is a need to explicitly specify && or & as logical or binary AND. The == operator does not really add any functionality to ruby, but it would add readability since *a lot* of programmers out there knows pre and post increment. /Anders