Path: csiph.com!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: Rod Pemberton Newsgroups: comp.lang.forth Subject: Re: BEGIN WHILE UNTIL THEN Date: Thu, 7 Jan 2016 05:13:10 -0500 Organization: Aioe.org NNTP Server Lines: 71 Message-ID: <20160107051310.67828226@_> References: <08c4616c-21ad-4bdf-9fe4-a9e5ee2e5dad@googlegroups.com> NNTP-Posting-Host: n4wpt9zq8xR26Ttf9mo2BA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Claws Mail 3.13.1 (GTK+ 2.24.10; x86_64-unknown-linux-gnu) Xref: csiph.com comp.lang.forth:44658 On Mon, 4 Jan 2016 14:50:25 -0800 (PST) Julian Fondren wrote: > The following code is from SwoopPortable.f > > : UPDATE-LINKS ( super link -- ) >R > BEGIN > DUP @ DUP WHILE \ prev cur > R@ BEGIN \ prev cur sup > @ DUP WHILE \ prev cur sup' > 2DUP = UNTIL > 2DROP R> @ SWAP ! EXIT > THEN DROP NIP > REPEAT R> DROP 2DROP ; > > Can someone rewrite this with normal control-flow? > Reformatting, ... : UPDATE-LINKS ( super link -- ) >R BEGIN DUP @ DUP WHILE \ prev cur R@ BEGIN \ prev cur sup @ DUP WHILE \ prev cur sup' 2DUP = UNTIL 2DROP R> @ SWAP ! EXIT THEN DROP NIP REPEAT R> DROP 2DROP ; I'm not sure I understand fully how this BEGIN-WHILE-UNTIL-THEN thing works ... My guess is that a false condition (NULL pointer terminating a linked-list) at the WHILE in the inner loop continues at the THEN's "DROP NIP" for end-of-list. Otherwise, if not end-of-list, then BEGIN-WHILE-UNTIL cycles until a pointer match is found. When found, the code after the UNTIL is executed for the true match. If so, then the inner BEGIN-WHILE-UNTIL-THEN loop is really a BEGIN-UNTIL followed by an IF-ELSE-THEN, where the BEGIN-UNTIL is checking for two conditions to exit. Since the BEGIN-UNTIL now exits for two conditions, you must determine which condition caused it to exit, afterwards. E.g., the BEGIN-WHILE-UNTIL-THEN is something to the effect of this BEGIN-UNTIL with two exit conditions, which is not tested, and is possibly incorrect for the sample code above ... BEGIN @ 2DUP = OVER 0= OR \ OR two exit conditions UNTIL IF DROP ... EXIT \ DROP one since IF took one ... ELSE DROP NIP THEN Rod Pemberton