From: dblack@... Date: 2007-08-08T20:26:59+09:00 Subject: Re: Question - Passing parameters by reference Hi -- On Wed, 8 Aug 2007, Gary Wright wrote: > > On Aug 7, 2007, at 6:28 PM, dblack@rubypal.com wrote: >> I'm thinking more about variables than literals, though, because >> that's where the questions arise. It's easy to see that 1++ is >> meaningless; but it's harder, I've found at least, to explain why: >> >> x = 1 >> x++ >> >> wouldn't make sense, without recourse to explaining the immediate >> presence of 1 in x. > > Take a look at this message from Matz: > . > > I have to think about this a bit more, but it isn't clear to me > why the concept of immediate values needs to be introduced in order > to explain the problems with x++ in Ruby. > > It seems to me that the idea of immediate values is not something > inherent in Ruby's semantics but instead is baggage that arrives > with programmers (myself included) coming from other languages. > We try to find a place for it in Ruby when it isn't really needed. I don't know -- in my case, I just always remember reading and learning that a = 1 resulted in a having the immediate value of 1 (specifically in Ruby, I mean). I have no instinct or incentive to introduce or find a place for the concept if it isn't there already. My understanding, which could be wrong, is that that's how things were actually happening. And remember that the whole concept of an "implementation detail" is relatively new in Ruby, since it's only recently that we've started dealing concretely with multiple implementations and the whole set of issues surrounding what is and is not a Ruby implementation. >> It's definitely not in the interest of pushing >> implementation details into view; it's more a matter of accounting for >> the semantics of the language and the behavior of its methods (things >> like ++ and why one can't append to symbols). > > Do those examples really require the introduction of immediate values? Again, I can't speak to the introduction point directly, because my impression is that the immediate value thing is already there. But as to the explanatory value -- I've always reached for the immediate value, unique, immutable explanation because I thought it was accurate and it helped people understand what was happening and how to use the objects. I've therefore never seen the need to look further. (Call it "Black's Razor", or something :-) I don't know whether it's necessary or not, though. It's certainly not a magic bullet, especially in the case of symbols. > [... various interesting ideas for other ways of explaining thigns > ...] > > Instead of using the immediate value abstraction though, the > situation can be explained by correcting the erroneous assumption > that fixnum objects are containers for an integer value that can > be changed. There is an extra level of indirection in the string > case that simply doesn't exist in the fixnum case. It's interesting -- I think it's always about that extra level of indirection, and perhaps just a matter of where one assigns it a place in the diagram, so to speak. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)