comp.lang.ada
 help / color / mirror / Atom feed
From: "Kai Schuelke" <kai.schuelke@gmx.net>
Subject: Re: Function pointer in Ada?
Date: Tue, 14 May 2002 22:00:36 +0200
Date: 2002-05-14T22:00:36+02:00	[thread overview]
Message-ID: <3ce16ccc.0@news.unibw-muenchen.de> (raw)
In-Reply-To: mailman.1021400702.30533.comp.lang.ada@ada.eu.org


"David C. Hoos" <david.c.hoos.sr@ada95.com> schrieb im Newsbeitrag
news:mailman.1021400702.30533.comp.lang.ada@ada.eu.org...

[..]

> Why you would want to do this, I can't imageine, but here's how it can be
> done:

[..]

That's how I did it. It was for a function-plotter. You put in a String and
you get back a pointer to a mathmatical function.

It looked like this. I hope you get a idea from this ut down version. If
anybody's interessted in it I can send the sources.

type Single_Operation is
    Op : Operator_Pointer;
    L    : Single_Operation_Pointer;
    R    : Single_Operation_Pointer;
    Parameter : FLOAT;
end record;

The mathematical function is represented with a tree of Single_Operation. To
solve the equation you just have to do a recursive call:

function solve(temp : Single_Operation_Pointer) return FLOAT is
begin
    if L /= null then
        return temp.Op.all(solve(L), solve(R));
    else
        return Parameter;
    end if;
end;

The program works, but it would be more elegant if I could get a pointer to
the Standard"+" without wrapping a extra function around it.

I thought it would be better to use pointers to functions because it is more
memory efficient and more flexible, too.

Have a good night!

Kai Schuelke








  reply	other threads:[~2002-05-14 20:00 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 [this message]
2002-05-14 18:25   ` Marin David Condic
2002-05-15 22:30     ` Kai Schuelke
2002-05-16 11:37       ` Marc A. Criley
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