comp.lang.ada
 help / color / mirror / Atom feed
* unconstrained array question
@ 2003-11-22 17:39 shoko
  2003-11-22 18:11 ` Marius Amado Alves
  0 siblings, 1 reply; 10+ messages in thread
From: shoko @ 2003-11-22 17:39 UTC (permalink / raw)


hi
I have few question to ask:
1.i have a Character array
can i print the all array wich is a string at once or do i have to
pront each item?
2.i have unconstrained array of Character i want to insert a string
when the program runs with the function get for example
how can i do it the compiler telling me i need to define the array
first:

------------------------------------------------------
type Arr is Array(integer range<>) of Character ;
type n_array_Ptr is access Arr;
n:n_array_Ptr ;
s:string(1..100);
begin
n:= new Arr'(Get(s));
-----------------------------------------



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

* Re: unconstrained array question
  2003-11-22 17:39 shoko
@ 2003-11-22 18:11 ` Marius Amado Alves
  2003-11-23  7:12   ` shoko
  0 siblings, 1 reply; 10+ messages in thread
From: Marius Amado Alves @ 2003-11-22 18:11 UTC (permalink / raw)
  To: comp.lang.ada

On Sat, 2003-11-22 at 17:39, shoko wrote:
> 1.i have a Character array
> can i print the all array wich is a string at once or do i have to
> pront each item?

You can convert to String (because String is defined exactly as an array
of Character), and then use operations of String e.g.

Ada.Text_IO.Put (String (Your_Array_Of_Character));

> 2.i have unconstrained array of Character i want to insert a string
> when the program runs with the function get for example
> how can i do it the compiler telling me i need to define the array
> first:...

Please rewrite this is correct English and I might be able to understand
it and help you.





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

* Re: unconstrained array question
  2003-11-22 18:11 ` Marius Amado Alves
@ 2003-11-23  7:12   ` shoko
  2003-11-23  8:42     ` tmoran
  2003-11-23 12:16     ` Marius Amado Alves
  0 siblings, 2 replies; 10+ messages in thread
From: shoko @ 2003-11-23  7:12 UTC (permalink / raw)


this what i am trying to do 
the compiler say:
"expected type arr defined"

----------------------------------------------------
procedure test1
type Arr is Array(Integer range<>) of Character; 
type n_array_Ptr is access Arr; 
n:n_array_Ptr ; 
Input_Line : String (1..256);
last : natural; 

begin
   Get_LIne(Input_Line,LAST);
   n:=new Arr'(Input_Line);
end test1;
-----------------------------------------------------------
what is wrong in this code?



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

* Re: unconstrained array question
  2003-11-23  7:12   ` shoko
@ 2003-11-23  8:42     ` tmoran
  2003-11-23 12:16     ` Marius Amado Alves
  1 sibling, 0 replies; 10+ messages in thread
From: tmoran @ 2003-11-23  8:42 UTC (permalink / raw)


>type Arr is Array(Integer range<>) of Character;
>Input_Line : String (1..256);
  So Input_Line is of type String, and Arr is a different type.
>  n:=new Arr'(Input_Line);
  "Arr'()" says "the thing inside the parens is of type Arr".  But in fact
the thing inside the parens is not an Arr, but is a String.  So the
compiler quite rightly points out that it expected something of type Arr.
  Perhaps what you want is
subtype Arr is String;
which, since there are no special constraints, would in effect mean
that "Arr" is a synonym for "String".  Of course even easier is just
to forget about "Arr" entirely, and just use "String" where you now
have "Arr".

>  Get_LIne(Input_Line,LAST);
>  n:=new Arr'(Input_Line);
  If you want "n" to point to just the data read, and not the whole
256 characters, you want
   n:=new Arr'(Input_Line(Input_Line'first .. LAST));



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

* Re: unconstrained array question
  2003-11-23  7:12   ` shoko
  2003-11-23  8:42     ` tmoran
@ 2003-11-23 12:16     ` Marius Amado Alves
  2003-11-23 18:03       ` shoko
  1 sibling, 1 reply; 10+ messages in thread
From: Marius Amado Alves @ 2003-11-23 12:16 UTC (permalink / raw)
  To: comp.lang.ada

On Sun, 2003-11-23 at 07:12, shoko wrote:
> procedure test1
> type Arr is Array(Integer range<>) of Character; ...

It's missing "is" after "procedure test1".




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

