Free Republic
Browse · Search
News/Activism
Topics · Post Article

To: ThinkDifferent
lazy evaluation programming techniques, where you don't bother computing a result until you actually need it

What's this? (serious question)

64 posted on 05/14/2003 5:11:34 PM PDT by Prodigal Son
[ Post Reply | Private Reply | To 61 | View Replies ]


To: Prodigal Son
What's this?

Say I was writing a computer program that read in a list of numbers and plotted them on a graph. The program also has options to compute various statistics about the numbers (mean, standard deviation, etc). But most of the time the users don't ask for that information, they just want the graph. Then it might be more efficient to not compute the statistics as the data was being read, but only to do that if the user actually requested it. Since they usually don't, the program avoids unneccesary work.

Now say I'm writing a somewhat more complicated program that simulates a universe. I could try to keep track of the position and velocity of every single particle, and update everything after each "tick" of the simulation. But that's really inefficient; for example, I don't need to be constantly updating the locations of all the atoms in Pluto. Instead, maybe I'd come up with an equation for each particle that describes where it will be in the future, given its starting position. This way once I've assigned an equation to a simulated particle I don't have to worry about it until I actually need to know where it is, perhaps because a simulated person is looking at it. Then I can just plug in the right numbers into the particle's equation to figure out where it should be.

Then at some point simulated scientists in my universe might figure out that they can cause particles to behave differently depending on whether or not they observe them...

98 posted on 05/14/2003 6:13:16 PM PDT by ThinkDifferent
[ Post Reply | Private Reply | To 64 | View Replies ]

Free Republic
Browse · Search
News/Activism
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson