Live data from Hacker News

If-then-else had to be invented

github.com

161–170 of 255 posts

Re: If-then-else had to be invented

#161
post #130

Earlier quoted context omitted.

I am the author, and I mean that I can say "or else" in a normal sentence, but I cannot say "else" without an "or" in normal speech in my normal dialect.

Hmmm, thinking about my dialect of English (Lancastrian) I can certainly say else without an or and it doesn't sound unnatural to my ears. Something like "if you're hungry now then I can make you a sandwich, else we'll eat when we get to the pub" doesn't sound more awkward than using otherwise. I can't say whether that's just because the Lancastrian dialect preserves quite a few old fashioned usages that have fallen…

I think it's relatively common in british english.

Certainly, from cumbria, it sounds quite natural also.

It's more spoken dialect than written. "What else do you want to do?" etc.

Re: If-then-else had to be invented

#162
post #101

> That's just English, right? Except that it isn't. I can't use "else" as a conjunction in normal speech, only in computer programs. Sure you can! Shakespeare used 'else' in the same sense as 'otherwise': https://www.shakespeareswords.com/Public/GlossaryHeadword.as... "else used as a conjunction" https://wordtype.org/of/else "Or else!" was common speech before computers, and a common vague cartoon/cowboy/sign threat.

There is some anecdotal support for the article's position in a recent [1] article about the origin of the C programming language -- apparently the C predecessor language CPL used "OR" as a keyword where most modern languages now use "else", on precisely these grammatical grounds, as understood by Christopher Strachey.

[1] https://arstechnica.com/features/2020/12/a-damn-stupid-thing...

Re: If-then-else had to be invented

#163

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.

If you say it out loud, you will realize that the question "Do you want to eat pizza or pasta?" (exclusive-or case with the answer "pizza" or "pasta," i.e. in the sense "these are your two choices, which would you prefer?") is an entirely different utterance from "Do you want to eat pizza or pasta?" (inclusive-or case with the answer "yes" or "no," i.e. in the sense "would you like to go to an Italian restaurant?").…

>inclusive-or case

I used to drive my friend crazy when he would ask if I wanted a peanut butter and jelly sandwich or a ham and cheese sandwich and I would answer yes.

Re: If-then-else had to be invented

#164

Chinese also has an interesting sentence structure that doesn't quite fit with European languages. In addition to subject.verb(object) form, there is also a kind of topic-comment form that might be reasonable to use in some assertion-like contexts. ensure(foo), !empty() require(bar), open() Chinese also has a word that can transform some kinds of statements into a question. `ma` is used to form yes-no questions. Imag…

Bulgarian also has a question particle (li or ли). In many cases questions are phrased by simply inserting “li” next to the focus of the question.

Re: If-then-else had to be invented

#165

Earlier quoted context omitted.

Your formula `(A --> B) ^ (¬A --> C)` expands to `¬(A & B) & (A | ¬C)`. I would propose that `(A & B) ^ (¬A & C)`, which expands to `(¬A | B) & (A | C)`, comes closer to actual `if` semantics.

They are equivalent (assuming ^ is the same as &). In particular, A --> B is equivalent to ¬A | B.

I see. I interpreted `^` as XOR. The implication (`-->`) was clear enough to not be misunderstood.

Re: If-then-else had to be invented

#166

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

I like the use of language in perl and wish it was more prevalent in other languages.

For example instead of saying "if not " you can also say "unless " which is more natural imo.

Re: If-then-else had to be invented

#167
Semi-related: Fortran has a where() and elsewhere() statement for applying a mask to part of an array. e.g.,

    where (C/=0)
        A = B/C
    elsewhere
        A = 0.0
    end
It blew my mind the first time I saw it. I’d never seen else in anything but an if statement before.

Re: If-then-else had to be invented

#168
post #130

Earlier quoted context omitted.

I am the author, and I mean that I can say "or else" in a normal sentence, but I cannot say "else" without an "or" in normal speech in my normal dialect.

Hmmm, thinking about my dialect of English (Lancastrian) I can certainly say else without an or and it doesn't sound unnatural to my ears. Something like "if you're hungry now then I can make you a sandwich, else we'll eat when we get to the pub" doesn't sound more awkward than using otherwise. I can't say whether that's just because the Lancastrian dialect preserves quite a few old fashioned usages that have fallen…

Works in my genericsSouthern British english dialect too. Think it might have been dropped in American english where it might be considered quite formal.

Re: If-then-else had to be invented

#169

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…

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…

> I’m not convinced that all semantics of “and” can be derived from set operations.

Totally agree. I think part of the issue is that "natural-language and" behaves differently when you apply it to different parts of speech, and everyone in this thread is thinking of a different part!

That being said, in the example sentences you gave ("I punched Bob and apologized" vs. "I apologized and punched Bob"), it's actually ambiguous whether they have equivalent meaning or not, when we ONLY consider grammar. Using ONLY the words in the sentence, the relationship between "apologized" and "punched" rests on our interpretation of "and"'s grammatical role. Taken in its usual sense as a conjunction, the two verbs are only related in the sense that the same subject performed them.

But I think you're arguing that "and" places the two verbs in sequence (which prevents the sentence from being flipped without changing meaning.) The more I think about this, the more I don't think it follows. To read the verb phrase this way, the reader has to infer a missing conjunctive adverb: ("punched Bob and [then] apologized")... and in order to make that inference, you need context from the sentence.

To make matters more complicated, we _could_ interpret the sentence in a way that doesn't imply the verbs are related: suppose the speaker is apologizing to some third party, and punches Bob for some unrelated reason. If we interpret it this way, the two sentences can be switched without changing the meaning too much.

But all this just goes to show: your core point is correct: natural languages aren't formal languages, and trying to treat them as such is an exercise in frustration.

Re: If-then-else had to be invented

#170
post #130
post #101

> That's just English, right? Except that it isn't. I can't use "else" as a conjunction in normal speech, only in computer programs. Sure you can! Shakespeare used 'else' in the same sense as 'otherwise': https://www.shakespeareswords.com/Public/GlossaryHeadword.as... "else used as a conjunction" https://wordtype.org/of/else "Or else!" was common speech before computers, and a common vague cartoon/cowboy/sign threat.

I am the author, and I mean that I can say "or else" in a normal sentence, but I cannot say "else" without an "or" in normal speech in my normal dialect.

Fascinating. English is not my first language but I thought https://en.wiktionary.org/wiki/what_else_is_new and https://www.ldoceonline.com/dictionary/what-else-can-somebod... are perfectly fine phrases.
Post reply on HN