From: "David A. Black" Date: 2005-10-03T05:51:14+09:00 Subject: Re: C++ equivs in Ruby Hi -- On Mon, 3 Oct 2005, Robert Klemme wrote: > Pascal GUICHARD wrote: > >> - on pointers, i try to understand (howto implement) datastructures >> in which you need to mix values and references/poiters > > You cannot use values in Ruby directly. There are only references. Think of > Ruby as Java without POD's. In practice there are some optimizations for > Fixnums, Symbols and some other types but conceptually (i.e. from a usage > point of view) you never see values directly. > > x = nil > x = Object.new > x = "foo" > x = 123 > > Here "x" is always a reference variable - like every other variable is a > reference variable. It's so simple but sometimes difficult to get used to - > especially when coming from other programming languages. I think the "immediate value" status of Fixnums etc. goes beyond just being an optimization, though, and has some practical consequences and even some explanatory power. In particular, in: x = 123 x holds the immediate value 123, rather than a reference to it, which is the rationale Matz has always given for not having x++ (i.e., it would be equivalent to doing 123++ and that would make no sense). David -- David A. Black dblack@wobblini.net