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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news.glorb.com!wn11feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Defining a binary operator between function access types: Is it Reply-To: no to spamers (No@email.given.org) References: X-Newsreader: IBM NewsReader/2 2.0 Message-ID: <2UWJk.75523$Mh5.16851@bgtnsc04-news.ops.worldnet.att.net> Date: Fri, 17 Oct 2008 07:10:54 GMT NNTP-Posting-Host: 12.64.6.156 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1224227454 12.64.6.156 (Fri, 17 Oct 2008 07:10:54 GMT) NNTP-Posting-Date: Fri, 17 Oct 2008 07:10:54 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:2431 Date: 2008-10-17T07:10:54+00:00 List-Id: -- -- File b.adb -- -- Even though Adam is correct, the following program works using -- pointers and assigning the function dynamically. -- Also, using Ada 95 specs -- with Ada.Text_IO ; use Ada.Text_IO ; with Ada.Float_Text_IO ; use Ada.Float_Text_IO ; procedure b is type function_access is access function ( x : Float ) return Float ; -- -- Library routines -- function square ( x : Float ) return Float is begin return x ** 2 ; end square ; function cubic ( x : Float ) return Float is begin return x ** 3 ; end cubic ; function f3 ( x : Float ) return Float ; -- -- dynamically assignable -- f1_access : function_access := null ; f2_access : function_access := null ; -- -- lock access to function f3 only -- f3_access : constant function_access := f3'access ; -- -- Dynamic useable function -- function f3 ( x : Float ) return Float is Function_Error : exception ; begin -- f3 if f1_access /= null and then f2_access /= null then return f1_access.all ( x ) + f2_access.all ( x ) ; end if ; raise Function_Error ; end f3 ; begin -- Initialize functions variables f1_access := square'Access ; f2_access := cubic'Access ; -- f3_acc := f1_acc + f2_acc ; -- the idea is that f3_acc.all ( x ) => square ( x ) + cubic ( x ) Put ( "1.0 := " ) ; Put ( f3_access.all ( 1.0 ) ) ; New_Line ; Put ( "Perform 'square ( x ) + cubic ( x )' => " ) ; Put ( "where x => 2.0 gives " ) ; Put ( f3_access.all ( 2.0 ) ) ; New_Line ; -- Reassign f2 to a square f2_access := square'Access ; Put ( "Perform 'square ( x ) + square ( x )' => " ) ; Put ( "where x => 2.0 gives " ) ; Put ( f3_access.all ( 2.0 ) ) ; New_Line ; end b ; In , soychangoman@gmail.com writes: >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 :=3D square'Access; > f2_acc :=3D cubic'Access; > > -- f3_acc :=3D f1_acc + f2_acc; >-- the idea is that ' f3_acc.all ( x ) ' and ' square (x) + cubic(x) >' are equivalent > >end operating_on_access; >----- > >Thanks in advance > >Mat=EDas Niklison