* Re: unconstrained array question
  2003-11-23 12:16     ` Marius Amado Alves
@ 2003-11-23 18:03       ` shoko
  2003-11-23 20:16         ` Marius Amado Alves
  0 siblings, 1 reply; 10+ messages in thread
From: shoko @ 2003-11-23 18:03 UTC (permalink / raw)


thanks a lot 


-------------------------
function  Get_Text    (Control : Multiline_Type;
                         Line    : Natural := 0)   return String  is abstract;
-----------------------------------------
the function Get_text(Value) returns string
i am trying to 
n:=new Arr'(Get_text(Value)); 

and i get ARR defined...
how do i convert it into a string since it is already returns abstract string

thanks a lot for your help
i am really stuck



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

* Re: unconstrained array question
  2003-11-23 18:03       ` shoko
@ 2003-11-23 20:16         ` Marius Amado Alves
  2003-11-24 17:40           ` shoko
  0 siblings, 1 reply; 10+ messages in thread
From: Marius Amado Alves @ 2003-11-23 20:16 UTC (permalink / raw)
  To: comp.lang.ada

Shoko, try to write correct English and use conventional Ada style. It
will improve your chances of getting an answer in this list.

You need to convert String to your character array where the latter is
expected:

  N := new Arr' (Arr (Input_Line));

But avoid using pointers. You can use declare blocks:

  declare
    A : Arr := Arr (Input_Line);
  begin
    ...
  end;





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

* Re: unconstrained array question
  2003-11-23 20:16         ` Marius Amado Alves
@ 2003-11-24 17:40           ` shoko
  2003-11-24 18:16             ` Jeffrey Carter
  0 siblings, 1 reply; 10+ messages in thread
From: shoko @ 2003-11-24 17:40 UTC (permalink / raw)


Marius Amado Alves <amado.alves@netcabo.pt> wrote in message news:<mailman.46.1069618607.3110.comp.lang.ada@ada-france.org>...
> Shoko, try to write correct English and use conventional Ada style. It
> will improve your chances of getting an answer in this list.
> 
> You need to convert String to your character array where the latter is
> expected:
> 
>   N := new Arr' (Arr (Input_Line));
> 
> But avoid using pointers. You can use declare blocks:
> 
>   declare
>     A : Arr := Arr (Input_Line);
>   begin
>     ...
>   end;

I am sorry for my bad english
I really need your help:
My question is:
--------------------------------------------------
type Arr is Array(integer range<>) of Character;

function  Get_Text    (Control : Multiline_Type;
                         Line    : Natural := 0)   return String  is abstract;
----------------------------------------------------
Now all i want to do is:

declare
  a : Arr := Arr(Get_Text(value)); 
begin
  something;
end;
--------------------------------------

How can i convert abstract String to my ARR type?   
(Character array).

thanks again.



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

* Re: unconstrained array question
@ 2003-11-24 18:11 amado.alves
  0 siblings, 0 replies; 10+ messages in thread
From: amado.alves @ 2003-11-24 18:11 UTC (permalink / raw)
  To: comp.lang.ada

First, you cannot call an abstract function.

Correct that, either by making the function concrete (elide "abstract" and provide a body), or by deriving from the controlling type and providing a (concrete) function for the derived type.

Then, to convert between any two compatible types you just write

  Target_Type (Object_Of_Source_Type)



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

* Re: unconstrained array question
  2003-11-24 17:40           ` shoko
@ 2003-11-24 18:16             ` Jeffrey Carter
  0 siblings, 0 replies; 10+ messages in thread
From: Jeffrey Carter @ 2003-11-24 18:16 UTC (permalink / raw)


shoko wrote:

> type Arr is Array(integer range<>) of Character;
> 
> function  Get_Text (Control : Multiline_Type;
>                     Line    : Natural := 0) return String is abstract;
> ----------------------------------------------------
> Now all i want to do is:
> 
> declare
>   a : Arr := Arr(Get_Text(value)); 
> begin
>   something;
> end;
> --------------------------------------
> 
> How can i convert abstract String to my ARR type?

You seem to have some confusion about "is abstract". Your understanding 
of basic Ada concepts seems to be poor. You should really work through 
some of the tutorials on www.adapower.com or an Ada textbook before 
trying to do this kind of stuff.

"is abstract" refers to the subprogram, not to String. An abstract 
subprogram cannot be called. You'll have to provide a non-abstract 
version of Get_Text.

-- 
Jeff Carter
"If you think you got a nasty taunting this time,
you ain't heard nothing yet!"
Monty Python and the Holy Grail
23




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

end of thread, other threads:[~2003-11-24 18:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-24 18:11 unconstrained array question amado.alves
  -- strict thread matches above, loose matches on Subject: below --
2003-11-22 17:39 shoko
2003-11-22 18:11 ` Marius Amado Alves
2003-11-23  7:12   ` shoko
2003-11-23  8:42     ` tmoran
2003-11-23 12:16     ` Marius Amado Alves
2003-11-23 18:03       ` shoko
2003-11-23 20:16         ` Marius Amado Alves
2003-11-24 17:40           ` shoko
2003-11-24 18:16             ` Jeffrey Carter

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