Live data from Hacker News

If-then-else had to be invented

github.com

91–100 of 255 posts

Re: If-then-else had to be invented

#91

Earlier quoted context omitted.

The word “and” in English is simply there to join multiple clauses together. Whether it is a set union or set intersection, (or some other relations) depends on the sentence. Set union: they can read and write’ Set intersection: my jeans were creased and dirty Sequential: he turned round and walked out Causal: there was a flash flood and by the next morning the town was under water’ And, there are many more usages.

I would say that in every case there is a set of things (maybe with a single member) and a set of predicates (maybe with a single member), a mapping from the things to the predicates, and every mapping produces a true proposition. "Women and children were present" isn't saying the intersection of the women and children were present but that the things were women and children and they all were present. The rest of the…

The meaning of “and” in natural language predates the meaning of “and” used in logics and set theories. I’m not convinced that all semantics of “and” can be derived from set operations.

1) not every clause is a predicate and applying logical operators to a non-predicate makes very little sense to me.

2) I don’t see how ordering, time, and causation can be inferred, if you treat each clause as a predicate.

“I punched Bob and apologized” has a different meaning than “I apologized, and punched Bob.”

The AND as used in logics simply doesn’t embody this usage.

—-

It was a sloppy wording of mine to say that AND just join clauses together. I meant to say that it joins clauses together, and the relations between the clauses are not necessarily set union. Of course it can’t embody all relations, but more than set unions.

Re: If-then-else had to be invented

#92
post #12

It begs the question: did we search and find the answer of if-then-else, or did we find an answer that was sufficiently likeable and usable- but one of many possibilities? How do we know whether this choice was the global optimum vs a local one? Is if-then-else the electron- a deep truth waiting to be discovered- or the gasoline powered car- an option we explored for decades among others options.

It is an interesting questions. My feeling is if-then-else falls some where between invented and discovered, something like mathematics. Once we had discovered the need for conditional control flow, any decent assembly language programmers would quickly discover many patterns for how it could be used. Eventually, these patterns were clarified and codified into languages and more abstract formalism. Like in much mathematics, that abstract formalism was am inevitable discovery once we took as axiom the basic logic of program control flow with conditional jumps.

It is such a basic, clear, and useful formalism, it is hard to imagine it not becoming widespread under some name/syntax.

But if-then-else is only clearly inevitable if you take as axiom the existence of store program computers with control flow. I can much more easily imagine that early on we invented a very different way to do computation as a whole. It seems likely that what we have actually invented is on a path toward a local optima.

Re: If-then-else had to be invented

#93

I remember there was a paper that tried to compare natural language usage of common programming language keywords to see if they may come up with other constructs to create a programming language that is easier to learn as your first one. There were a few interesting observations. The one that stuck with me the most is that 'and' is most commonly used with almost the opposite sense in natural language vs programming:…

What is the name of the paper?

Re: If-then-else had to be invented

#94
post #8
post #6

You can use "else" that way in ordinary speech. "If this then do that else do the other thing" is perfectly legitimate English, just a bit archaic.

Wiktionary has a usage example from 1903, clearly before modern computers but not too ancient. > 1903, Jack London, The Call of the Wild, Grosset & Dunlap, page 44: > […] and his first experience taught him an unforgetable lesson. It is true, it was a vicarious experience, else he would not have lived to profit by it. As an aside there is at least one common word which does seem to have been invented by the software…

> "access" as a verb

But is it pronounced the same way? I stress the first or the second vowel depending on the case.

Re: If-then-else had to be invented

#95

The story of development is interesting, but I doubt that the concept itself needed invention. Even in machine language using nothing but conditional branching the pattern would have appeared enough to be an idiom perhaps without a name: ... b? addr1 ...else stuff jmp addr2 addr1: ...then stuff addr2: ...always stuff What's more interesting is the generalization to any boolean expression, not the naming/placement of…

I miss that. Chaining jump to continue range of memory of jump is fun.

It's all down to comparing hex in 2 registers and jump. JNE, JE, JMP etc.

