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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,db9fec59d36b64c1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-08-15 06:01:31 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news-out.cwix.com!newsfeed.cwix.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Re: Indexed list Date: Fri, 15 Aug 2003 13:01:31 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <3922594d.0308150346.65657e94@posting.google.com> NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1060952491 3542 217.17.192.37 (15 Aug 2003 13:01:31 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Fri, 15 Aug 2003 13:01:31 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:41505 Date: 2003-08-15T13:01:31+00:00 List-Id: * Alex Crivat wrote: > Is there a way of doing this in Ada using operators or should I use a > custom function; You should use a custom function, but if you really need this, there is a trick. The '()' syntax is used in two contexts. First as an array subscript, as you like to recognise it. And second as a function call. Using access variables to function calls the same syntax applies. So you have to set a variable either to an array or a function. Because a variable can't be of type function, use access to function instead. You only need a slight modification to set the initial value. I'll provide you the short and the generic solution: ------------------------------------------------------------------------ with Ada.Text_IO; procedure t is function Get(i : Natural) return Natural is begin return i + 4; end Get; type List is access function (i : Natural) return Natural; a : Natural; f : List := Get'Access; begin a := f(3); Ada.Text_IO.Put_Line("a =" & Natural'Image(a)); end t; ------------------------------------------------------------------------ with Ada.Text_IO; procedure t is generic type Item (<>) is limited private; type Offset (<>) is limited private; with function Get(i : Offset) return Item is <>; package GenList is type List is access function (i : Offset) return Item; Current : constant List; private function MyGet (i : Offset) return Item renames Get; Current : constant List := MyGet'Access; end GenList; function Get(i : Natural) return Natural is begin return i + 4; end Get; package MyList is new GenList(Natural, Natural); use MyList; a : Natural; f : List := Current; begin a := f(3); Ada.Text_IO.Put_Line("a =" & Natural'Image(a)); end t; ------------------------------------------------------------------------ Have fun.