On Mon, 2002-10-28 at 09:49, William Djaja Tjokroaminata wrote:

> Well, it may occur in C++ programs, but it is not the intention.  Suppose
> 
>     derived a;
>     parent  b;
>     parent  c;
>     ....
>     a = b + c;
> 
> Assuming that this code compiles and executes, here we are guaranteed that
> the class of a is "derived" (i.e., a will respond to methods that
> are defined for class derived). 

Well, yes ... but this is doing something completely different than the
Ruby example.  b and c are added together (for some definition of "+")
and the result is a Parent type.  The parent is then converted to the
derived type (either by an appropriate constructor or assignment
operator in Derived).

The same effect can be achieved in Ruby with ...

    b = Parent.new
    c = Parent.new
    a = Derived.from_parent(b+c)

Here "from_parent" performs the same function as the CTOR/Assignment
statement in C++.

However, the original question was slightly different in that it had
either b or c being objects of the derived type and dynamically
determining the proper return type.

> There may be some semantic/logic error
> depending on the overloadings of the '+' and '=' operators, but that is a
> separate issue.

Right... to get the proper behavior in C++, you must explicitly program
for it.  Likewise in Ruby.

> >> In a "typeless" language such as Ruby,
> 
> > Ruby is hardly "typeless".  It has all kinds of types.  Types are a very
> > important part of programming in Ruby. (end of mild rant)
> 
> Oh, I agree completely.  I just use a terminology that apprently has been
> used very often here.  I think the term "typed/typeless" is usually
> used to refer to the variables themselves, and not the objects.

I don't mind the "typeless" modifier being applied to variables.  I was
objecting to it being applied to the language. :-)

-- 
-- Jim Weirich     jweirich / one.net    http://w3.one.net/~jweirich
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct, 
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)