Re: If-then-else had to be invented

#96
post #12

It begs the question: did we search and find the answer of if-then-else, or did we find an answer that was sufficiently likeable and usable- but one of many possibilities? How do we know whether this choice was the global optimum vs a local one? Is if-then-else the electron- a deep truth waiting to be discovered- or the gasoline powered car- an option we explored for decades among others options.

"if then else" is indicative of an underlying pattern that exists at a more fundamental level. In that sense, it was "discovered", not invented.

Depending on the language, the syntax of "if then else" is not needed and is syntactic sugar.

In the Lambda Calculus you can implement "if else" using "first" and "second".

Here is something equivalent in JavaScript.

  const trueFn  = (first, second) => first
  const falseFn = (first, second) => second

  const ifFn = (boolFn, first, second) => boolFn(first, second)
  
  ifFn(trueFn,  'yes', 'no')  // returns 'yes'
  ifFn(falseFn, 'yes', 'no')  // returns 'no'

Re: If-then-else had to be invented

#98

I remember there was a paper that tried to compare natural language usage of common programming language keywords to see if they may come up with other constructs to create a programming language that is easier to learn as your first one. There were a few interesting observations. The one that stuck with me the most is that 'and' is most commonly used with almost the opposite sense in natural language vs programming:…

Great observations. In the same idea, "or" is inclusive in all of programming and CS, i.e. A and B => A or B, but in natural languages (as least the ones I know) "or" is almost always exclusive, i.e "do you want to eat pizza or pasta?" does not imply that eating both is an option. This is of course related to why the famous joke "Is it a boy or a girl? Yes." is so hilarious.

To make things even worse, we sometimes capitalise these words to emphasise that we're using them in a technical sense, but OR reads as if it's emphasising that it's an exclusive 'or'. You can have tea OR coffee is clearly emphasising that it's an XOR operation.

Somewhat related: the Ada language uses and, or, xor for its logical operators, but uses and then and or else for the short-circuit forms. [0] Not a very natural solution in my opinion.

[0] https://en.wikibooks.org/wiki/Ada_Programming/Operators#Shor...

Re: If-then-else had to be invented

#99
post #58

Earlier quoted context omitted.

The word “and” in English is simply there to join multiple clauses together. Whether it is a set union or set intersection, (or some other relations) depends on the sentence. Set union: they can read and write’ Set intersection: my jeans were creased and dirty Sequential: he turned round and walked out Causal: there was a flash flood and by the next morning the town was under water’ And, there are many more usages.

How is your set union example not another intersection (your quantification could go in one of two places though, they = (set of readers) cap (set of writers) versus they = { p in people such that (p writes) cap (p reads) }.

> they can read and write

Note that I’m not joining people with AND. I joined abilities.

For instance, to expand on the example.

I have three Pokémons. They can read and write.

I’m not saying that my three Pokémon are the intersection of reading Pokémon and writing Pokémon. There might be other Pokémon who can do just the same.

I’m saying that what they can do is a union of writing and reading.

EDIT: spelling

Re: If-then-else had to be invented

#100
post #4

This reminds me of a note in FreeBSD rc(1) man page[0] under "INCOMPATIBILITIES" > The Tenth Edition rc does not have the else keyword. Instead, if is > optionally followed by an if not clause which is executed if the pre- > ceding if test does not succeed. which i found pretty interesting [0]: https://www.freebsd.org/cgi/man.cgi?query=rc

Having taught programming to novices a little, I believe “if not” is clearer than “else”. Imagining “not” being prepended to the original conditional expression would be natural, especially in languages with “not X” construct (like Python), and it’s easy to forget that “else” is in fact archaic to non-programmer ears, slightly and possibly needlessly raising the barrier. if (X) { doY(); } if not /* X is implied */ {…

I wonder whether anyone has used "otherwise" for this. It'd be a simple alias for "else", but it'd certainly sound natural:

    if (X) { doY(); }
    otherwise { doZ(); }
Post reply on HN