9 ms·
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 construc
by tsimionescu 6y ago
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.
- fouronnes3 6y agoGreat 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.
- gpderetta 6y agoLatin has both in inclusive ('vel') and exclusive ('aut') or.
- cgriswald 6y ago> "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."
- rvense 6y agoI'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.)
- cgriswald 6y ago>> 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.
- u801e 6y agoOne way to make the or inclusive is to use the construct and/or.
- hutzlibu 6y ago"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...
- still_grokking 6y agoExcept the folks are mathematicians. But in this case there is actually a slight chance that nobody recognizes this as a joke at all...
- hutzlibu 6y agoI 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?
- potiuper 6y agoWhat 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.
- combatentropy 6y ago> 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.
- deleted 6y ago[deleted]
- tsimionescu 6y agoCompletely 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.
- MaxBarraclough 6y agoTo 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#Short-circuit_control_forms https://en.wikibooks.org/wiki/Ada_Programming/Operators#Shor...
- DaiPlusPlus 6y agoVB.NET also uses “OrElse” and “AndAlso” for short-circuiting. VB6 didn’t support short-circuiting at all.
- MaxBarraclough 6y agoGood 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.
- csicseri 6y agoIf 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.
- a1369209993 6y agoThe 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.
- bryanrasmussen 6y ago>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.
- benibela 6y agoHe should have given you peanut butter, and a cheese sandwich
- 6y ago
- nmg 6y agoThis may be why interrogative programming never caught on.
- etripe 6y agoIt 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.
- powersnail 6y agoThe 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.
- tel 6y agoHow 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) }.
- remram 6y agoIt depends if you consider the implied set to be the people (of which there are readers and writers) or the capabilities (reading and writing).
- powersnail 6y ago> 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
- drdeca 6y agoBut they are in the intersection of "entities that can read" with "entities that can write".
- dragonwriter 6y agoYes 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.)
- k__ 6y ago"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?
- gnramires 6y agoThere'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".
- laumars 6y agoInterestingly 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.
- gallerdude 6y agoWhat is the name of the paper?
- abhinav22 6y agoI really want to know too
- proverbialbunny 6y ago>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.
- dragonwriter 6y ago> 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.)
- lou1306 6y ago> 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.
- SilasX 6y ago> 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.)
- thomasahle 6y agoIn 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 https://t.co/nBYXLPidoS?amp=1
- still_grokking 6y ago> 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.
- wildmanx 6y agoThis use of "and" and "or" was inherited from mathematical logic though. It's not specific to programming languages.
- m463 6y agoI 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.
- hnick 6y agoYes 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);
- Can_Not 6y agoThis is valid in crystal: unless a a = 4 end return x unless y return z
- ilyagr 6y agoRegarding '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).
- alentist 6y agoWhat 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.
- zodiac 6y ago> 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"
- yiyus 6y ago> 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.