Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!seismo!sundc!newstop!sun!brahmand!grover From: grover@brahmand.Sun.COM (Vinod Grover) Newsgroups: comp.lang.misc Subject: Re: What is Lazy Evaluation? Keywords: expression evaluation, lazy evaluation Message-ID: <131929@sun.Eng.Sun.COM> Date: 16 Feb 90 02:50:02 GMT References: <3109@caesar.cs.montana.edu> <6081@bd.sei.cmu.edu> Sender: news@sun.Eng.Sun.COM Reply-To: grover@sun.UUCP (Vinod Grover) Distribution: usa Organization: Sun Microsystems, Mountain View Lines: 17 In article <6081@bd.sei.cmu.edu> firth@sei.cmu.edu (Robert Firth) writes: > >Example: > > munge(1/x) > >greedy evaluation will evaluate 1/x and then call munge(). lazy >evaluation will call munge(), and evaluate 1/x only when the body >of munge referenced its formal parameter. > >As the example shows, lazy evaluation "works" in cases where greedy >evaluation does not - in this case, if x=0 but munge doesn't reference >its parameter. Lazy Evaluation differs fromn call-by-name in that the expression is evaluated at-most-once. If there are multiple refrences to 1/x, in the above example, only one of them will be evaluated if needed.