On Oct 29, 9:18 ¨Âí¬ ÒéãèáòäÏîÒáéìó <RichardDummyMailbox58... / USComputerGurus.com> wrote: > Hi, > > In The Well Grounded Rubyist (which, ¨Âìïîç ÷éôè ÔèÒõâù ×áù¬ > love), ¨ÂáöÂìáãðòåóåîôó êõóôéæéãáôéïæïôèø«ïíéóóéïî éî > Ruby. ¨Â ôèïõçèɧóå÷èåôèåãïõìéíðìåíåîêõóô ôè> incrementing portion of C's x++ functionality (without the prefix/ > postfix issues) in pure Ruby. ¨Â ÷áóîÃÕ willing to delve into Matz> implementation of higher-level Ruby functions or low-level C/C++ > code. ¨Âåìï÷ éó ÷èáô ãáíå õð ÷éôè> > Q1. ¨Âåóæáéìåäéíáçéîå¬ ¨Âåãáõóå ôèéîôåòðòåôèïõçèÅ¢h, 7ÃÔ > a Fixnum which I Á×e seen billions of times, so I know what to do with > it. ¨Âèõó¬ ¨Âéçîïòåíù ïöåòòéäéîäåæéîéôéïî ïæ Æéøîõí ¨Â> call it ÅÄompiler error to use the vernacular, ¨Âòåðïòôéîôèáôáä îï íåôèïä ÅÑp ¨Âáì÷åô¿ > > Test 2 passed, ¨Âõô éô ÷éôè ãïõðìå ïæ áîïíáìéåóº > > Q2. x.to_s yielded xÃÔ class and address, suggesting x had become a > ÅÔemi-Fixed Num i.e, x now stored a REFERENCE to the to xÃÔ data, > rather than the immediate storage of the data, as interpreter is wont > to do with FixnumÃÔ. m I all wet? > > Q3. y.inspect yielded only itÃÔ value (8) and nothing else, > suggesting the x.pp yielded a full-fledged Fixnum. m I all wet? > > Dave Black argues that since Fixnum values use immediate storage > rather than referenced storage, x=1;x++ would be akin to changing 1 > into 2. his example somewhat supports that view, ut the > interpreter sidestepped the matter by creating a reference for xÃÔ > value and an immediate value for y (=x.pp). > > Any ideas, > Richard > > class FixNum > attr :val > def initialize (fixnum) > puts "Initializing object %d" % fixnum > raise "Initializer not a Fixnum" if > fixnum.class != Fixnum > puts "\nInitializing Fixnum to %d" % fixnum > @val = fixnum > end > > def pp > @val+=1 > end > end > > # Test 1 (Failure) > x = 7; = x.pp; z =x.class # undefined method `pp' for 7:Fixnum > (NoMethodError) > > # Test 2 (Success) > x = FixNum.new(7); = x.pp; z =x.class > puts [x.to_s, y.inspect, z.to_s].join("; ") # => <FixNum:0x2b62694>; > 8; FixNum Hi, Please ignore my questions. I just discovered a major mistake: I thought I was overriding Ruby's Fixnum class, but I misspelled it at FixNum. That error invalidates most if not all of the things I reported. Mea Culpa. I'll correct my errors and probably have a new theory subsequently. Best wishes, Richard