comp.lang.ada
 help / color / mirror / Atom feed
* Using 'Base
@ 2012-07-21 16:26 Simon Wright
  2012-07-26 17:21 ` Simon Wright
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Wright @ 2012-07-21 16:26 UTC (permalink / raw)


I've been working on a binding to msgpack[1]; progress so far at [2],
for booleans, integer, and modular types.

Looking at the read-integer spec, I have

   with Ada.Streams;
   generic
      type Integer_Type is range <>;
   function Message_Pack.Integer_Reader
     (From : not null access Ada.Streams.Root_Stream_Type'Class)
     return Integer_Type'Base;

and I _think_ that the point of returning the 'Base of the formal type
is that any Constraint_Errors will happen in user code during assignment
of the function result. The idea was copied from the Generic Elementary
Functions, but I may well have got the reason wrong. And, also, I may
still raise CE internally if the value received from the wire won't fit
in Integer_Type'Base.

Is there any point in a similar declaration for write-integer? At
present I have

    with Ada.Streams;
    generic
       type Integer_Type is range <>;
    procedure Message_Pack.Integer_Writer
      (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
       Item : Integer_Type'Base);

(again, cf Generic Elementary Functions).

[1] http://msgpack.org/
[2] git://git.code.sf.net/u/simonjwright/msgpack-ada/code



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

* Re: Using 'Base
  2012-07-21 16:26 Using 'Base Simon Wright
@ 2012-07-26 17:21 ` Simon Wright
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Wright @ 2012-07-26 17:21 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> I've been working on a binding to msgpack[1]; progress so far at [2],
> for booleans, integer, and modular types.
>
> Looking at the read-integer spec, I have
>
>    with Ada.Streams;
>    generic
>       type Integer_Type is range <>;
>    function Message_Pack.Integer_Reader
>      (From : not null access Ada.Streams.Root_Stream_Type'Class)
>      return Integer_Type'Base;
>
> and I _think_ that the point of returning the 'Base of the formal type
> is that any Constraint_Errors will happen in user code during
> assignment of the function result. The idea was copied from the
> Generic Elementary Functions, but I may well have got the reason
> wrong. And, also, I may still raise CE internally if the value
> received from the wire won't fit in Integer_Type'Base.

Quoting from the Ada 95 Rationale Part 3 Chapter A[3],

   "The Ada 95 version uses Float_Type'Base as a type mark in
   declarations; this was not available in Ada 83. Thus the formal
   parameter types and result types of the functions are of the
   unconstrained (base) subtype of the generic formal type Float_Type,
   eliminating the possibility of range violations at the interface."

So I was correct.

> Is there any point in a similar declaration for write-integer? At
> present I have

But I still don't see why this is needed for _parameters_; if I supply
an out-of-range value for the generic formal type, shoudn't I be warned
at the call?

>     with Ada.Streams;
>     generic
>        type Integer_Type is range <>;
>     procedure Message_Pack.Integer_Writer
>       (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
>        Item : Integer_Type'Base);
>
> (again, cf Generic Elementary Functions).
>
> [1] http://msgpack.org/
> [2] git://git.code.sf.net/u/simonjwright/msgpack-ada/code

[3]
http://www.adaic.org/resources/add_content/standards/95rat/rat95html/rat95-p3-a.html#3,
a bit over half way down



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

end of thread, other threads:[~2012-08-01  2:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-21 16:26 Using 'Base Simon Wright
2012-07-26 17:21 ` Simon Wright

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