From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3ce28d0565014394 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!j2g2000vbo.googlegroups.com!not-for-mail From: Phil Thornley Newsgroups: comp.lang.ada Subject: Re: Spark sorting algorithm with generic input data Date: Sun, 19 Sep 2010 10:30:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0ee44942-9bca-414c-907d-f95913d34706@j2g2000vbo.googlegroups.com> References: <2a161cb7-87a8-4ba1-8adc-bb3eff322fed@e20g2000vbn.googlegroups.com> NNTP-Posting-Host: 80.177.171.182 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1284917435 21290 127.0.0.1 (19 Sep 2010 17:30:35 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 19 Sep 2010 17:30:35 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j2g2000vbo.googlegroups.com; posting-host=80.177.171.182; posting-account=Fz1-yAoAAACc1SDCr-Py2qBj8xQ-qC2q User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14164 Date: 2010-09-19T10:30:34-07:00 List-Id: On 19 Sep, 12:14, chuck wrote: > hi folks, > at the moment i become acquainted with ada as well as spark language. > i implemented a bubble sort algorithm with generic input values in ada > and tried a transferring to spark. implementing and proofing the > algorithm in spark was not a problem at all, but i'm not sure how to > handle generic input values. To my knowledge the concept of generics > is not available in spark, therefore i would appreciate any valuable > comments on how to make use of data abstraction. You are correct that SPARK does not support generics - there have been some suggestions that they are actively in development but no dates have been given. When it comes to using a SPARK component (such as a sort operation) or data structure (such as a list or tree) with different data types, there are two basic approaches: 1. Write the code so that it makes the minimum possible assumptions about the data type - then changing the data type should be as simple as possible, but this does require a change to the code of the component (even if the only change is the declaration of the element type). 2. If the identity of each element of the type can be encapsulated in, say, an integer (eg if there is a 'key' value that can be calculated for each element) then write the SPARK code using an Integer element and only pass the key values to the operations. Use your own 'pool' (ie array of elements) to store the actual elements, then the outputs of the operations tell you how to access that array. For example, using the second approach for a sort procedure, store values in the key array and the element array in parallel, then the sorted key array tells you the sequence of elements in the data array. Or, for a list or tree, every operation that stores or reads a data element actually calls the relevant operation with the key value for the element, and the operation has an 'out' parameter that is the index of that key within the structure - so this tells you which element of your actual data array to read/write. (This method has the restriction that no key element can move within the data structure once stored in there.) Cheers, Phil