Author: James Swafford
Date: 15:30:26 05/29/04
Go up one level in this thread
On May 29, 2004 at 18:27:53, James Swafford wrote: >On May 29, 2004 at 17:47:02, Sune Fischer wrote: > >>On May 29, 2004 at 11:33:01, James Swafford wrote: >>>> >>>>How would you pass arguments to a function in an unevaluated state? Can you draw >>>>a stack frame showing exactly what would be done? >>> >>>The problem (well, Uri's problem) is the order in which the compiler >>>evaluates the expression tree. Think of 'printf' as a node in a tree >>>with the parameters as children. >>> >>>Apparently the children are evaluated first (bottom up), and since >>>they share memory, voila... >>> >>>I think printf could do something like: >>> >>>While (unevaluated parameter) { >>> evaluate parameter >>> copy results to buffer >>>} >>>print buffer >>> >>>Not as efficient, but it would work. >>> >>>Note I am _not_ saying it _should_ work this way! >> >>From what I understand the problem is not with printf, but in the way parameters >>are passed to functions in general. >> >>Eg. if I write F(3*x+4,0.6*y-2), then the program will first evaluate the >>argumens and _then_ pass them to the function, F. >> >>It is not possible for the compiler to replace that with two calls like F(3*x+4) >>and F(0.6*y-2), because the compiler can't possibly know if F can handle that. >> >>Printf is no exception I think, it gets treated like any other function in this >>respect. > >No... perhaps C can't do this because of the way the language is >defined, but you _can_ change the order in which expressions are >evaluated. Functional languages are good examples of how a >parameter might not get evaluated at all. > >Languages that do this use what's called 'lazy evaluation', or >'outside-in evaluation'. Ah.. after rereading, I see the difference. You're talking about applying the outside function to both parameters, not 'not evaluating' a parameter. I agree with you... -- James > >-- >James > > > >> >>-S. >>>-- >>>James
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.