News for hackers. Stuff that matters.
Re:If-then-else had to be invented by tsimionescu on Sunday December 13, 2020 @10:16AM (#25407087)
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: more precisely, in natural language, 'and' usually implies set union, which is more similar to boolean Or. For example, 'women and children' means of course 'if X is a woman OR X is a child'.

The other interesting observation was that in natural language we usually describe operations on sets as taking the whole set as an argument, not in terms of what happens with each individual member. For example, it's more likely you'll say something like 'give candy to these kids' or 'wash these cars' than 'give a piece of candy to each kid' or 'wash each of these cars'. Of course, index based loops are essentially never used in common language, but even the common loop comprehensions that introduce a loop variable are quite far from natural language.

Re:If-then-else had to be invented by powersnail on Sunday December 13, 2020 @10:37AM (#25407232)
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.

Re:If-then-else had to be invented by chalst on Sunday December 13, 2020 @11:52AM (#25407895)
This is correct. The technical word linguists use for the role words like "and" play is coordination.

https://en.wikipedia.org/wiki/Coordination_(linguistics)

Re:If-then-else had to be invented by DFHippie on Sunday December 13, 2020 @11:49AM (#25407861)
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 variety of "meanings" of "and" are just inferences on top of this basic meaning. If things occur in sequence, for instance, we can infer causality from what we know about the things conjoined apart from the conjunction.

Crucially, there is more here than just "joining multiple clauses together" (and many of the things conjoined aren't clauses), because "or" can be described this way too, but "and" does not mean the same thing as "or". With "or" you are only asserting that some of the propositions are true.

Re:If-then-else had to be invented by powersnail on Sunday December 13, 2020 @12:32PM (#25408259)
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 by DFHippie on Sunday December 13, 2020 @04:17PM (#25410374)
I'm being a little sloppy in my language as well.

Since words and phrases necessarily occur in sequence, if you are speaking of things can be and typically are in sequence, it is natural to infer that the speaker is presenting them in the sequence of their occurrence. The speaker can do this, the speaker and the hearer both know that the speaker can do this, and it is a common understanding between the speaker and the hearer that the speaker intends the hearer to receive a particular representation of events: this is the purpose of communication. This being so, the speaker presenting events out of their temporal sequence would be perverse. If the speaker knows the hearer will assume she is presenting events in their temporal sequence, she must present them in this sequence or explain that they are not so presented. To do otherwise would be understood by the speaker and hearer as deliberate deception.

So the sequence comes not from the semantics of "and" but the pragmatics of speaking itself. In fact, you don't need "and" at all. If you leave "and" out -- asyndeton -- and list things, they will be understood to be in temporal sequence if they are the sort of thing that occur that way. "I opened the door. I went out."

All of these "meanings of and" can be explained via pragmatics and a very simple meaning of "and". The meaning I provided was intended as a hand-wavy gesture in the direction of a more formal theory.

Re:If-then-else had to be invented by mhink on Sunday December 13, 2020 @05:11PM (#25410870)
> 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 by patates on Monday December 14, 2020 @08:43AM (#25417377)
> The meaning of “and” in natural language predates the meaning of “and” used in logics and set theories

Yes and it's usually very hard to summarize what words can mean in different contexts, therefore it's usually harder to learn natural languages than programming languages. For example, in a programming language "while you're out, pick up some milk" would be an infinite loop. I think this is why Alexa, Google Assistant, Siri and many more are only finding usage for the simplest of tasks.

Re:If-then-else had to be invented by edflsafoiewq on Sunday December 13, 2020 @12:03PM (#25407997)
"(Women were present) and (children were present)"
Re:If-then-else had to be invented by chalst on Sunday December 13, 2020 @12:24PM (#25408176)
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 by XorNot on Sunday December 13, 2020 @09:54PM (#25413016)
Isn't this basically proper nouns implicitly creating a set of size 1?
Re:If-then-else had to be invented by linuxrebe1 on Sunday December 13, 2020 @12:20PM (#25408143)
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 by patmorgan23 on Sunday December 13, 2020 @12:32PM (#25408257)
Isn't OR in most languages non exclusive? If you want exclusive OR you use XOR.
Re:If-then-else had to be invented by tel on Sunday December 13, 2020 @11:01AM (#25407423)
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) }.
Re:If-then-else had to be invented by powersnail on Sunday December 13, 2020 @12:46PM (#25408387)
> 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 by drdeca on Sunday December 13, 2020 @02:31PM (#25409370)
But they are in the intersection of "entities that can read" with "entities that can write".
Re:If-then-else had to be invented by dragonwriter on Sunday December 13, 2020 @06:11PM (#25411423)
Yes having attributes containing the union of the sets of attributes {“can read”} and {“can write”} means being in the intersection of the set of things having the attribute “can read” and that having the attribute “can write”. Set union, intersection, and membership are related that way.

(Which means saying that “and” is about intersection and not union is nonsense, everything statement about set union can be rephrased to an equivalent statement about intersection, and vice versa.)

Re:If-then-else had to be invented by drdeca on Sunday December 13, 2020 @07:12PM (#25411876)
Yeah, there's some duality there. If each predicate is identified with the set of things that satisfy that predicate, then the "and" of two predicates is identified with the intersection of the sets that satisfy the two predicated. On the other hand, if you instead use predicates by talking about the set of predicates that objects satisfy, then saying that something satisfies one set of predicates, and satisfies some other set of predicates, then that says that the thing satisfies all the predicates in the union of those two sets.

For some relation R between elements of the set X and elements of the set Y (we can think of X as being the set of individuals, and Y as being a set of elementary unary predicates), for each x in X, we can refer to A(x) := {y in Y : x R y} , and for each y in Y we can talk about B(y) := {x in X : x R y} . When we say (x_1 R y_1) && (x_1 R y_2), this is equivalent to both (x_1 in B(y_1)) && (x_1 in B(y_2)) i.e. (x_1 in (B(Y_1) intersect(B(y_2)))) , and also to (y_1 in A(x_1)) && (y_2 in A(x_1)) , i.e. ({y_1} \subset A(x_1)) && ({y_2} \subset A(x_1)) i.e. (({y_1} union {y_2}) \subset A(x_1)) .

Personally, if we are talking about a single x_1, and we are saying "and" about a number of different y_1 , y_2 , etc. , or if we are talking about each x in some collection but are saying the same thing about each of them, namely that for each x in the collection, that x R y_1 and that x R y_2 and that x R y_3 , I think it seems more natural to take the first of the two framings described above. That is, I think it seems more natural to say that for each x in the collection, that x \in (B(y_1) intersect B(y_2) intersect B(y_3)), rather than saying that ({y_1} union {y_2} union {y_3}) subset A(x) .

Or, if we give the name W to the collection we are talking about, we could say that "W subset (B(y_1) intersect B(y_2) intersect B(y_3))". This seems to me a fairly natural way to say "all the W , y_1 , y_2, and y_3" ("each of my 3 pokemon can do reading, writing, and arithmetic") .

The other way would end up more like, "({y_1} union {y_2} union {y_3}) subset (the intersection over all x in W, of A(x))".

This works, but seems less natural to me.

Also, especially in the case where you expect X to be substantially larger than Y.

Re:If-then-else had to be invented by gerdesj on Sunday December 13, 2020 @05:29PM (#25411041)
"I have three Pokémons. They can read and write." cf: I have three Pokémons that can read and write.

Now, thanks to what I can only describe as the implicit vagaries of English, the bounding (three) might now imply that I have three ... or more Pokémons! To make that sentence precise: I have three Pokémons and they can read and write. Here I am substituting and for a full stop (period.) When I deployed "that" I managed to muddy the waters.

Mapping logical and Boolean operators to grammatical constructs is tricky and should not be taken lightly. Best to consider them separately. AND is not and (except when it is!)

Be careful out there kids.

Re:If-then-else had to be invented by remram on Sunday December 13, 2020 @11:23AM (#25407634)
It depends if you consider the implied set to be the people (of which there are readers and writers) or the capabilities (reading and writing).
Re:If-then-else had to be invented by phkahler on Sunday December 13, 2020 @01:18PM (#25408703)
>> Set union: they can read and write’

>> Set intersection: my jeans were creased and dirty

IMHO those are both unions. One describes two capabilities people have while the other describes two conditions some clothing has.

They both become intersection when using the pair of conditions as selection or decision criteria.

It's the difference between an assertion and a question.

Re:If-then-else had to be invented by _emacsomancer_ on Sunday December 13, 2020 @12:59PM (#25408512)
To join like constituents, not just clauses, as per your examples.
Re:If-then-else had to be invented by Toenex on Sunday December 13, 2020 @11:14AM (#25407546)
It's surprising how often you can replace 'but' with 'and' in a sentence.
Re:If-then-else had to be invented by thaumasiotes on Sunday December 13, 2020 @03:17PM (#25409810)
Why is that surprising? They have exactly the same meaning; the difference is that 'but' additionally carries information about the subjective point of view of the speaker. (Where 'and' indicates that two things are true, 'but' indicates that (1) two things are true; and (2) the speaker considers this surprising or anticipates that the listener might find it surprising.)
Re:If-then-else had to be invented by jfoutz on Sunday December 13, 2020 @11:45AM (#25407812)
coordinating conjunctions are wierd. and, or, for, but, yet, so, nor. Nor is sort of an oddball there, since it continues negated clauses, well I use it to. - my jeans were neither creased nor dirty. Yet fits in a ton of places as well.
Re:If-then-else had to be invented by fouronnes3 on Sunday December 13, 2020 @10:35AM (#25407226)
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.

Re:If-then-else had to be invented by csicseri on Sunday December 13, 2020 @12:52PM (#25408441)
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?"). The first case is pronounced with primary stress on the first syllables of both "pizza" and "pasta," and with a high tone on "pizza" and a low tone on "pasta," indicating a contrast between the two alternatives. The second case is pronounced with primary stress on the first syllable of "pizza," secondary stress on the first syllable of "pasta," and a uniform tone over the phrase "pizza or pasta" on which is superimposed the rising tone on the last syllable of the sentence indicating a yes/no question. (To see that the latter is true, add "tonight" to the yes/no sentence - "would you like to eat pizza or pasta tonight?" The tone does not rise until the syllable "night.")

You have to be very careful in reasoning about natural language based solely on the written record, since spoken language regularly includes features, such as the suprasegmentals (stress and intonation) in the above examples, that aren't recorded in the orthography.

Re:If-then-else had to be invented by a1369209993 on Sunday December 13, 2020 @02:49PM (#25409519)
The first one is not exclusive-or, though: if you wanted to eat pizza and pasta, you would not answer "no" to "Do you want to eat pizza or pasta?", you would answer "both". Rather, "or" is serving as a inclusive-or with (perhaps) the incidental implication that picking more than one doesn't make sense in the first place.
Re:If-then-else had to be invented by mantap on Sunday December 13, 2020 @05:45PM (#25411176)
Do you want to eat pizza and garlic bread? - inclusive

Do you want to eat pizza or garlic bread? - exclusive

In natural language "and" works like a inclusive or. If there is pizza and garlic bread I can choose to eat one or both. Or is always exclusive in this sentence.

Re:If-then-else had to be invented by tsimionescu on Monday December 14, 2020 @06:21AM (#25415779)
With minor modifications, it can become inclusive or:

Do you want to eat some pizza or some garlic bread? - probably inclusive or

Also, I would interpret the first question as "addition" (pizza with garlic bread, on the model of mac and cheese), not as an inclusive or.

Re:If-then-else had to be invented by bryanrasmussen on Sunday December 13, 2020 @04:43PM (#25410602)
>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 by benibela on Sunday December 13, 2020 @05:25PM (#25411017)
He should have given you peanut butter, and a cheese sandwich
Re:If-then-else had to be invented by MaxBarraclough on Sunday December 13, 2020 @12:45PM (#25408381)
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 by DaiPlusPlus on Sunday December 13, 2020 @01:47PM (#25408970)
VB.NET also uses “OrElse” and “AndAlso” for short-circuiting. VB6 didn’t support short-circuiting at all.
Re:If-then-else had to be invented by MaxBarraclough on Sunday December 13, 2020 @05:53PM (#25411249)
Good example, I'd forgotten about that.

On second thought I was mistaken about the example I gave. If someone says You can have tea OR coffee they're really expressing a NAND. You can have at most one out of the two options. Unlike with XOR, you're permitted to have neither.

To express XOR, you'd need to say You must have tea or coffee.

Re:If-then-else had to be invented by gpderetta on Sunday December 13, 2020 @11:16AM (#25407560)
Latin has both in inclusive ('vel') and exclusive ('aut') or.
Re:If-then-else had to be invented by hutzlibu on Sunday December 13, 2020 @11:38AM (#25407760)
"This is of course related to why the famous joke "Is it a boy or a girl? Yes." is so hilarious"

Only to IT people though. Common folks will just look at you in a weird way...

Re:If-then-else had to be invented by still_grokking on Sunday December 13, 2020 @02:54PM (#25409564)
Except the folks are mathematicians.

But in this case there is actually a slight chance that nobody recognizes this as a joke at all...

Re:If-then-else had to be invented by hutzlibu on Monday December 14, 2020 @06:34AM (#25415870)
I knew that someone would point that out..

But I figured most mathematicians are IT people, too. But there is at least also a third group: philisophers. They have formal logic, too (in university), but seldom math.

So in the spirit of the joke:

"Only to IT people though. "

Would have to be:

"Only to IT people and/or math people and/or philosophers, though. "

Desire for formal correctness satisfied?

Re:If-then-else had to be invented by etripe on Monday December 14, 2020 @09:20AM (#25417807)
It can also be used as the equivalent to a try/catch statement in most Germanic languages (including English, though Ingveonic, really) when ending a sentence with it.

"Do you like pizza, or?"

Depending on the exact statement, you might catch more or less flak.

Re:If-then-else had to be invented by cgriswald on Sunday December 13, 2020 @11:22AM (#25407619)
> "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."

Re:If-then-else had to be invented by rvense on Sunday December 13, 2020 @12:04PM (#25408007)
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 by cgriswald on Sunday December 13, 2020 @12:13PM (#25408081)
>> 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 by potiuper on Sunday December 13, 2020 @11:53AM (#25407905)
What is wrong with a yes response to "do you want to eat pizza or pasta?" with yes implying that one would be willing to eat either rather than requiring an exclusive preference that could be asked with "either" before pizza? Similarly with the boy or girl question, "no" may be stillborn.
Re:If-then-else had to be invented by combatentropy on Sunday December 13, 2020 @06:10PM (#25411416)
> What is wrong with a yes response to "do you want to eat pizza or pasta?"

It doesn't answer the question. The questioner is asking for your help in making a decision. If you are completely neutral about the two, then most people answer with the phrase, "Either one is fine". Saying just "yes" sounds like you misunderstood the question --- unless you say it with a wry smile, showing that you mean to be funny in your answer.

(I suppose occasionally someone could ask the question with a different inflection, with the last word at a higher pitch, meaning, "Are either of these fine with you?" rather than, "Please pick one.")

> Similarly with the boy or girl question, "no" may be stillborn.

The sex is set at conception.

Re:If-then-else had to be invented by tsimionescu on Monday December 14, 2020 @06:31AM (#25415844)
Completely off topic, but this is a pet peeve of mine:

> > Similarly with the boy or girl question, "no" may be stillborn.

> The sex is set at conception.

Not necessarily - at conception, the cells could be XX, XY, but also XXY (not to mention, they could be X- or -Y). After conception, chymerism could occur, where XX and XY twins become conjoined and a single fetus develops having both XX and XY chromosomes in different parts of the body - the sex will mostly be determined by which DNA is used when forming the gonads. It could also end up developing both kinds of gonads. But even if the fetus develops testicles, there is a chance that it has some kind of testosterone resistance and ends up with a completely female phenotype. Of course, there is also a possibility that no gonads are developed. This is all staying well in the realm of biological sex, and disregarding other hormonal complications that could happen based on what the mother is doing and her health, and disregarding any morphological abnormalities that could cause surface-level confusion between biologically male and female sexual organs.

Re:If-then-else had to be invented by combatentropy on Monday December 14, 2020 @11:05AM (#25419080)
These are edge cases, abnormalities. Do you have this pet peeve with other topics? ("If you press the gas pedal, the car will accelerate --- unless you're out of gas, the fuel line is broken . . . ")
Re:If-then-else had to be invented by u801e on Sunday December 13, 2020 @11:25AM (#25407647)
One way to make the or inclusive is to use the construct and/or.
Re:If-then-else had to be invented by nmg on Sunday December 13, 2020 @04:34PM (#25410519)
This may be why interrogative programming never caught on.
Re:If-then-else had to be invented by lou1306 on Sunday December 13, 2020 @01:38PM (#25408892)
> For example, it's more likely you'll say something like 'give candy to these kids' or 'wash these cars'

That's one of the reasons I like functional programming. In ML-style languages you have something like `Set.map giveCandy kids`, which is both concise and close to natural language.

Comprehensions are also cool in my book, because they're very close to set-builder notation.

Re:If-then-else had to be invented by zodiac on Monday December 14, 2020 @03:06AM (#25414617)
> in natural language, 'and' usually implies set union

well, sometimes it can be syntactically ambiguous too, right?

e.g. "I welcome big and small dogs" vs "I welcome well-behaved and properly groomed dogs"

Re:If-then-else had to be invented by ilyagr on Sunday December 13, 2020 @06:27PM (#25411543)
Regarding 'and', it's just that the implied order of precedence is crucial to the meaning. Compare:

(I ate all the chocolate candies) and (I ate all the waffles)

I ate everything that was (chocolate candy and waffles).

In the first example, the intersection is in the set of things that happened. In the second, it is in the set of things.

It's merely a convention that "I ate all the chocolates and waffles" means the first of these while "I ate all the chocolate waffles" means the second.

This is similar to how even if means "power" unambiguously, 2 3 5 doesn't mean one thing until you put parentheses in (explicitly or by convention).

Re:If-then-else had to be invented by m463 on Sunday December 13, 2020 @04:54PM (#25410727)
I like the use of language in perl and wish it was more prevalent in other languages.

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

Re:If-then-else had to be invented by hnick on Sunday December 13, 2020 @06:43PM (#25411666)
Yes it's a weird feature but I found myself drawn to it. Just like with natural language, sometimes the 'unless' keyword feels like a better fit.

Both keywords work in postfix form, and this is how I usually use 'unless' so it reads more like a sentence.

  do_thing() unless ($a == 1);
  do_thing() if ($a != 1);
Re:If-then-else had to be invented by Can_Not on Sunday December 13, 2020 @09:27PM (#25412854)
This is valid in crystal:

    unless a
        a = 4
    end
    return x unless y
    return z
Re:If-then-else had to be invented by SilasX on Sunday December 13, 2020 @01:45PM (#25408956)
> For example, it's more likely you'll say something like 'give candy to these kids' or 'wash these cars' than 'give a piece of candy to each kid' or 'wash each of these cars.

True but for more complex instructions, it’s common to say “do these things for that kid, then do that for all the kids”, which is pretty much a for loop. I can’t speak to how common this was in lay speech before programming was common though.

(There was an earlier thread about this but algolia’s search UI suddenly became a pain to use on mobile and it’s too tedious to find.)

Re:If-then-else had to be invented by proverbialbunny on Sunday December 13, 2020 @12:56PM (#25408471)
>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.

Wasn't that the goal of Perl? It was inspired from natural language first, not inspired from another programming language first. This is why it's so quick and easy to prototype in it, arguably far easier than any other language. I believe it is the only programming language to be inspired from natural language first.

Re:If-then-else had to be invented by wildmanx on Sunday December 13, 2020 @02:42PM (#25409451)
This use of "and" and "or" was inherited from mathematical logic though. It's not specific to programming languages.
Re:If-then-else had to be invented by alentist on Sunday December 13, 2020 @10:04PM (#25413077)
What you're describing seems to come down to the identity

(((w ∨ c) → a) ↔ ((w → a) ∧ (c → a)))

That is, an implication whose antecedent is a disjunction is a conjunction of implications. On the other hand,

((a → (w ∨ c)) ↔ ((a → w) ∨ (a → c)))

That is, an implication whose consequent is a disjunction is a disjunction of implications.

Re:If-then-else had to be invented by laumars on Sunday December 13, 2020 @11:38AM (#25407759)
Interestingly your index based loop example is the opposite of how shell scripting works. That is a lot more like a human language in its construct:

   candy | kids
Where candy and kids are self contained programs that already understand the operations which make up candy and kids.
Re:If-then-else had to be invented by still_grokking on Sunday December 13, 2020 @02:40PM (#25409440)
> it's more likely you'll say something like 'give candy to these kids' or 'wash these cars' than 'give a piece of candy to each kid' or 'wash each of these cars'.

Reminds me of APL.

But I'm not sure APL can be considered being close to natural language.

Re:If-then-else had to be invented by thomasahle on Sunday December 13, 2020 @01:51PM (#25409004)
In fact, when propositional logic was first formalised [1] George Boole gave "and" and "or" the same meaning, denoted by the symbol "+".

[1]: https://t.co/nBYXLPidoS?amp=1

Re:If-then-else had to be invented by gallerdude on Sunday December 13, 2020 @12:36PM (#25408297)
What is the name of the paper?
Re:If-then-else had to be invented by abhinav22 on Sunday December 13, 2020 @02:31PM (#25409364)
I really want to know too
Re:If-then-else had to be invented by yiyus on Monday December 14, 2020 @06:30AM (#25415839)
> we usually describe operations on sets as taking the whole set as an argument, not in terms of what happens with each individual member.

That's something that array languages did right.

Re:If-then-else had to be invented by k__ on Sunday December 13, 2020 @11:20AM (#25407600)
"we usually describe operations on sets as taking the whole set as an argument, not in terms of what happens with each individual member"

Doesn't R do it like that too?

Re:If-then-else had to be invented by gnramires on Monday December 14, 2020 @01:03PM (#25420858)
There's javascript's foreach, which also gives an optional index. Indices are important to uniquely identify members in case you want non-uniform behavior: for example, "give 3 kinds of candy alternatingly"; element variables in turn are important for behavior that's a function of the member, say when you want to "give candy in proportion to their age".
Re:If-then-else had to be invented by dragonwriter on Sunday December 13, 2020 @01:30PM (#25408821)
> For example, 'women and children' means of course 'if X is a woman OR X is a child'.

Well, no, “women and children” alone doesn't mean that, “if X is a member of women and children” means “if X is in women OR X is in children”.

But that's consistent with AND and OR as boolean operators in programming (it's inconsistent with the way &-and-| symbols are used as set operators in some programming languages, though; ∪ and ∩ would be better, but aren't in ASCII.)