comp.lang.ada
 help / color / mirror / Atom feed
* Ada puzzle
@ 1989-09-07 15:15 Glenn Bruns
  1989-09-07 17:02 ` hagerp
  0 siblings, 1 reply; 2+ messages in thread
From: Glenn Bruns @ 1989-09-07 15:15 UTC (permalink / raw)


Given the text for an arbitrary Ada procedure, and assuming that all
variables within the procedure are either local variables of the
procedure or parameters of the procedure, is it possible to make a
copy of any variable within the procedure?  By "make a copy", I mean
to create a new variable with the same value as the original variable
that can be used in exactly the same way as the original variable.
Note that no type information is available except as found in the
text of the procedure.

If the variable is a local variable of the procedure, the problem
does not seem too hard.  Consider the following procedure:

    procedure FOO is
	X : INT_ARRAY(1 .. 3) := (4, 5, 6);
	I : INTEGER;
    begin
	I := X(1);  
    end FOO;

This version of FOO contains code to copy X to new variable Y:

    procedure FOO is
	X : INT_ARRAY(1 .. 3) := (4, 5, 6);
	I : INTEGER;
	Y : INT_ARRAY(1 .. 3);
    begin
	Y := X;
	I := Y(1); 
    end FOO;

But what if the variable to be copied is a parameter of the procedure?

    procedure BAR(X : in SOME_TYPE; Z : out SOME_TYPE) is
    begin
	Z := X;
    end BAR;

It does not seem that I know enough about the type of X here to be
able to create a new variable Y that is a copy of X.  The naive
solution is:

    procedure BAR(X : in SOME_TYPE; Z : out SOME_TYPE) is 
	Y : SOME_TYPE;
    begin
	Y := X;
        Z := Y;	
    end BAR;

But this doesn't work when, for example, SOME_TYPE is an
unconstrained array type.  There are ways to copy X if SOME_TYPE _is_
an unconstrained array type, but these techniques don't work for all
types.


-- 
Glenn Bruns 
MCC, Software Technology Program
arpa: bruns@mcc.com    
uucp: {seismo,harvard,gatech,pyramid}!ut-sally!im4u!milano!bruns

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

* Re: Ada puzzle
  1989-09-07 15:15 Ada puzzle Glenn Bruns
@ 1989-09-07 17:02 ` hagerp
  0 siblings, 0 replies; 2+ messages in thread
From: hagerp @ 1989-09-07 17:02 UTC (permalink / raw)



How about something like:

	generic
	    type X is (<>);
	procedure Foo (Param : X) is
	    Y : X;
	begin
	    Y := Param;
	end Foo;

Is this what you had in mind?

--paul hager

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

end of thread, other threads:[~1989-09-07 17:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-09-07 15:15 Ada puzzle Glenn Bruns
1989-09-07 17:02 ` hagerp

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