comp.lang.ada
 help / color / mirror / Atom feed
From: gmc444@yahoo.com (Greg C)
Subject: Re: Ada / C++ comparison paper
Date: 20 Dec 2001 12:16:06 -0800
Date: 2001-12-20T20:16:07+00:00	[thread overview]
Message-ID: <62340e2a.0112201216.3480a14f@posting.google.com> (raw)
In-Reply-To: 1008859296.991767@master.nyc.kbcfp.com

"Hyman Rosen" <hyrosen@mail.com> wrote in message news:<1008859296.991767@master.nyc.kbcfp.com>...
> "Greg C" <gmc444@yahoo.com> wrote in message
> news:62340e2a.0112190810.16f029ff@posting.google.com...
> > Actually, this is not true. In Eiffel the parent's methods can declare
> > parameter types such that child classes can be substituted.
> 
> "Can" but not "must". In C++ terms, Eiffel allows this:
> 
> struct a { virtual void f(const a &p_a) const; };
> struct b : a { virtual void f(const b &p_b) const; };
> 
> with b::f considered the overrider of a::f. Now, suppose
> I have this function:
> 
> void apply(const a &a1, const a &a2) { a1.f(a2); }
> 
> Even though this compiles without any problem, I have
> no assurance that it will not fail at runtime, because it's
> possible for a1 to refer to a "b" object while a2 refers
> to an "a" object. Eiffel advocates hope for whole-program
> analysis to save them from this by trying to track whether
> such a case actually arises. Feh.

Well, this is getting way off-topic for comp.lang.ada, but here
is an Eiffel version of what you sketched out above, compiled
and executed with the SmallEiffel compiler
(http://smalleiffel.loria.fr)

The compiler doesn't catch B referencing an A object at compile time,
but it the error can be trapped at runtime with an assertion declared
in A. Even though class B redefines "foo" the redefined version still
has to conform to A's contract, and indeed, the violation you talk
about is detected.

I think the notion that these violations can be found at compile time
is an ideal , but Eiffel compiler writers understand that this is an
ideal only and so there are facilities to detect these kinds of
problems at runtime.

Greg

------------
class A creation make
feature 
   make is do end 

   foo(in: like Current) is 
      require 
         in.conforms_to(Current)
      do  
         print("Foo of A%N")
      end 
end -- A
-----
class B
inherit A redefine foo end; 
creation make

feature 
   foo(in: B) is 
      do  
         print("foo B%N")
      end 
end -- B
--------
class TEST
creation make
feature 
   make is 
      local a, ab: A;
      do  
         create a.make;
         create {B} ab.make;
         apply(a,a);
         apply(a,ab);
         apply(ab,ab);
         apply(ab,a)  -- Assertion violation
      end 
feature 
   apply(one, two: A) is 
      do  
         one.foo(two)
      end 
end -- TEST

------------- output
Foo of A
Foo of A
foo B
Line : 7 column 15 in .\a.e.
*** Error at Run Time *** :
   Target is not valid (not the good type).
   Expected: "B", Actual: "A".



  reply	other threads:[~2001-12-20 20:16 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-17 10:22 Ada / C++ comparison paper Martin Dowie
2001-12-17 14:42 ` Frode Tenneboe
2001-12-17 22:07   ` Hyman Rosen
2001-12-17 22:34     ` David C. Hoos
2001-12-17 22:37     ` Marin David Condic
2001-12-18  0:54       ` Ed Falis
2001-12-18  9:30         ` martin.m.dowie
2001-12-18 14:49           ` Marin David Condic
2001-12-18 17:51           ` Hyman Rosen
2001-12-19 16:10             ` Greg C
2001-12-20 14:41               ` Hyman Rosen
2001-12-20 20:16                 ` Greg C [this message]
2001-12-19 20:44             ` Wes Groleau
2001-12-19 20:47               ` Ed Falis
2001-12-20 18:16                 ` Ted Dennison
2001-12-20 19:12                 ` Richard Riehle
2001-12-18  1:16       ` Larry Kilgallen
2001-12-17 22:52     ` Matthew Heaney
2001-12-18 15:47     ` Hyman Rosen
2001-12-18 16:20       ` Pat Rogers
2001-12-18 17:00         ` Hyman Rosen
2001-12-18 17:28           ` Larry Kilgallen
2001-12-18 19:40         ` Brian Rogoff
2001-12-18 20:25           ` Hyman Rosen
2001-12-19  0:53           ` was Re: Ada / C++ comparison paper anymore Mark Lundquist
2001-12-19  1:47             ` Brian Rogoff
2001-12-19 18:20               ` Mark Lundquist
2001-12-19 19:39                 ` Patrick Hohmeyer
2001-12-19 19:38                   ` Mark Lundquist
2001-12-19 20:51                     ` Patrick Hohmeyer
2001-12-20 17:56                       ` Brian Rogoff
2001-12-20 18:48                         ` Patrick Hohmeyer
2001-12-20 19:20                           ` Brian Rogoff
2001-12-21  3:16                             ` Implicit instantiation (was Re: Ada / C++ comparison paper anymore) Mark Lundquist
2001-12-21  3:12                           ` Implicit instantiation (was Re: was " Mark Lundquist
2001-12-21  2:55                       ` Mark Lundquist
2001-12-20 20:22             ` was Re: Ada / C++ comparison paper anymore Ted Dennison
2001-12-20 20:57               ` Marin David Condic
2001-12-21 17:44               ` Richard Riehle
2001-12-21 17:51                 ` Marin David Condic
2001-12-19 18:20       ` Ada / C++ comparison paper Mark Lundquist
2001-12-20 20:27         ` Ted Dennison
2001-12-20 20:59           ` Marin David Condic
2001-12-21 14:26             ` Ted Dennison
2001-12-21 14:32               ` Marin David Condic
2001-12-21 15:11               ` Jean-Marc Bourguet
2001-12-20 22:30           ` tmoran
2001-12-20 22:36             ` Marin David Condic
2001-12-21 14:23             ` Ted Dennison
2001-12-21 18:46               ` tmoran
2001-12-21 19:09                 ` Ted Dennison
2001-12-21  2:46           ` Mark Lundquist
2001-12-21 14:28             ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox