From: Martin Krischik <martin@krischik.com>
Subject: Re: Discriminant computation problem
Date: Mon, 15 Nov 2004 16:16:24 +0100
Date: 2004-11-15T16:16:24+01:00 [thread overview]
Message-ID: <1428466.J51lMFusOX@linux1.krischik.com> (raw)
In-Reply-To: 7e2ad2d.0411150602.79ee1251@posting.google.com
Sandro Magi wrote:
> Jim Rogers <jimmaureenrogers@att.net> wrote in message
> news:<yjVld.906538$Gx4.504752@bgtnsc04-news.ops.worldnet.att.net>...
>> You might want to reconsider your design.
>> First of all, your chosen example is a very poor way to represent
>> a bit vector in Ada. This appears to be an Ada translation of a C
>> or C++ programming approach.
>
> As I said, it was just the simplest example of what I was trying to
> do. It's not what I'm actually trying to do.
>
>> My second point deals with your desire to perform a calculation
>> on a parameterized value. The more acceptable way to accomplish
>> such an end is the use of a generic package rather than a
>> record discriminant. The use of a generic package provides
>> encapsulation and information hiding for your operations that
>> prevent you from unnecessarily exposing internal data structures.
>
> I was trying to avoid the extra step of instantiating a generic
> package. Furthermore, the types from one package would not be
> interoperable with the types from another package would they? ie.
> using my Bit_Vector example and assuming the package defines an Append
> operation:
>
> procedure Test is
> package Bit_Vector_1024 is new Bit_Vector(1024);
> package Bit_Vector_2048 is new Bit_Vector(2048);
>
> b1024 : Bit_Vector_1024.Bit_Vector;
> b2048 : Bit_Vector_2048.Bit_Vector;
Hint: When you have a package and a type with the same name you can't "use"
that package without risking name clashes. That's why most packages have
name for multiples like Unbounded_Strings.
> begin
> ...
> (initialize some data in each vector)
> ...
> --this would fail to type check wouldn't it?
> Append(Data=>b1024, To=>b2048);
> end Test;
>
> Sorry for asking something so obvious, but I can't check this myself
> at the moment.
Deppends on how the types and the parameters are defined. If both
Bit_Vector_1024.Bit_Vector and Bit_Vector_2048.Bit_Vector are subtypes with
a common ancestor then it well could work:
In Ada, with it's extensive type system, getting the types right is more
important then getting the procedures right.
With Regards
Martin
--
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com
next prev parent reply other threads:[~2004-11-15 15:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-15 1:11 Discriminant computation problem Sandro Magi
2004-11-15 3:24 ` Jim Rogers
2004-11-15 14:02 ` Sandro Magi
2004-11-15 15:16 ` Martin Krischik [this message]
2004-11-15 16:02 ` Dmitry A. Kazakov
2004-11-15 22:11 ` Nick Roberts
2004-11-15 23:25 ` tmoran
2004-11-16 20:00 ` Nick Roberts
2004-11-16 20:14 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox