comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcqada95@earthlink.net>
Subject: Re: Function pointer in Ada?
Date: Thu, 16 May 2002 11:37:04 GMT
Date: 2002-05-16T11:37:04+00:00	[thread overview]
Message-ID: <3CE39A2D.2C75435A@earthlink.net> (raw)
In-Reply-To: 3ce2e175.0@news.unibw-muenchen.de

Kai Schuelke wrote:
> 
> I want a program that can solve every mathematical function (e.g.: z = 2*x +
> sin(x)) for any value (e.g. x=4). It is enough to work with one mathematical
> function at a time. My spec looks like:
> 
> -- Spec
> package math is
>     procedure Set_Function(Func : in STRING);
>     function Calculate(Value : in FLOAT) return FLOAT;
> end math;
> 
> -- Sample program
> with math; use math;
> procedure sample is
>     result : FLOAT;
> begin
>     Set_Function("2*x+sin(x)");
>     result := Calculate(4.0);
> end;
> 
> What would be the Ada way to do this?

If you're going to pass the function in as a String, as your package
shows, then you will have to parse that string into its constituent
operands and operations.. These would be stored perhaps in a tree
structure, then traverse the tree in the proper sequence, doing an
interpretive evaluation as you go.  (And watch for malformed functions!)

Marc A. Criley
Consultant
Quadrus Corporation
www.quadruscorp.com



  reply	other threads:[~2002-05-16 11:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-14 12:51 Function pointer in Ada? Henrik Quintel
2002-05-14 13:08 ` Markus Knauss
2002-05-14 13:12 ` Marin David Condic
2002-05-14 14:36 ` Alfred Hilscher
2002-05-14 17:58 ` Kai Schuelke
2002-05-14 18:01   ` Preben Randhol
2002-05-14 18:24   ` David C. Hoos
2002-05-14 20:00     ` Kai Schuelke
2002-05-14 18:25   ` Marin David Condic
2002-05-15 22:30     ` Kai Schuelke
2002-05-16 11:37       ` Marc A. Criley [this message]
2002-05-16 19:06         ` Kai Schuelke
2002-05-16 19:18           ` Preben Randhol
2002-05-16 12:53       ` Georg Bauhaus
replies disabled

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