Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Guard (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Evolution== A simple conditional expression, already present in [[CPL programming language|CPL]] in 1963, has a guard on first sub-expression, and another sub-expression to use in case the first one cannot be used. Some common ways to write this: (x>0) -> 1/x; 0 x>0 ? 1/x : 0 If the second sub-expression can be a further simple conditional expression, we can give more alternatives to try before the last ''fall-through'': (x>0) -> 1/x; (x<0) -> -1/x; 0 In 1966 [[ISWIM]] had a form of conditional expression without an obligatory fall-through case, thus separating guard from the concept of choosing either-or. In the case of ISWIM, if none of the alternatives could be used, the value was to be ''undefined'', which was defined to never compute into a value. [[Kent Recursive Calculator|KRC]], a "miniaturized version"<ref>{{cite web|last1=Turner|first1=D. A.|title=Some History of Functional Programming Languages|url=https://www.cs.kent.ac.uk/people/staff/dat/tfp12/tfp12.pdf}}</ref> of [[SASL programming language|SASL]] (1976), was one of the first programming languages to use the term "guard". Its function definitions could have several clauses, and the one to apply was chosen based on the guards that followed each clause: <!-- SASL isn't Haskell, of course, but the syntax is close enough... --> <syntaxhighlight lang="haskell"> fac n = 1, n = 0 = n * fac (n-1), n > 0 </syntaxhighlight> <!-- add something on how Guarded commands fit in --> Use of guard clauses, and the term "guard clause", dates at least to [[Smalltalk]] practice in the 1990s, as codified by [[Kent Beck]].<ref name="beck"/> In 1996, Dyalog APL adopted an alternative pure functional style in which the guard is the only control structure.<ref>{{Cite web|url=http://www.dyalog.com/uploads/documents/Papers/dfns.pdf|title=Direct Functions in Dyalog APL|last=Scholes|first=John|date=|website=|publisher=|access-date=}}</ref> This example, in APL, computes the parity of the input number:<syntaxhighlight lang="apl"> parity←{ 2∣⍵ : 'odd' 'even' } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)