Dynamic Programming Language Idea

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

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:
This sounds similar to various methods of a class(class module).
I see what you are saying - you have an algorithm with 3 variables; if you know 2 you can determine the third; the twist is any of the 3 could be the unknown....

Perhaps you could add a 4th parameter -- unknwn one of s/t/d

then
Select case unknwn
...calculations
case "D"
distance = speed * time
Case "S"
speed = distance/time
Case "T"
time = distance/speed
Case Else
End Select
return the appropriate value
 
Last edited:
Yes that's it jdraw I'll have a look at class modules.
 

Users who are viewing this thread

Back
Top Bottom