Re: Re: Until -Reply
- To: mathgroup at smc.vnet.net
- Subject: [mg7110] Re: [mg7096] Re:[mg7063] Until -Reply
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Sun, 11 May 1997 02:57:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Wed, 7 May 1997 Sean Ross <SEAN at mail.creol.ucf.edu> [mg7096] Re:[mg7063] Until -Reply >The forms: >.....; or yours > Until[test_,body_]:=While[test=!=True,body]; >work fine, but are not a true Until because they don't execute body first. Sean: The form I suggestion in mg: SetAttributes[Until,HoldAll] Until[test_, body_]:= While[body;test=!=True] does execute body first: i=1;Until[True,i++];i 2 Allan Hayes hay at haystack.demon.co.uk http://www.haystack.demon.co.uk/ ********************** Begin forwarded message: >From: Sean Ross <SEAN at mail.creol.ucf.edu> >Subject: [mg7110] Re:[mg7063] Until -Reply The big difference between a While and an Until is that the Until performs its test after the execution of the body and while tests first. The forms: Until[test_,body_]:=While[Unevaluated[Not[test]],body]; or yours Until[test_,body_]:=While[test=!=True,body]; work fine, but are not a true Until because they don't execute body first. The form: Until[test_,body_]:=body;While[Unevaluated[Not[test]],body]; works for simple cases in which the variables in test are in existence independent of body, but does not work when the definitions necessary for execution of the test are first performed in body, so this is not a true Until structure either. Your suggestion applied to a true Until: Until[test_,body_]:=body;While[test=!=True,body] falls prey to the same problem. It is not a true until because the variables necessary to perform the test cannot be first defined in body, so it is not truly an independent structure. As an example for this definition problem, imagine a test involving the second element of a List, but the list is not defined anywhere except in body. Mathematica seems to scan the entire structure to make sure that List[] makes sense before it executes any of it rather than waiting until the test is to be performed to see if it makes sense. What I need is an attribute that will stop mathematica from examining or precompiling test or While so that it only looks at it after body is executed for the first time. Thanks for your help.