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-Thread: 103376,bd50112c03f1f521 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!postnews.google.com!b31g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Defining a binary operator between function access types: Is it possible? Date: Thu, 16 Oct 2008 07:29:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1224167341 17745 127.0.0.1 (16 Oct 2008 14:29:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 16 Oct 2008 14:29:01 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b31g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2423 Date: 2008-10-16T07:29:00-07:00 List-Id: On Oct 16, 6:34 am, soychango...@gmail.com wrote: > I'm trying to define a binary operator between function access types > that returns the access to the function that is the binary operator > acting on both functions. Let's put it a bit clearer: > > ----------- > procedure operating_on_access is > > type function_access is access function ( x : Real) return Real; > > function "+" (f1 : function_access; f2 : function_access) return > function_access is > begin > -- The question is what to put here > return null; > end "+" > > funcion square (x : Real) return Real is > begin > return x**2; > end square; > > funcion cubic (x : Real) return Real is > begin > return x**3; > end square; > > f1_acc, f2_acc, f3_acc : function_access; > > begin > > f1_acc := square'Access; > f2_acc := cubic'Access; > > -- f3_acc := f1_acc + f2_acc; > -- the idea is that ' f3_acc.all ( x ) ' and ' square (x) + cubic(x) > ' are equivalent > > end operating_on_access; You must be used to Lisp or something, right? This isn't going to work at all. A Function_Access is basically a pointer to a function that has already been written. You're asking the program to build a *new* function on the fly and return a pointer to that. That pretty much works only in interpreted languages, and Ada isn't one of those. If you really need something like this, you'll have to build your own interpreter somehow. It could be a very simple one depending on what your needs are. -- Adam