LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-28-2014, 10:31 AM   #1
Mario Blunk
Member
 
Registered: Dec 2008
Location: Wild Eastern Germany
Distribution: OpenSuse Tumbleweed
Posts: 131

Rep: Reputation: 21
ADA 2005: sorting constrained array


Does anyone have an example of how to sort a constrained array in ADA (2005) ?

I found an example for an unconstrained array here

http://rosettacode.org/wiki/Sort_an_...structures#Ada

But I could not manage to adopt it to a constrained array as shown in the code below. GNAT says regarding the line marked below:
"guv.adb:744:55: index types of actual do not match those of formal "Array_Type"
guv.adb:744:55: instantiation abandoned
gnatmake: "guv.adb" compilation error

Code:
procedure sort_bookings 
	( takings_to_sort : takings_sized) is -- a constrained array gets passed

	function "<" (L, R : entry_taking) return Boolean is
	 begin
	  return L.date < R.date;
	 end "<";
				
	procedure Put_Line (C : entry_taking) is
	 begin
	  Put_Line (C.date & " " & to_string(C.subject));
	end Put_Line;
				
	procedure Sort is new Ada.Containers.Generic_Constrained_Array_Sort (
		index_type => natural, 
		element_type => entry_taking, 
   	        array_type => takings_sized -- <-- affected line
                );

	begin
	--Sort (expenses);
	-- for I in 1..expenses'last loop
	-- 	Put_Line (expenses (I));
	-- end loop;
	end sort_bookings;
Thanks for your help !!!
 
Old 02-10-2014, 05:10 PM   #2
muggabug
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Rep: Reputation: Disabled
Ada generics are way over my head, but I think that your only problem is that you have defined the wrong type or bounds for the array index somewhere.

Running a little test with different index types in definition and declaration for a generic function, causes a similar error message from gnat-ada95:

h.adb:13:42: index types of actual do not match those of formal "arT"
h.adb:13:42: instantiation abandoned

Code used:
Code:
function h return integer is
   subtype r is natural range 1..20;
   generic
      type item is (<>);
      type arT is array(r) of item;
      function print(x:in arT) return string;
      function print(x:arT) return string is
      begin
         return "nothing";
      end print;
      type tmp is array(natural range 1..21) of character;
      function f is new print (character,tmp);
begin
   return 0;
end h;
Looks like this is it


--------
(If anyone has a clue about this, why, btw, can't I just use:
type arT is array(natural range 1..20) of item;
This gives me an error
(error is p.adb:5:25: only a subtype mark is allowed in a formal)
but would be much simpler, just like substituting the type definition for tmp in the "..new print.." declaration somewhere.)

Last edited by muggabug; 02-10-2014 at 05:12 PM. Reason: code
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I buffer textinput from file in Ada (Ada newbie) muggabug Programming 3 11-03-2011 01:28 AM
ADA Development tools in Linux for ADA 83 and ADA95 ehudnatan Linux - Software 2 05-11-2011 09:58 AM
two dimensional array sorting in C/C++ George2 Programming 10 11-19-2006 08:29 PM
Perl Array Sorting craig467 Programming 8 10-02-2006 05:32 AM
I need help sorting an array in PHP! socceroos Programming 14 05-09-2006 02:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration