comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Using 'Base
Date: Thu, 26 Jul 2012 18:21:56 +0100
Date: 2012-07-26T18:21:56+01:00	[thread overview]
Message-ID: <m2r4ryphe3.fsf@nidhoggr.home> (raw)
In-Reply-To: m2ipdhrsfr.fsf@nidhoggr.home

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



      reply	other threads:[~2012-08-01  2:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-21 16:26 Using 'Base Simon Wright
2012-07-26 17:21 ` Simon Wright [this message]
replies disabled

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