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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d8e7e976ead4a812 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-16 04:37:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3CE39A2D.2C75435A@earthlink.net> From: "Marc A. Criley" Organization: Quadrus Corporation X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Function pointer in Ada? References: <5f4adaeaa2a7b35810acd4e20fb98b25.86200@mygate.mailgate.org> <3ce15027.0@news.unibw-muenchen.de> <3ce2e175.0@news.unibw-muenchen.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 16 May 2002 11:37:04 GMT NNTP-Posting-Host: 63.191.67.32 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1021549024 63.191.67.32 (Thu, 16 May 2002 04:37:04 PDT) NNTP-Posting-Date: Thu, 16 May 2002 04:37:04 PDT Xref: archiver1.google.com comp.lang.ada:24178 Date: 2002-05-16T11:37:04+00:00 List-Id: 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