comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Defining a binary operator between function access types: Is it possible?
Date: Thu, 16 Oct 2008 07:29:00 -0700 (PDT)
Date: 2008-10-16T07:29:00-07:00	[thread overview]
Message-ID: <e027c16b-3da9-4c85-a20d-f1468ac2649d@b31g2000prf.googlegroups.com> (raw)
In-Reply-To: fed9902a-28f0-4e70-a427-4773b20aae47@p49g2000hsd.googlegroups.com

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




  parent reply	other threads:[~2008-10-16 14:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-16 13:34 Defining a binary operator between function access types: Is it possible? soychangoman
2008-10-16 14:26 ` Dmitry A. Kazakov
2008-10-16 14:29 ` Adam Beneschan [this message]
2008-10-16 22:18   ` Robert A Duff
2008-10-16 15:14 ` Jacob Sparre Andersen
2008-10-17  7:10 ` Defining a binary operator between function access types: Is it anon
2008-10-21  6:46 ` Defining a binary operator between function access types: Is it possible? Ivan Levashew
2008-10-21 13:17   ` soychangoman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox