Mon, 29 Oct 2001 11:44:23 +1300
text/plain; charset="us-ascii"; format=flowed
Here is a package that implements a type of String. Each String can have
Unlike with Ada.Strings.Bounded.Bounded String, there is not a need to
know what the maximum length of a string is. Unlike GNAT's
Unbounded_String's,the package could be significantly faster.
This following design could have 'SV' compiled if there was no "out" in
the record. That "out" is a new proposed feature that provides a way of
making data entities be read-only. The "out" is there to make the
component named "Ptr" be read-only. An aim here is to get convenient
access to every byte in the SV String's 'Ptr.all' whilst avoiding a use
of the Controlled types that are in Unbounded Strings. Unbounded Strings
are slow and SV Strings could be faster and possibly a lot faster (in
GNAT). But the language maybe does not have the right features needed.
procedure Test is
package SV is
type String_Access is access all String;
Null_String_Access : constant String_Access;
type Vstr is
Ptr : out String_Access := Null_String_Access;
Len : Natural := 0;
procedure Free (X : in out Vstr);
function "+" (Source : Vstr) return String; -- pragma Inline ("+");
Null_String_Access : constant String_Access := new String (1 .. 0);
package body SV is ... end SV;
X, Y : SV.Vstr;
-- All these 4 cases are legal and illegal in the way needed
X := Y; -- Illegal due to the 'limited' and the 'out'
X.Len := Y.Len; -- Legal
X.Ptr.all := Y.Ptr.all; -- Legal. Better than Unbounded_String style
X.Ptr := Y.Ptr; -- Illegal because the LHS is read-only due to
-- the use of the "out" keyword.
Without the "out" there would be a problem, which is that a package
with-ing the SV package can do this:
A.Len := B.Len;
A.Ptr := B.Ptr;
That last line involves the copying of a pointer. The designer of the SV
package wants to stop copying of pointers (then the user is less likely to
have a problem when reclaiming the memory of both A and B.
If the "String_Access" type were instead defined by:
type String_Access is access constant String;
then that, allows assigning to A.Ptr and it stops assigning to A.Ptr.all.
That is swapped from what is wanted.
To make Ptr be 'limited private' stops initialising since it is limited.
To make Ptr private stops the user from writing "Ptr.all". A function can
return the value of the "Ptr" component. But then ".all" can't be
appended to a function (but a feature like that could be nice).
Something like this has to be written. This this has an extra line:
AR := Ref_Val (A);
AR.all := B.Ptr.all;
A.Len := B.Len;
The default mode for records can be an "in out" mode. A synonym for
"in out" can be "var" or "ref". If package spec variables default to
being "out" then there could be a lot of variables that can be written
Big systems with read-write access to thousands of variables, most
of which only need to be available read-only, are going to be less
safe. How can Ada be advocated to an optimum degree if another
language allows read only publishing of the values of data objects.
At the Ada-Comment, there was a man from Boeing that said that the
certifier required no inlining. Perhaps due to bugs (maybe including
optimiser bugs). That person said privately to me that a compiler
already allowed the exporting in a read only way, of variables in
a package spec. However it was done with a pragma. Does anybody know
the names of compilers allowing read only exporting of data that is
variable inside the package body ?.
Here is an example of a new design I propose. "var" is a synonym for
"in out". Some global option(s) allow switching between "in out"
mode and the read-only "out" mode.
package Q is
X : var Integer := 0; -- packages with-ing Q can write to Q.X
I could have e-mailed this to Ada-Comment @ adaic.org.
Top vendors (ACT, and some others were unclear) were at that list
declaring briefly that Ada does not need a read-only feature since
inlining is possible and so is asking users to add ".all" to each
var, and also there is an export/import option.
Here is a URL of the Ada-Comment list (that is moderated by
Mr R. Brukardt) (I guess people didn't know it was there):
What are the arguments in favour of prohibiting variables and
record components from having their values be 'published in a read
only way' ?. I guess we don't know.
Mailing Lists: http://www.ijs.co.nz/ada_95.htm