Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!desnoyer From: desnoyer@Apple.COM (Peter Desnoyers) Newsgroups: comp.lang.c Subject: Re: C optimizer Message-ID: <27606@apple.Apple.COM> Date: 20 Mar 89 21:05:34 GMT References: <36662@think.UUCP> <453@lakart.UUCP> <1470@mcgill-vision.UUCP> <21652@agate.BERKELEY.EDU> Organization: Apple Computer Inc, Cupertino, CA Lines: 34 In article <21652@agate.BERKELEY.EDU> bowles@eris.berkeley.edu (Jeff A. Bowles) writes: >>>> In article <1028@frog.UUCP> john@frog.UUCP (John Woods) writes: >>> [various people arguing whether getpid() is pure] >> >Are we still on this topic? By the bogosity above, nothing is "pure", >because you might write a function that changes the behaviour of another >function - for example, [...] I beg to differ. I would consider that any "pure" function that does not take arguments to be a constant, as otherwise it cannot depend solely on its arguments, but must return a value dependent on state information external to the function. How about these definitions: (note that I am considering "implicit" results, e.g. status = f(arguments,&result) style calls return two results.) pure - if f is pure and f takes arguments Ai and returns results Ri, then for any action B which does not modify A or R: R=f(A),B,R=f(A) is equiv. to R=f(A),B is equiv. to B,R=f(A) conditionally pure - if f is conditionally pure, then one can define a dependency set D such that if B is some action with does not modify A or R, and does not contain any elements of D, then R=f(A),B,R=f(A) is equiv. to R=f(A),B is equiv. to B,R=f(A). It is a lot simpler for a compiler to take advantage of pure functions than conditionally pure ones, because it doesn't have to worry about dependencies. Peter Desnoyers