Zahn's construct
Zahn's construct in computer science, also known as the "situation case statement", was a proposed structure for structured control flow in computer programming languages first described by Charles T. Zahn in 1974.[1] The construct is primarily described in terms of an extension to looping constructs to recognize multiple means by which a loop could terminate. For example, a search loop might terminate early, when the target is found; or it might terminate after the search has been completed unsuccessfully. Zahn's construct can be used to avoid GO TO statements when determining which case was encountered. Zahn does this by introducing a new kind of variable called a situation indicator in a CASE-like construct surrounding the loop.
Donald Knuth, in his paper "Structured Programming with Go To Statements",[2] describes two forms of Zahn's construct as follows:
loop until <situation 1> or ... or <situation n>:
<statement list 0>
repeat;
then <situation 1> => <statement list 1>;
...
<situation n> => <statement list n>;
fi
and:
begin until <situation 1> or ... or <situation n>:
<statement list 0>;
end;
then <situation 1> => <statement list 1>;
...
<situation n> => <statement list n>;
fi
There must also be a statement to set a specific situation indicator and exit the body of the construct.
The following simple example involves searching a two-dimensional table for a particular item.
exitwhen found or missing;
for I := 1 to N do
for J := 1 to M do
if table[I,J] = target then found;
missing;
exits
found: print ("item is in table");
missing: print ("item is not in table");
endexit;
Try-catch blocks, used in modern programming languages for exception handling, are substantial extensions of Zahn's construct. The major difference is that the scope of Zahn's proposals were limited to individual loops within a program, whereas exception-handling capabilities often allow exceptions to be "thrown" from deep within a call stack and "caught" at a point higher up in the stack. Because Zahn's construct is local to a routine, it can be implemented very efficiently, without any need to 'unwind' the call stack.
Zahn implemented his situation case statement in his SKOL language. SKOL was implemented as a set of macros for the MORTRAN Fortran preprocessor.
References
- ^ Zahn, C. T. "A control statement for natural top-down structured programming" presented at Symposium on Programming Languages, Paris, 1974.
- ^ Knuth, D. E. "Structured Programming with Go To Statements" Archived 2013-10-23 at the Wayback Machine, Computing Surveys, Volume 6, December 1974, page 275
External links
- Zahn, C. T. Structured Control in Programming Languages[dead link] SLAC Pub-1530, January 1975
- Control structures Archived 2011-06-08 at the Wayback Machine defined using Scheme; Zahn's construct is the last one in the list
- Zahn's construct Archived 2006-09-23 at the Wayback Machine defined using GOTOs in Forth
- The SKOL Programming Language Reference Manual
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.