[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Determining which functions to call
- From: Florian Berger <fberger@...>
- Date: Tue, 21 Jan 2003 09:37:59 +0200 (EET)
Thanks for your answer.
What I was looking was a little bit more general solution. The idea is
that my system would search the solution from available functions and
determine which functions are needed for the final solution. I have come
up with something like this:
-- Array of function descriptions
-- First index is return value and after that come parameters
aryFD={}
aryFD["Diameter"]={"DIAMETER", "RADIUS"}
aryFD["Perimeter"]={"PERIMETER", "DIAMETER"}
Now my system can check what kind of functions are in system and what they
return and require as parameters. I think now it is possible to add so
many functions as possible. How good is this idea and are there any other
ideas?
Florian
> Florian Berger wrote:
> >
> > Hi.
> >
> > I would like to make a script system which determines the order of needed
> > function calls to solve a problem. The basic idea is that I know values of
> > some variables and then I have functions which can or cannot solve the
> > problem with existing variables.
> >
> > Simple example:
> > I have a Circle-object which has two attributes: radius and diameter.
> > I know the circle's radius but not the diameter.
> > I have two functions: one which calculates diameter from radius and other
> > which calculates area of circle using diameter.
> > I would like to make my system solve the area of circle so, that it
> > automatically solves the diameter for the area-function.
> >
> > Are there some examples of this kind of problems for LUA and do you think
> > LUA is good choice for this kind of programming?
> >
> > Florian
>
> This would be quite simple:
> (Lua 5 beta code, I think it's PI in stead of math.pi in Lua 4)
>
> function areafromdiameter(d)
> return math.pi * d * d / 4
> end
>
> function calccircle(circle)
> if circle.radius then --will be false if not defined.
> circle.diameter = circle.radius * 2
> end
> return areafromdiameter(circle.diameter)
> --This skips certain sanity checks that might be useful
> end
>
> print(calccircle({radius=4}))
> print(calccircle({diameter=8}))
>
> --Outputs:
> --50.265482457437
> --50.265482457437
>
> --
> "No one knows true heroes, for they speak not of their greatness." --
> Daniel Remar.
> Björn De Meyer
> bjorn.demeyer@pandora.be
>