Lightwave
Ad astra
- Local time
- Today, 00:43
- Joined
- Sep 27, 2004
- Messages
- 1,537
Just a thought
Last night I was thinking about writing user defined functions particularly with equations and lets say you have an equation like
Distance = Speed x Time
Normally you would write a function similar to the following
All well and good but then what if you are in a situation where you have one unknown but it isn't Distance its speed. In this situation you would then have to write a new function to Calculate Speed
My question is this.
Are there any programming languages out there where you don't have to do this. Ones where you can give it a formula and it will alter the subject of the formula itself.
My air code VB for this might be something like this
So you could then go call the speeddistancetime equation and pass whatever two parameters you knew. It would know which parameters you were passing because you would put them in the equivalent places within the original brackets.
So it assumes that the computer can rearrange the subject of an equation on the sly given one example of that equation.
My curiosity leads me to ask are there any programming languages out there that can do it and do you think it would be a good feature of a programming language?? I had a quick search on the web for something but either it doesn't exist or more likely I'm not defining my search with enough clarity/ the right terms.
Last night I was thinking about writing user defined functions particularly with equations and lets say you have an equation like
Distance = Speed x Time
Normally you would write a function similar to the following
Code:
Public Function CalculateDistance(Speed as long, Time as long) as long
CalculateDistance = Speed * Time
End Function
All well and good but then what if you are in a situation where you have one unknown but it isn't Distance its speed. In this situation you would then have to write a new function to Calculate Speed
Code:
Public Function CalculateSpeed(Distance as long, Distance as long) as long
CalculateSpeed = Distance / Time
End Function
My question is this.
Are there any programming languages out there where you don't have to do this. Ones where you can give it a formula and it will alter the subject of the formula itself.
My air code VB for this might be something like this
Code:
Public Equation SpeedDistanceTime(Speed as long, Distance as long, Time as long)
Speed = Distance / Time
End Equation
So you could then go call the speeddistancetime equation and pass whatever two parameters you knew. It would know which parameters you were passing because you would put them in the equivalent places within the original brackets.
So it assumes that the computer can rearrange the subject of an equation on the sly given one example of that equation.
My curiosity leads me to ask are there any programming languages out there that can do it and do you think it would be a good feature of a programming language?? I had a quick search on the web for something but either it doesn't exist or more likely I'm not defining my search with enough clarity/ the right terms.
Last edited: