From: Mike Young <mikey@mcs.com>
Subject: Re: Something like "->" in Ada?
Date: 1996/04/04
Date: 1996-04-04T00:00:00+00:00 [thread overview]
Message-ID: <3164A243.418D@mcs.com> (raw)
In-Reply-To: dewar.828580219@schonberg
Robert Dewar wrote:
>
> Mike said
>
> "But, as you say, it's probably a matter of acclimation."
>
> Probably. One thing you can say is that the Ada approach is more general.
> FOr instance if you declare an operation "+" in an abstract algebra, and
> then you derive a particular concrete algebra with a specific concrete
> "+" operator, this fits into the Ada scheme cleanly and easily, but in
> a "send mssage to this object" paradigm, it is awkward and forced, if
> cleanly possible at all.
===========
It seems the mention of "sending messages" sidetracked this to something
like Smalltalk (?). This was not the intention. In either case, I miss
your point.
It's not possible in C++ to override an infix operator (that is, they
cannot be virtual... ummm, polymorphic). The "work-around" is to define
a concrete infix operator in terms of a polymorphic private method:
class B {
public:
B operator+(const B& b) const
{ return Add(b); }
private:
virtual B Add(const B& b) const = 0; // pure virtual
};
Public concrete children of B will now dispatch to their own (or
inherited) Add, unless some intervening class in the inheritance chain
also hides (can't override) "+".
I don't recall how overriding infix operators fits in context with the
original discussion regarding x.f() versus f(x). Also, as yet, nobody
addressed the disparity between attributes and sub-programs in context
of cascading (C++, Java) vs explicitly passing "this" to sub-programs
(Ada). The following are (I hope) equivalent:
Java-ish:
d = x.a().b().c; // where c is an attribute of return from b().
e = x.a().b().c(); // where c is a method of return from b().
f = x.a().b.c(); // where b is an attribute of return from x.a()
Ada-ish:
D := B(A(X)).C;
E := C(B(A(X)));
F := C(A(X).B);
In all Java-ish examples, the path from x to a to b to c is clear and
consistent. I apparently have a great deal of re-acclimating to do
before intuitively grasping the same in Ada-ish. I understand the
algorithm: start from deepest paren level, look left, look right, repeat
until we run outa parens. This feels very much like the much despised
C-pointer-to-function "parsing" algorithm.
(I'm not nit-picking the languages to death. This follows-up on the
original poster's question regarding preference for Perl's "->" notation
versus Ada's function call notation.)
Mike.
next prev parent reply other threads:[~1996-04-04 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-04-01 0:00 Something like "->" in Ada? Chris O'Regan
1996-04-01 0:00 ` Robert Dewar
1996-04-02 0:00 ` Mike Young
1996-04-03 0:00 ` Robert Dewar
1996-04-04 0:00 ` Mike Young [this message]
1996-04-04 0:00 ` Mike Young
1996-04-03 0:00 ` Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox