comp.lang.ada
 help / color / mirror / Atom feed
* Ada Gems in educational material
@ 2008-03-05 15:48 Georg Bauhaus
  2008-03-06  5:35 ` Jerry
  0 siblings, 1 reply; 5+ messages in thread
From: Georg Bauhaus @ 2008-03-05 15:48 UTC (permalink / raw)


Gem #27: Changing Data Representation (Part 1) by Robert Dewar
explains how to use type derivation if you want to have two
representations of the same data. The types let you convert
between an external and an internal representation, say.

IIRC, this is feature of Ada 83 and has been text book material
at the time. Has it got lost in modern times introductions
to Ada 95 and later? How can a valuable, venerable basic
facility for problem solving be missed?

<p mode=bold>Maybe authors and instructors have not come across
these features because the features are not easily available in
the non-Ada languages with which they have learned programming?</>



http://www.adacore.com/2008/03/03/gem-27/



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ada Gems in educational material
  2008-03-05 15:48 Ada Gems in educational material Georg Bauhaus
@ 2008-03-06  5:35 ` Jerry
  2008-03-06  9:49   ` Peter Hermann
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jerry @ 2008-03-06  5:35 UTC (permalink / raw)


On Mar 5, 8:48 am, Georg Bauhaus <rm.tsoh-plus.nicif-
bauh...@maps.futureapps.de> wrote:
> Gem #27: Changing Data Representation (Part 1) by Robert Dewar
> explains how to use type derivation if you want to have two
> representations of the same data. The types let you convert
> between an external and an internal representation, say.
>
> http://www.adacore.com/2008/03/03/gem-27/

I wonder if this works on records with discriminants.

Jerry



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ada Gems in educational material
  2008-03-06  5:35 ` Jerry
@ 2008-03-06  9:49   ` Peter Hermann
  2008-03-06 10:32   ` Georg Bauhaus
  2008-03-08  5:50   ` ME
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Hermann @ 2008-03-06  9:49 UTC (permalink / raw)


Jerry <lanceboyle@qwest.net> wrote:
> I wonder if this works on records with discriminants.
 
Jerry Jerry: you do have a free compiler and you are able to test
this within a few seconds...



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ada Gems in educational material
  2008-03-06  5:35 ` Jerry
  2008-03-06  9:49   ` Peter Hermann
@ 2008-03-06 10:32   ` Georg Bauhaus
  2008-03-08  5:50   ` ME
  2 siblings, 0 replies; 5+ messages in thread
From: Georg Bauhaus @ 2008-03-06 10:32 UTC (permalink / raw)


Jerry wrote:
> On Mar 5, 8:48 am, Georg Bauhaus <rm.tsoh-plus.nicif-
> bauh...@maps.futureapps.de> wrote:
>> Gem #27: Changing Data Representation (Part 1) by Robert Dewar
>> explains how to use type derivation if you want to have two
>> representations of the same data. The types let you convert
>> between an external and an internal representation, say.
>>
>> http://www.adacore.com/2008/03/03/gem-27/
> 
> I wonder if this works on records with discriminants.

It should work I think, according to LRM 13.5.1 and
3.2.1(6). This works with GNAT. -gnatR2[s] might be useful.

package News5 is

   -- components
   type C is range 1000 .. 5000;

   -- discriminating values
   type T is range -1 .. +1;

   -- internal type
   type R(D: T) is record
      Data: C;
   end record;

   -- external type
   type X(D: T) is new R(D);
   for X'Size use 36;
   for X use record
      Data at 0 range 0 .. 11;
      D at 0 range 24 .. 27;
   end record;


   Internal: R := R'(0, Data => 4200);
   External: X := X(Internal);

end News5;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ada Gems in educational material
  2008-03-06  5:35 ` Jerry
  2008-03-06  9:49   ` Peter Hermann
  2008-03-06 10:32   ` Georg Bauhaus
@ 2008-03-08  5:50   ` ME
  2 siblings, 0 replies; 5+ messages in thread
From: ME @ 2008-03-08  5:50 UTC (permalink / raw)


"Jerry" <lanceboyle@qwest.net> wrote in message 
news:f34a2d2c-879c-415c-ba4e-657195c92c34@34g2000hsz.googlegroups.com...
On Mar 5, 8:48 am, Georg Bauhaus <rm.tsoh-plus.nicif-
bauh...@maps.futureapps.de> wrote:
> Gem #27: Changing Data Representation (Part 1) by Robert Dewar
> explains how to use type derivation if you want to have two
> representations of the same data. The types let you convert
> between an external and an internal representation, say.
>
> http://www.adacore.com/2008/03/03/gem-27/

I wonder if this works on records with discriminants.

Jerry

Yes it does. Tucker Taft showed me how to do it. I used nested discriminated 
records even. The problem is that if you have a whole buffer of ,for 
example,commands to convert i.e. an array you can't do the type conversion 
on the whole array at once.

Ada does not allow this.

There is a lot of flexibility of course you can specify where the 
discriminant goes in the record rep clause and even change the bit order.


Then there are the usual limitations with discriminated records like the 
invariant part must come first etc. 




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-03-08  5:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-05 15:48 Ada Gems in educational material Georg Bauhaus
2008-03-06  5:35 ` Jerry
2008-03-06  9:49   ` Peter Hermann
2008-03-06 10:32   ` Georg Bauhaus
2008-03-08  5:50   ` ME

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