<- People Behind Informatics


All 0-9 A B C D E F G H I J K L M N O P Q R S T U V W XY Z




 
Guarded Command
The term guarded command, as defined by Dijkstra (1975), is synonymous with a conditionally executed statement. More precisely, a guarded command is the combination of a condition (boolean expression) B and the (possibly compound) statement S whose execution is controlled by B. In a sense, B "guards" the execution of S. In Dijkstra's notation, a guarded command is represented as B S. In more common notation, the meaning of a guarded command is very much like that of the simple selection structure (if statement): if B then S. Unlike the if statement, however, a guarded command, by itself, is not a complete statement in a programming language. Rather, it is one component of a more extensive control structure containing one or more guarded commands. The most interesting applications of guarded commands are those involving a set of n of them, for n > 1. B1-->S1 B2-->S2 . . Bn-->Sn Here there are n boolean expressions, each guarding a different statement. When a structure containing a set of guarded commands is executed, the guards are evaluated; the order in which they are evaluated is completely immaterial. Upon evaluation of all n, a subset (which may be empty) of the guards will have the value true. Of this subset, one is chosen at random; it is the corresponding S that is selected for execution. If all of the guards in a given guarded command set are disjoint-that is, if no more than one guard is true at any given time-then the selection of S is well defined despite the unspecified and random nature of guard evaluation and selection. If, however, the guards are not disjoint, with the possibility that more than one may be true simultaneously, then selection of S is not well defined (and indeed may be different from one execution of the program to the next). For this reason, guarded command sets are fundamentally nondeterministic. The nondeterminism places increased emphasis on abstract specification of the desired computation, with corresponding de-emphasis of algorithm implementation details. This encourages more systematic, and hence reliable, program development. As an example let’s assign the minimum value of x and y to the variable min. In deterministic (Algol-like) code this would look like: if x <= y then min:= x else min:= y end Note that if x = y then it is irrelevant whether we assign x or y to min. Thus, the following statement is equivalent to the previous, although the actual execution is different if x = y: if x < y then min:= x else min:= y end With the help of guarded commands we can directly express the above nondeterministic nature (let the relevant set of guarded statements be enclosed between brackets): [ x <= y --> min:= x; y <= x --> min := y ; ] If only one of the guards is true then the statement selection is deterministic. If both guards are true (x = y) then one of the statements is selected at random – which entirely corresponds to the semantics of the problem. [Source: Encyclopedia of Computer Science, Fourth Edition, Anthony Ralston, Edwin D. Reilly, David Hemmendinger; Laszlo Böszörmenyi: Notes to the Virtual Exhibition "People behind Informatics"]
 

 

<- People Behind Informatics


Home  |  Top  |  Search  |  Gallery  | Glossary  | Sitemap  |  Making Of  |  Help