Live data from Hacker News

If-then-else had to be invented

github.com

81–90 of 255 posts

Re: If-then-else had to be invented

#81

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…

"(Women were present) and (children were present)"

Re: If-then-else had to be invented

#82

Earlier quoted context omitted.

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.

> "or" is almost always exclusive, i.e "do you want to eat pizza or pasta?" does not imply that eating both is an option. English is way too ambiguous for this example and often relies heavily on context. Wanting to eat pizza does not preclude also wanting to eat pasta. If it was exclusive or, and you wanted to eat both pizza and pasta, the honest answer to this question would be "no," but what you should say is "yes…

I'd say all languages work like that, not just English. Your phrasing "too ambiguous" is a little off to me. Ambiguity (in the sense of utterances having multiple possible interpretations) is the norm in natural language, and it combines with our ability to effortlessly pick the intended one based on context to make natural language work.

Even sentences that on their face are strictly propositional will, in actual situated language use, have implied meanings (a pragmatic level). The canonical example is where one person says "It's cold" (at it's core a statement of fact), after which another person closes a window, or hands them a jacket, or follows with "Let's go home, then". If you want to give an account of natural language meaning that's even remotely complete, you cannot stop at what's in the sentence at the surface, you absolutely have to look at why it's being said.

Indeed, if you think of an actual situation where someone would say "do you want to eat pizza or pasta?", I think you'd find that it does, in fact, imply that the two are exclusive in that context - say if you're at a restaurant where they only expect you to order one main course. But this is not a problem at all, it's just how language works.

(And personally, on the subject of logic and language, I'd even go as far as to say that logic is based on natural language rather than the other way around, but I think that might be tough sell to the mathematically minded.)

Re: If-then-else had to be invented

#83
post #82

Earlier quoted context omitted.

> "or" is almost always exclusive, i.e "do you want to eat pizza or pasta?" does not imply that eating both is an option. English is way too ambiguous for this example and often relies heavily on context. Wanting to eat pizza does not preclude also wanting to eat pasta. If it was exclusive or, and you wanted to eat both pizza and pasta, the honest answer to this question would be "no," but what you should say is "yes…

I'd say all languages work like that, not just English. Your phrasing "too ambiguous" is a little off to me. Ambiguity (in the sense of utterances having multiple possible interpretations) is the norm in natural language, and it combines with our ability to effortlessly pick the intended one based on context to make natural language work. Even sentences that on their face are strictly propositional will, in actual si…

>> Indeed, if you think of an actual situation where someone would say "do you want to eat pizza or pasta?", I think you'd find that it does, in fact, imply that the two are exclusive in that context

It was actually this specific question that made it clear to me that this is not the case.

In order to narrow down our takeout options, the girlfriend and I regularly ask questions like, "Do you want pizza or pasta?" meaning "Are any or all of these meal options acceptable to you?" (at which point the conversation continues with maybe us listing a few restaurants which offering one or both options.) This is the same exact phrase, but from context it is inclusive or.

>> - say if you're at a restaurant where they only expect you to order one main course.

Indeed, if the question was something like "Would you like soup or salad?" where, from context, the choice is binary and exclusive.

Re: If-then-else had to be invented

#84

Earlier quoted context omitted.

BBC Basic II does have ELSE, it just has to go on one line. IF A=4 THEN PRINT "FOUR" ELSE PRINT "NOT FOUR" Statements for the IF block and the ELSE block can be separated by ':'. I was recently given a BBC Micro and it's a fascinatingly impressive machine, the hardware and software are so beautifully designed in tandem that it's quite awesome even in 2020.

ah yes you are right, the in-line ELSE Obligatory shout out for 'Micro Men', about the making of the BBC Micro and ZX Spectrum https://www.youtube.com/watch?v=XXBxV6-zamM

For more geeky insights into the time, I can recommend the book The ZX Spectrum ULA http://www.zxdesign.info/book/ The business side of things is incidental to the rich details of the hardware design and production.

Re: If-then-else had to be invented

#85

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:…

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.

Short would be, 'and' implies, coincidence, not causality. 'Or' implies choice. If-then implies causality ("If my pants are dirty, then they need to be cleaned")

The big difference I see is with 'OR' in programing the options are exclusive. Ex: "Are you tired or hungry" The answer is yes if you are tired. Yes if you are hungry, Yes if you are both. No if you are neither. This is natural English. In programming if you are both. The answer is No.(False)

Re: If-then-else had to be invented

#86
post #27
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.

In colloquial english we usually put an "or" in front of else. It really breaks down when you put it in boolean form because the "or" implies other actions when true rather than actions if false. Removing the "or" completely is unambiguous but is antiquated English. Examples: "Go to college or else work for your uncle" Turn this into boolean form: "If you go to college then or else you will work for your uncle" But t…

The human language leaves the decision to the executor, dependency injecting an if/else framework into the entity making the decision.

Re: If-then-else had to be invented

#87

Earlier quoted context omitted.

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…

"(Women were present) and (children were present)"

How would you distribute "Jack and Jill play together."? If you start introducing prepositions, then your theory of "and"-expansion is going to get quite complex as it covers more and more cases.

Re: If-then-else had to be invented

#88
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 the else/always parts.

Re: If-then-else had to be invented

#89
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.

I wondered whether there was a conscious link in the minds of early language designers to Church encoding of booleans. (well, other than McCarthy and Lisp)

A Church boolean is either:

  true = λt.λf.t
  false = λt.λf.f
So instead of writing an expression with keywords like

  if bool then yep else nope
Just use the boolean as a function and apply it to the then and else clauses like

  bool yep nope
So the shape is very similar to modern languages, but with less syntactic scaffolding.

Re: If-then-else had to be invented

#90

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.

Short would be, 'and' implies, coincidence, not causality. 'Or' implies choice. If-then implies causality ("If my pants are dirty, then they need to be cleaned") The big difference I see is with 'OR' in programing the options are exclusive. Ex: "Are you tired or hungry" The answer is yes if you are tired. Yes if you are hungry, Yes if you are both. No if you are neither. This is natural English. In programming if you…

Isn't OR in most languages non exclusive? If you want exclusive OR you use XOR.
Post reply on HN