comp.lang.ada
 help / color / mirror / Atom feed
* meaning of "current instance"
@ 1999-11-11  0:00 Matthew Heaney
  1999-11-11  0:00 ` Robert A Duff
  1999-11-11  0:00 ` tmoran
  0 siblings, 2 replies; 22+ messages in thread
From: Matthew Heaney @ 1999-11-11  0:00 UTC (permalink / raw)


I have some code below that I thought had a bug (um, I mean "error"), 
but now I'm not so sure.

Suppose I have this:

  type T is tagged private;
...
  function Init (O : access T'Class)

  type T is
    tagged record
      I : Integer := Init (T'Access);
    end record;

If I have an object of type T:

declare
  O1 : T;
begin

then it's clear that the "current instance" to which T'Access refers has
type T.

But now suppose I derive from T:

  type NT is new T with null record;

and declare an instance of type NT:

declare
  O2 : NT;
begin

Object O2 (like O1) has a component I, which is initialized with the
"current instance."  But what is the type of the "current instance"
here, passed to Init?


--STX
with Ada.Text_IO;  use Ada.Text_IO;

package body P.C is

  function Do_Init (O : access NT) return Integer is
  begin
    Put_Line ("P.C.Do_Init");
    return 1;
  end;

end P.C;
package P.C is

  type NT is new T with null record;

private

  function Do_Init (O : access NT) return Integer;

end P.C;
with Ada.Text_IO;  use Ada.Text_IO;

package body P is

  procedure Put (O : in T'Class) is
  begin
    Put_Line ("I is" & Integer'Image (O.I));
  end;

  function Init (O : access T'Class) return Integer is
  begin
    Put_Line ("P.Init");
    return Do_Init (O);
  end;


  function Do_Init (O : access T) return Integer is
  begin
    Put_Line ("P.Do_Init");
    return 0;
  end;


end P;
package P is

  type T is tagged limited private;

  procedure Put (O : in T'Class);

private

  function Init (O : access T'Class) return Integer;

  function Do_Init (O : access T) return Integer;

  type T is
    tagged limited record
      I : Integer := Init (T'Access);
    end record;

end P;
with P;   use P;
with P.C; use P.C;

procedure Test_P is
  OT : T;
  ON : NT;
begin
  Put (OT);
  Put (ON);
end;




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

* Re: meaning of "current instance"
  1999-11-11  0:00 meaning of "current instance" Matthew Heaney
@ 1999-11-11  0:00 ` Robert A Duff
  1999-11-11  0:00   ` Matthew Heaney
  1999-11-15  0:00   ` Tucker Taft
  1999-11-11  0:00 ` tmoran
  1 sibling, 2 replies; 22+ messages in thread
From: Robert A Duff @ 1999-11-11  0:00 UTC (permalink / raw)


"Matthew Heaney" <matthew_heaney@acm.org> writes:

> I have some code below that I thought had a bug (um, I mean "error"), 

;-)

> but now I'm not so sure.
> 
> Suppose I have this:
> 
>   type T is tagged private;
> ...
>   function Init (O : access T'Class)
> 
>   type T is
>     tagged record
>       I : Integer := Init (T'Access);
>     end record;

I think you want T to be limited, or else use 'Unchecked_Access.

> If I have an object of type T:
> 
> declare
>   O1 : T;
> begin
> 
> then it's clear that the "current instance" to which T'Access refers has
> type T.
> 
> But now suppose I derive from T:
> 
>   type NT is new T with null record;
> 
> and declare an instance of type NT:
> 
> declare
>   O2 : NT;
> begin
> 
> Object O2 (like O1) has a component I, which is initialized with the
> "current instance."  But what is the type of the "current instance"
> here, passed to Init?

Um, I guess it's T, but what difference does it make?  It's *tag* is
NT'Tag.  Inside Init, we have a value of an anonymous
access-to-class-wide.  So if Init dispatches, it will dispatch to
an NT operation.

> --STX
> with Ada.Text_IO;  use Ada.Text_IO;
> 
> package body P.C is
> 
>   function Do_Init (O : access NT) return Integer is
>   begin
>     Put_Line ("P.C.Do_Init");
>     return 1;
>   end;
> 
> end P.C;
> package P.C is
> 
>   type NT is new T with null record;
> 
> private
> 
>   function Do_Init (O : access NT) return Integer;
> 
> end P.C;
> with Ada.Text_IO;  use Ada.Text_IO;
> 
> package body P is
> 
>   procedure Put (O : in T'Class) is
>   begin
>     Put_Line ("I is" & Integer'Image (O.I));
>   end;
> 
>   function Init (O : access T'Class) return Integer is
>   begin
>     Put_Line ("P.Init");
>     return Do_Init (O);
>   end;
> 
> 
>   function Do_Init (O : access T) return Integer is
>   begin
>     Put_Line ("P.Do_Init");
>     return 0;
>   end;
> 
> 
> end P;
> package P is
> 
>   type T is tagged limited private;
> 
>   procedure Put (O : in T'Class);
> 
> private
> 
>   function Init (O : access T'Class) return Integer;
> 
>   function Do_Init (O : access T) return Integer;
> 
>   type T is
>     tagged limited record
>       I : Integer := Init (T'Access);
>     end record;
> 
> end P;
> with P;   use P;
> with P.C; use P.C;
> 
> procedure Test_P is
>   OT : T;
>   ON : NT;
> begin
>   Put (OT);
>   Put (ON);
> end;

Seems to me it should print:

    I is 0
    I is 1

But I don't see what the type of the expression T'Access has to do with
it, so perhaps I'm misunderstanding your question.

- Bob




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

* Re: meaning of "current instance"
  1999-11-11  0:00 meaning of "current instance" Matthew Heaney
  1999-11-11  0:00 ` Robert A Duff
@ 1999-11-11  0:00 ` tmoran
  1999-11-11  0:00   ` Matthew Heaney
  1 sibling, 1 reply; 22+ messages in thread
From: tmoran @ 1999-11-11  0:00 UTC (permalink / raw)


In
> type T is
>   tagged record
>     I : Integer := Init (T'Access);
what does Init(T'Access) mean?




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

* Re: meaning of "current instance"
  1999-11-11  0:00 ` Robert A Duff
@ 1999-11-11  0:00   ` Matthew Heaney
  1999-11-11  0:00     ` Tucker Taft
  1999-11-15  0:00   ` Tucker Taft
  1 sibling, 1 reply; 22+ messages in thread
From: Matthew Heaney @ 1999-11-11  0:00 UTC (permalink / raw)


In article <wcc7ljo3ld8.fsf@world.std.com> , Robert A Duff 
<bobduff@world.std.com>  wrote:

> I think you want T to be limited, or else use 'Unchecked_Access.

Yes.  (The example code below is limited.)


>> Object O2 (like O1) has a component I, which is initialized with the
>> "current instance."  But what is the type of the "current instance"
>> here, passed to Init?
>
> Um, I guess it's T, but what difference does it make?  It's *tag* is
> NT'Tag.  Inside Init, we have a value of an anonymous
> access-to-class-wide.  So if Init dispatches, it will dispatch to
> an NT operation.

Function Init does indeed call a dispatching operation.  I was hoping
that the tag of the parameter was NT'Tag, and you have confirmed that
that should be the tag.

However, my compiler (GNAT v3.12p) doesn't dispatch on the NT operation;
it calls the operation for T.


>> procedure Test_P is
>>   OT : T;
>>   ON : NT;
>> begin
>>   Put (OT);
>>   Put (ON);
>> end;
>
> Seems to me it should print:
>
>     I is 0
>     I is 1

That's what I was hoping it would do.  But with my compiler, that's not
what it does.  (The output of my compiler is "I is 0" both times.)


> But I don't see what the type of the expression T'Access has to do with
> it, so perhaps I'm misunderstanding your question.

Perhaps I stated my question incorrectly.

I do not care about the type of the expression T'Access.

I do care about the type of the object designated by the access object
returned by T'Access.

I care because I want to call an operation that dispatches on the tag of
the designated object:

  function Init (O : access T'Class) return Integer is
  begin
    return Do_Init (O);
  end;

where Do_Init is a (private) primitive operation:

  function Do_Init (O : access T) return Integer;


For object O1 (of type T), I want T's Do_Init to be called.

For object O2 (of type NT), I want NT's Do_Init to be called.

My compiler calls T's Do_Init for both O1 and O2.



--
It is impossible to feel great confidence in a negative theory which has
always rested its main support on the weak points of its opponent.

Joseph Needham, "A Mechanistic Criticism of Vitalism"




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

* Re: meaning of "current instance"
  1999-11-11  0:00 ` tmoran
@ 1999-11-11  0:00   ` Matthew Heaney
  1999-11-12  0:00     ` tmoran
  0 siblings, 1 reply; 22+ messages in thread
From: Matthew Heaney @ 1999-11-11  0:00 UTC (permalink / raw)


In article <cgGW3.175$dp.21730@typhoon-sf.snfc21.pbi.net> , 
tmoran@bix.com  wrote:

> In
>> type T is
>>   tagged record
>>     I : Integer := Init (T'Access);
> what does Init(T'Access) mean?

The locution "T'Access" inside the declaration of type T means the
"current instance" of the type, similar to "self" in other languages.

This syntax seems to throw everyone off, I guess because you're using
the name of a type (instead of an object) as the target of 'Access.

No, it is not an error.  "<type name>'Access" means "current instance"
of the type.

What I'm trying to do here is let a descendent define what the default
value of a component is, for a component declared in the ancestor.

Function Init takes an access parameter designating T'Class.  It is
implemented by calling a primitive operation that dispatches according
to the tag of the "current instance," which can be any type in the
class.


--
If we let the Creationists have their way, we may as well go whole hog.
Let us reintroduce the flat-earth theory, the chemistry of the four
elements, and mediaeval astrology.  For these outworn doctrines have
just as much claim to rival current scientific views as Creationism does
to challenge evolutionary biology.

Abusing Science: The Case Against Creationism
Philip Kitcher




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

* Re: meaning of "current instance"
  1999-11-11  0:00   ` Matthew Heaney
@ 1999-11-11  0:00     ` Tucker Taft
  0 siblings, 0 replies; 22+ messages in thread
From: Tucker Taft @ 1999-11-11  0:00 UTC (permalink / raw)


Matthew Heaney wrote:
> ...
> > But I don't see what the type of the expression T'Access has to do with
> > it, so perhaps I'm misunderstanding your question.
> 
> Perhaps I stated my question incorrectly.
> 
> I do not care about the type of the expression T'Access.
> 
> I do care about the type of the object designated by the access object
> returned by T'Access.
> 
> I care because I want to call an operation that dispatches on the tag of
> the designated object:
> 
>   function Init (O : access T'Class) return Integer is
>   begin
>     return Do_Init (O);
>   end;
> 
> where Do_Init is a (private) primitive operation:
> 
>   function Do_Init (O : access T) return Integer;
> 
> For object O1 (of type T), I want T's Do_Init to be called.
> 
> For object O2 (of type NT), I want NT's Do_Init to be called.

You should probably be saying "with tag NT" rather than "of type NT."
For dispatching, the "type" (which is basically a compile-time concept)
is not particularly important, so long as it is class-wide.
What matters is the "tag" (which is fundamentally a run-time concept).

At least when talking to Bob and I ;-), it would behoove you
to reserve the term "type" for the compile-time view of the object,
and the term "tag" for the relevant run-time characteristics.

Another way to be clear is to say the "run-time type" or even
the "underlying run-time type" but that is pretty much what
"tag" means, so why not use that nice 3-letter word?

> 
> My compiler calls T's Do_Init for both O1 and O2.

Sounds like a bug, though I haven't personally analyzed the
situation in depth (it seems like Bob did...).

-Tuck
-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

* Re: meaning of "current instance"
  1999-11-12  0:00     ` tmoran
@ 1999-11-11  0:00       ` Matthew Heaney
  1999-11-12  0:00         ` tmoran
  0 siblings, 1 reply; 22+ messages in thread
From: Matthew Heaney @ 1999-11-11  0:00 UTC (permalink / raw)


In article <NcLW3.1031$dp.46853@typhoon-sf.snfc21.pbi.net> , 
tmoran@bix.com  wrote:

>  Given
> type T is record
>   I : Integer := T.I;
>   J : Integer := Random(RGen);
> A declaration of an object of type T will result in (unbounded)
> erroneous execution, but with T.I replaced by T.J it would be OK,
> resulting in T.I = T.J, right?


I don't know that you're trying to do here.  Your example doesn't refer
to the "current instance" of the type.

I don't think your program will even compile.

--
Science is, foremost, a method of interrogating reality: proposing
hypotheses that seem true and then testing them -- trying, almost
perversely, to negate them, elevating only the handful that survive to
the status of a theory. Creationism is a doctrine, whose adherents are
interested only in seeking out data that support it.

George Johnson, NY Times, 15 Aug 1999




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

* Re: meaning of "current instance"
  1999-11-12  0:00         ` tmoran
@ 1999-11-12  0:00           ` Matthew Heaney
  1999-11-12  0:00             ` tmoran
  1999-11-13  0:00             ` Robert A Duff
  1999-11-13  0:00           ` Nick Roberts
  1 sibling, 2 replies; 22+ messages in thread
From: Matthew Heaney @ 1999-11-12  0:00 UTC (permalink / raw)


In article <2hNW3.1742$dp.68215@typhoon-sf.snfc21.pbi.net> , 
tmoran@bix.com  wrote:

>>I don't think your program will even compile.
> Sorry, I tried to simplify more than was possible.
> This prints "1 1", as seems nice, but unexpected, with one compiler,
> but "5832148 1" with another compiler.  If X.J in function Init
> is replaced by X.I, then the two compilers give
> "39190036 1" and "0 1" respectively.

These results are consistent with referring to junk on the stack.


> I presume either of X.I or X.J in function Init is erroneous, right?

I'm not sure whether it's "erroneous" or a "bounded error."  Depend in
which component you refer to, your either referring to a component that
hasn't been initialized (not too bad) or to a component that hasn't been
elaborated (very bad).


> Is the Init function allowed only to reference previously initialized values
> (ie, X.I could be referenced by Init in "J : Integer := Init(T'access);"),

The version in the code I sent earlier didn't refer to any components;
it just returned a value.  That's what I recommend you do too.

That being said, the RM says record components get elaborated in the
order in which they're declared in the record (at least this is true for
tagged types).

So in your example above, it may be OK for Init to refer to component I,
because that component has definitely been elaborated.  But you're
really treading on thin ice here...


> or can
> it reference any values (seems impossible) or are there no references
> at all to initial values of the current instance that are legal?

If the record components are elaborated in their declaration order, you
may be able to take advantage of that.  But I don't know the exact
rules.


> package junk1 is
>   type T is private;
>   procedure dump(X : in T);
>   function Init(X : access T) return Integer;
>
> private
>   function Stepper return Integer;
>
>   type T  is record
>     I : Integer := Init(T'access);

Type T probably needs to be limited.  (Did this even compile?)


>     J : Integer := Stepper;
>   end record;
>
> end junk1;
>
> with ada.text_io;
> use  ada.text_io;
> package body junk1 is
>
>   Current : Integer := 0;
>
>   function Stepper return Integer is
>   begin
>     Current := Current+1;
>     return Current;
>   end Stepper;

You have to be careful about concurrency issues.  Suppose two different
tasks each declare an instance of T, and elaborate them at exactly the
same time.  The separate invocations of Stepper are likely to clobber
each other, unless you properly synchronize access to the global
variable Current (by wrapping it in a protected object).


>   function Init(X : access T) return Integer is
>   begin
>     return X.J;   -- or X.I
>   end Init;

But X.J hasn't even been elaborated yet, and X.I doesn't even have a
value.  So referring to either component is going to get you into
trouble.



>   procedure dump(X : in T) is
>   begin
>     put_line(Integer'image(X.I)
>              & Integer'image(X.J));
>   end dump;
>
> end junk1;
>
> with junk1;
> procedure junk2 is
>   x : junk1.T;
> begin
>   junk1.dump(x);
> end junk2;

"Junk" about sums it up.



--
The theory of evolution is quite rightly called the greatest unifying
theory in biology.  The diversity of organisms, similarities and
differences between kinds of organisms, patterns of distribution and
behavior, adaptation and interaction, all this was merely a bewildering
chaos of facts until given meaning by the evolutionary theory.

Populations, Species, and Evolution
Ernst Mayr




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

* Re: meaning of "current instance"
  1999-11-12  0:00           ` Matthew Heaney
@ 1999-11-12  0:00             ` tmoran
  1999-11-12  0:00               ` Matthew Heaney
  1999-11-13  0:00             ` Robert A Duff
  1 sibling, 1 reply; 22+ messages in thread
From: tmoran @ 1999-11-12  0:00 UTC (permalink / raw)


>So in your example above, it may be OK for Init to refer to component I,
>because that component has definitely been elaborated.  But you're
>really treading on thin ice here...
  Is it legal, or is it not?  The only mention of "current instance"
of a type that I see in the LRM index is to 8.6(17), which leaves me
guessing that the usual elaboration order rules apply, even though
things can be written that are normally un-writeable.
  If the order of components in a record declaration is changed, it
usually doesn't break things, or at least the compiler will point out
that you are using something before it exists.  A usage of "current
instance" presumably is a red flag to a maintenance programmer that
re-ordering is treading on thin ice.

>Type T probably needs to be limited.  (Did this even compile?)
 It compiled on two compilers, giving the results mentioned
previously.  Cohen's book only discusses limited T, but I don't see
anything in 8.6(17) that says limited, and these two compilers don't
require limited.

As I read LRM 8.6(17), T.I should be just as allowable as T'access,
but compilers don't seem to agree.  Where is this mentioned?

>You have to be careful about concurrency issues.
Not in a little "junk" program testing "current instance".  Stepper
was intended as a standin for anything with a side effect - random
numbers, IO, etc.  I hope anybody writing code that might be used
concurrently would use the appropriate protections, but I don't think
a little test program counts.




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

* Re: meaning of "current instance"
  1999-11-12  0:00             ` tmoran
@ 1999-11-12  0:00               ` Matthew Heaney
  0 siblings, 0 replies; 22+ messages in thread
From: Matthew Heaney @ 1999-11-12  0:00 UTC (permalink / raw)


In article <mG%W3.5997$dp.134843@typhoon-sf.snfc21.pbi.net> , 
tmoran@bix.com  wrote:

>   Is it legal, or is it not?

It doesn't matter if it's legal.  Don't do it.


> The only mention of "current instance"
> of a type that I see in the LRM index is to 8.6(17), which leaves me
> guessing that the usual elaboration order rules apply, even though
> things can be written that are normally un-writeable.

See 3.10.2 (24).


>   If the order of components in a record declaration is changed, it
> usually doesn't break things, or at least the compiler will point out
> that you are using something before it exists.  A usage of "current
> instance" presumably is a red flag to a maintenance programmer that
> re-ordering is treading on thin ice.

No.  Using the "current instance" of the type is *very* common.  It's
how we implement multiple inheritance in Ada95:

  type Digital_Clock (Timer : access Timer_Type) is
    new Limited_Controlled with record
      Hour_Observer : Hour_Observer_Type (Digital_Clock'Access);
      Min_Observer  : Min_Observer_Type (Digital_Clock'Access);
      Sec_Observer  : Sec_Observer_Type (Digital_Clock'Access);
    end record;


(Type Digital_Clock effectively has 4 parent types.)



--
Get the FAQs about evolution and creationism.

<http://www.talkorigins.org/origins/faqs.html>




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

* Re: meaning of "current instance"
  1999-11-11  0:00   ` Matthew Heaney
@ 1999-11-12  0:00     ` tmoran
  1999-11-11  0:00       ` Matthew Heaney
  0 siblings, 1 reply; 22+ messages in thread
From: tmoran @ 1999-11-12  0:00 UTC (permalink / raw)


 Given
type T is record
  I : Integer := T.I;
  J : Integer := Random(RGen);
A declaration of an object of type T will result in (unbounded)
erroneous execution, but with T.I replaced by T.J it would be OK,
resulting in T.I = T.J, right?




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

* Re: meaning of "current instance"
  1999-11-11  0:00       ` Matthew Heaney
@ 1999-11-12  0:00         ` tmoran
  1999-11-12  0:00           ` Matthew Heaney
  1999-11-13  0:00           ` Nick Roberts
  0 siblings, 2 replies; 22+ messages in thread
From: tmoran @ 1999-11-12  0:00 UTC (permalink / raw)


>I don't think your program will even compile.
Sorry, I tried to simplify more than was possible.
This prints "1 1", as seems nice, but unexpected, with one compiler,
but "5832148 1" with another compiler.  If X.J in function Init
is replaced by X.I, then the two compilers give
"39190036 1" and "0 1" respectively.  I presume either of X.I or X.J
in function Init is erroneous, right?  Is the Init function allowed
only to reference previously initialized values (ie, X.I could be
referenced by Init in "J : Integer := Init(T'access);"), or can
it reference any values (seems impossible) or are there no references
at all to initial values of the current instance that are legal?

package junk1 is
  type T is private;
  procedure dump(X : in T);
  function Init(X : access T) return Integer;

private
  function Stepper return Integer;

  type T  is record
    I : Integer := Init(T'access);
    J : Integer := Stepper;
  end record;

end junk1;

with ada.text_io;
use  ada.text_io;
package body junk1 is

  Current : Integer := 0;

  function Stepper return Integer is
  begin
    Current := Current+1;
    return Current;
  end Stepper;

  function Init(X : access T) return Integer is
  begin
    return X.J;   -- or X.I
  end Init;

  procedure dump(X : in T) is
  begin
    put_line(Integer'image(X.I)
             & Integer'image(X.J));
  end dump;

end junk1;

with junk1;
procedure junk2 is
  x : junk1.T;
begin
  junk1.dump(x);
end junk2;




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

* Re: meaning of "current instance"
  1999-11-12  0:00         ` tmoran
  1999-11-12  0:00           ` Matthew Heaney
@ 1999-11-13  0:00           ` Nick Roberts
  1999-11-13  0:00             ` Robert A Duff
  1 sibling, 1 reply; 22+ messages in thread
From: Nick Roberts @ 1999-11-13  0:00 UTC (permalink / raw)


I think the short answer to your question, Tom, is that the order in
which the components of a record type are initialised is not specified
by the Ada 95 standard, and so may vary from compiler to compiler. So if
you have T.J initialised to T.I, say, this may work on compiler A (which
initialises T.I first), and fail on compiler B (which initialises T.J
first). In this respect, your code is said to have an "incorrect order
dependency", which - in Ada 95 - is a bounded error.

One possible way to sidestep the problem is to make T.I a discriminant
(with a default).

   type T (I: Integer := Random(Gen)) is
      record
         J: Integer := I;
      end record;

This discriminant could be hidden by making the above declaration the
private completion of a public declaration of T with no discriminants.

But I'm intrigued as to what you are really trying to do (and why)!

-- 
Nick Roberts
Computer Consultant (UK)
http://www.callnetuk.com/home/nickroberts
http://www.adapower.com/lab/adaos






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

* Re: meaning of "current instance"
  1999-11-12  0:00           ` Matthew Heaney
  1999-11-12  0:00             ` tmoran
@ 1999-11-13  0:00             ` Robert A Duff
  1 sibling, 0 replies; 22+ messages in thread
From: Robert A Duff @ 1999-11-13  0:00 UTC (permalink / raw)


"Matthew Heaney" <matthew_heaney@acm.org> writes:

> 
> In article <2hNW3.1742$dp.68215@typhoon-sf.snfc21.pbi.net> , 
> tmoran@bix.com  wrote:
> 
> >>I don't think your program will even compile.
> > Sorry, I tried to simplify more than was possible.
> > This prints "1 1", as seems nice, but unexpected, with one compiler,
> > but "5832148 1" with another compiler.  If X.J in function Init
> > is replaced by X.I, then the two compilers give
> > "39190036 1" and "0 1" respectively.

I think record components can be initialized in an arbitrary order (ie
whatever order the compiler chooses).  So if the init of one component
refers to the value of another, you might be referring to an
uninitialized variable, which is a bounded error -- no matter which
order you declare the components.

- Bob




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

* Re: meaning of "current instance"
  1999-11-13  0:00           ` Nick Roberts
@ 1999-11-13  0:00             ` Robert A Duff
  1999-11-14  0:00               ` tmoran
  0 siblings, 1 reply; 22+ messages in thread
From: Robert A Duff @ 1999-11-13  0:00 UTC (permalink / raw)


Nick Roberts <nickroberts@callnetuk.com> writes:

> But I'm intrigued as to what you are really trying to do (and why)!

I think the "why" is simply, "try to understand all the ramifications of
referring to the current instance of a type".

- Bob




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

* Re: meaning of "current instance"
  1999-11-14  0:00               ` tmoran
@ 1999-11-13  0:00                 ` Matthew Heaney
  1999-11-15  0:00                   ` John English
  0 siblings, 1 reply; 22+ messages in thread
From: Matthew Heaney @ 1999-11-13  0:00 UTC (permalink / raw)


In article <zaoX3.10259$dp.270354@typhoon-sf.snfc21.pbi.net> , 
tmoran@bix.com  wrote:

>   Is there anything you can do with "current instance" that couldn't
> be done (and perhaps more safely) with Initialize on a Controlled type?
> I grant that ":=T'access;" is simpler, but it could be done with
> Initialize.


My original motivation for using

  type RT is
    tagged limited record
      I : Integer := Init (RT'Access);
    end record;

instead of

  type RT is
    new Limited_Controlled with record
      I : Integer;
    end record;

  procedure Initialize (O : in out RT);


was precisely to avoid having to use a controlled type.  Controlled
types are in general less efficient than non-controlled types.


--
Get the FAQs about evolution and creationism.

<http://www.talkorigins.org/origins/faqs.html>




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

* Re: meaning of "current instance"
  1999-11-13  0:00             ` Robert A Duff
@ 1999-11-14  0:00               ` tmoran
  1999-11-13  0:00                 ` Matthew Heaney
  0 siblings, 1 reply; 22+ messages in thread
From: tmoran @ 1999-11-14  0:00 UTC (permalink / raw)


>I think the "why" is simply, "try to understand all the ramifications
>of referring to the current instance of a type".
Yes.
  Is there anything you can do with "current instance" that couldn't
be done (and perhaps more safely) with Initialize on a Controlled type?
I grant that ":=T'access;" is simpler, but it could be done with
Initialize.




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

* Re: meaning of "current instance"
  1999-11-11  0:00 ` Robert A Duff
  1999-11-11  0:00   ` Matthew Heaney
@ 1999-11-15  0:00   ` Tucker Taft
  1999-11-15  0:00     ` tmoran
  1 sibling, 1 reply; 22+ messages in thread
From: Tucker Taft @ 1999-11-15  0:00 UTC (permalink / raw)


Robert A Duff wrote:
> 
> "Matthew Heaney" <matthew_heaney@acm.org> writes:
> 
> > I have some code below that I thought had a bug (um, I mean "error"),
> 
> ;-)
> 
> > but now I'm not so sure.
> >
> > Suppose I have this:
> >
> >   type T is tagged private;
> > ...
> >   function Init (O : access T'Class)
> >
> >   type T is
> >     tagged record
> >       I : Integer := Init (T'Access);
> >     end record;
> 
> I think you want T to be limited, or else use 'Unchecked_Access.

This is illegal, even if you use 'Unchecked_Access, unless T is limited,
because only if T is limited is the "view from the inside" aliased
(see 3.10(9) and 3.10.2(24)).  Just making it tagged is not enough.

> ...
-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

* Re: meaning of "current instance"
  1999-11-15  0:00   ` Tucker Taft
@ 1999-11-15  0:00     ` tmoran
  1999-11-15  0:00       ` Tucker Taft
  0 siblings, 1 reply; 22+ messages in thread
From: tmoran @ 1999-11-15  0:00 UTC (permalink / raw)


>This is illegal, even if you use 'Unchecked_Access, unless T is limited,
Two out of the three compilers on my machine accept:
  package junk1 is
     type T is tagged private;
     function Init (O : access T'Class) return integer;
  private
     type T is
       tagged record
         I : Integer := Init (T'Access);
       end record;
  end junk1;
with no "limited".  I take it they are in error?




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

* Re: meaning of "current instance"
  1999-11-15  0:00     ` tmoran
@ 1999-11-15  0:00       ` Tucker Taft
  0 siblings, 0 replies; 22+ messages in thread
From: Tucker Taft @ 1999-11-15  0:00 UTC (permalink / raw)


tmoran@bix.com wrote:
> 
> >This is illegal, even if you use 'Unchecked_Access, unless T is limited,
> Two out of the three compilers on my machine accept:
>   package junk1 is
>      type T is tagged private;
>      function Init (O : access T'Class) return integer;
>   private
>      type T is
>        tagged record
>          I : Integer := Init (T'Access);
>        end record;
>   end junk1;
> with no "limited".  I take it they are in error?

Yes.  Even my favorite front end missed this one (but it won't for
long ;-).

-Tuck
-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

* Re: meaning of "current instance"
  1999-11-13  0:00                 ` Matthew Heaney
@ 1999-11-15  0:00                   ` John English
  1999-11-15  0:00                     ` Matthew Heaney
  0 siblings, 1 reply; 22+ messages in thread
From: John English @ 1999-11-15  0:00 UTC (permalink / raw)


Matthew Heaney wrote:
> Controlled
> types are in general less efficient than non-controlled types.

But code that works is generally more efficient that code that
doesn't... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: meaning of "current instance"
  1999-11-15  0:00                   ` John English
@ 1999-11-15  0:00                     ` Matthew Heaney
  0 siblings, 0 replies; 22+ messages in thread
From: Matthew Heaney @ 1999-11-15  0:00 UTC (permalink / raw)


In article <382FE906.19371521@bton.ac.uk> , John English <je@bton.ac.uk>  
wrote:

> Matthew Heaney wrote:
>> Controlled
>> types are in general less efficient than non-controlled types.
>
> But code that works is generally more efficient that code that
> doesn't... :-)

You're quoting me out of context.  Let's try again:

My original motivation for using

  type RT is
    tagged limited record
      I : Integer := Init (RT'Access);
    end record;

instead of

  type RT is
    new Limited_Controlled with record
      I : Integer;
    end record;

  procedure Initialize (O : in out RT);

is because the former is more efficient than the latter.



--
The theory of evolution is quite rightly called the greatest unifying
theory in biology.  The diversity of organisms, similarities and
differences between kinds of organisms, patterns of distribution and
behavior, adaptation and interaction, all this was merely a bewildering
chaos of facts until given meaning by the evolutionary theory.

Populations, Species, and Evolution
Ernst Mayr




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

end of thread, other threads:[~1999-11-15  0:00 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-11  0:00 meaning of "current instance" Matthew Heaney
1999-11-11  0:00 ` Robert A Duff
1999-11-11  0:00   ` Matthew Heaney
1999-11-11  0:00     ` Tucker Taft
1999-11-15  0:00   ` Tucker Taft
1999-11-15  0:00     ` tmoran
1999-11-15  0:00       ` Tucker Taft
1999-11-11  0:00 ` tmoran
1999-11-11  0:00   ` Matthew Heaney
1999-11-12  0:00     ` tmoran
1999-11-11  0:00       ` Matthew Heaney
1999-11-12  0:00         ` tmoran
1999-11-12  0:00           ` Matthew Heaney
1999-11-12  0:00             ` tmoran
1999-11-12  0:00               ` Matthew Heaney
1999-11-13  0:00             ` Robert A Duff
1999-11-13  0:00           ` Nick Roberts
1999-11-13  0:00             ` Robert A Duff
1999-11-14  0:00               ` tmoran
1999-11-13  0:00                 ` Matthew Heaney
1999-11-15  0:00                   ` John English
1999-11-15  0:00                     ` Matthew Heaney

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