[comp.lang.forth] Guarded Commands

wmb@MITCH.ENG.SUN.COM (Mitch Bradley) (03/21/91)

Those interested in guarded commands and similar control structures
may be interested to read Kurt Louto's paper "Parnas' it..ti Structure",
Forth Dimensions, Vol. VI, No. 1, May 1984.

Mitch Bradley

UNBCIC@BRFAPESP.BITNET (03/21/91)

> > These are Dijinskra structeres.
> What's that you said?

> Dijinskra?

> (Since you called him that twice I don't consider the posibility of faulty
> transmission software:)

> I knew Dutch is not the easiest language for a non-native, but the man
> was called Dijkstra when he left this university X years ago.

*PLEASE* forgive me. I *SWEAR* that, if I had time, I would look for the
correct information. I'm not sure that the first example was him. And I knew I
would probably mispell the name. But.....

> Furthermore I would use the original (shorther) spelling, so the constructs
> become:

IF guard0                            DO guard0
-> statement0                        -> statement0
[] guard1                            [] guard1
-> statement1                        -> statement1
   ...                                  ...
[] guardn                            [] guardn
-> statementn                        -> statementn
FI                                   OD

> By the way, implementing IF/FI and DO/OD as is in Forth, will be a bit hard,
> because of the prefixedness. Therefore I'd suggest a syntax like the
> following:

guard0                               guard0
IF statement0 []                     DO statement0 []
guard1                               guard1
IF statement1 []                     DO statement1 []
   ...                                  ...
guardn                               guardn
IF statementn FI                     DO statementn OD

> Note that when  [] gets rewritten as ELSE, you'd have a alternative
> to the Baden's OF THENS and Eaker's CASE. I'll leave the implementation
> pleasures to you :)

No way. As I don't have time, I'll not implement, but I assure you that they
can be implemented, with the same syntax in 5 lines each. Se, the IF (we should
change the IF and DO names) puts a flag on stack, that is tested by FI. This
flag is initialized (by IF) with 0. The -> can be a POSTPONE IF POSTPONE R>
POSTPONE DROP POSTPONE TRUE POSTPONE >R, and [] an alias for THEN. Same kind of
behavior for DO ... OD.

> Jan Stout, Eindhoven University of Technology

Thank you *VERY* much for the correction.

                              (8-DCS)
Daniel C. Sobral
UNBCIC@BRFAPESP.BITNET