4

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'?

amalloy
  • 89,153
  • 8
  • 140
  • 205
alex_why
  • 95
  • 3
  • 7
    A *guard* decides who can come in, and who stays out. So the condition decides if the expression "fires". – Willem Van Onsem Jun 23 '17 at 16:38
  • 3
    On the close votes: the question ("Was Dijkstra the first to use the term 'guard'?") is neither broad nor opinion-based. I'm not sure whether computing history questions are on-topic or not. I'm leaning towards not, but in any case the question clearly is not about general computing hardware and software (and would probably be *even more* off-topic on SuperUser than it is here). So I squint at all of the close votes that exist so far. – Daniel Wagner Jun 23 '17 at 18:51
  • not SASL, KRC . – Will Ness Jun 23 '17 at 18:55
  • guards are not much different from plain conditionals. and these already were in the (largely ignored) Plankalkül (although Wikipedia says it influenced Algol 58). – Will Ness Jun 23 '17 at 19:30

2 Answers2

1

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.

philipxy
  • 14,867
  • 6
  • 39
  • 83
0

I think it's pointless asking where terminology comes from. (For example why does Haskell have 'types' and 'kinds', whereas math has 'sorts'?) The wikipedia article is good.

The style of writing guards to the right does mirror maths (the wikipedia article has an example). That's probably what influenced Dijkstra. And there's the same mathematical style in Strachey 1967 'Fundamental Concepts'. (He doesn't use "guard".)

@Will Ness guards are not much different from plain conditionals is not right. So it's good to have a different word than "condition". Guards come after pattern-matching:

case x of
  (Maybe x') | x' > 0 -> ...
  Nothing {- x' not in scope here -} -> ...

In a case branch: first match the pattern, and that binds variables; then apply guards using the variables.

And you can extend the idea to the type level https://github.com/AntC2/ghc-proposals/blob/instance-apartness-guards/proposals/0000-instance-apartness-guards.rst

AntC
  • 2,623
  • 1
  • 13
  • 20
  • 3
    I think it's pointless to claim that someone's curiosity is pointless – luqui Jun 24 '17 at 07:05
  • `(cond ((even? 2) => (lambda (b) ...)) (else ... ;|b is not in scope here|; ...))`. potayto, potahto. :) "not much different" =/= "exactly the same". --- Looked at from sufficiently afar, everything resembles everything else. ("huh, those hadron-based objects aren't that much different from one another", says an energy-based lifeform looking at a human and a tree ...) – Will Ness Jun 24 '17 at 11:57
  • (BTW the @ ping does not work from the post body, only from the comments) – Will Ness Jun 24 '17 at 12:00