haskellfunctional-programmingguard-statement

Why guards are called 'guards'?


Does anyone know what is the origin of the name for the construct called guards?

func x
    | cond1 -> expr1  
    ...
    | condN -> exprN

Wikipedia article Guard_(computer_science) gives some historical perspective, but lacks explanation for where name came from (it just mentions that SASL was one of the first to use the name).

So far I found references to Edsger Dijkstra and his Guarded Command Language. Was he first to use the term 'guard'?


Solution

  • Yes, the term is from Dijkstra. Guarded commands, non-determinacy and formal derivation of programs (CACM 1975)

    It's ironically hilarious that the Wikipedia article Guard (computer science) says "Guard code provides an early exit from a subroutine, and is a commonly used deviation from structured programming", lacking a fundamental appreciation of guards & structured programming, since the term became important because Dijkstra's guards were a fundamental & influential contribution to structured programming.