comp.lang.ada
 help / color / mirror / Atom feed
From: soychangoman@gmail.com
Subject: Re: Defining a binary operator between function access types: Is it possible?
Date: Tue, 21 Oct 2008 06:17:39 -0700 (PDT)
Date: 2008-10-21T06:17:39-07:00	[thread overview]
Message-ID: <a1f7fcba-a25d-42e6-af8d-91c59596dbbd@y71g2000hsa.googlegroups.com> (raw)
In-Reply-To: b1fadb29-118f-4f6f-934e-834927eb7708@26g2000hsk.googlegroups.com

Well, first of all thanks for all the responses. I finally found a
solution that makes me happy and I was able to implement.

Here's what I did:

I defined:
--------------
   type Symbols_Enumeration is ('+', '-','*', '/', Power,
                                analytic);
   package Symbols is new Stacks(Symbols_Enumeration);

   type Analytic_Function_Access is access function ( x : Real'Base)
return Real'Base;
   package Analytics is new Stacks(Analytic_Function_Access);

   package Real_Numbers is new Stacks(Real);

   type My_Function is record
      Symbols_Stack      : Symbols.Stack;

      Analytics_Stack    : Analytics.Stack;
      Real_Numbers_Stack : Real_Numbers.Stack;

   end record;
-------------
Where the package Stacks is a generic Stack manager.

The idea is to use the calculator notation, I mean, if I do:
------
f1,f2,f : My_Function;

--some kind of initialization to f1 and f2 where I say that
--f1.Symbols_Stack   f1.Analytic_Stack
--|analytic|         |f1_acc|
-- the same for f2

f := f1 + f2;
------
then f will have
f.Symbols_Stack   f.Analytic_Stack
|+       |         |f1_acc|
|analytic|         |f2_acc|
|analytic|

If I have a * or even a ** the compiler takes care of precedence of
the operators, all i have to take care is to put everithing on the
stack.
example:
f := (f1+f2) * (f3+f4);

f.Symbols_Stack   f.Analytic_Stack
|*       |
|+       |        |f1_acc|
|analytic|        |f2_acc|
|analytic|        |f3_acc|
|+       |        |f4_acc|
|analytic|
|analytic|

If I want to do this
f:= f1 * 2.0;

then

f.Symbols_Stack   f.Analytic_Stack    f.Real_Numbers_Stack
|*          |
|analytic   |
|Real_Number|        |f1_acc|         |2.0  |

When I want to get f(x) I just do like the calculator. I Get symbol by
Symbol in the Symbols_Stack and when I find something that is not a
operator (like a 'Real_Number') I look for it in the corresponding
stack (f.Real_Numbers_Stack).

I didn't post the source code becouse it's a little long, but if
anyone has curiosity just mail me.
About Ivan Levashew's Post... well I realy didn't quite understood
yet, but I think that if the package is used adequately it won't blow
my stack away, even if it's used for big calculations, am I right?

Thanks everyone again =)

Saludos

Matías Niklison



      reply	other threads:[~2008-10-21 13:17 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
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 [this message]
replies disabled

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