Live data from Hacker News

If-then-else had to be invented

github.com

191–200 of 255 posts

Re: If-then-else had to be invented

#192
post #124
post #33

I guess the unknown German word mentioned in the post is probably "sonst". It can be translated to "otherwise" or "else". And "wenn...dann...sonst" sounds perfectly natural in German.

Except that you’d then have to make all the operators postfix to match how German puts the verbs at the end of subordinate clauses :-p “wenn a b ==...”

ah but it's more complicated because only the main verb is at the end of the sentence, so if you need an auxiliary or you have a copular construction like "ist gleich", you need to split the verb phrase...

in fact, Germans would say (and do say, e.g. in mathematics) "wenn a gleich b" as a shorthand for "wenn a gleich b ist".

Re: If-then-else had to be invented

#193
post #129

Earlier quoted context omitted.

But they are in the intersection of "entities that can read" with "entities that can write".

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

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

#194
post #152
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.

You’ve framed it in the article and here again as a correctness issue, but it’s not a correctness issue. It’s fair to say you haven’t heard it, or that it’s uncommon today, but if you use it, it’s not wrong. And people will understand you, even if you do get a sideways glance from some people. You can use “else” without “or”, if you like. The article was fascinating, especially the historical examples from different…

> The article was fascinating, especially the historical examples from different programming languages, and I buy the plausibility of a German speaker using “else” this way... I work with German speakers and they do it all the time. From the small amount of German I know, it feels like there might be some parallel with “als”.

I‘m a native German.

It was certainly not „als“ as this translates to either „than“ as in „more than“ or „when“ as in „when I came home“.

My guess is that the original German text used „falls“ for „if“ and „sonst“ for „else“:

„falls A > 0 dann X“

„sonst Y“

Re: If-then-else had to be invented

#195
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 lean toward "if a b c" being a true primitive, due to it being one of the special forms in Lisp. This is necessary to avoid evaluating the arguments in the road-not-taken, without fexprs, and I daresay that would be a distraction at the moment.

It's also embodied in actual machine words. The actual verbiage of "if a then b else c" is clearly less important, C elides the "then" after all.

I'm presuming you mean the construct, not the happenstance of how it's spelled out, because you're clearly referring to the electron, not the word for amber-the-stone which we happened to adopt for it.

Re: If-then-else had to be invented

#196
post #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 = (f…

Not truly equivalent!

let's define `delete(file)`, which returns 0 if it successfully deletes the file, and 1 if there's an error.

ifFn(trueFn, delete('A'), delete('B')) will not do what you want it to.

Re: If-then-else had to be invented

#197

Earlier quoted context omitted.

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.

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

[deleted]

Re: If-then-else had to be invented

#199
post #152

Earlier quoted context omitted.

You’ve framed it in the article and here again as a correctness issue, but it’s not a correctness issue. It’s fair to say you haven’t heard it, or that it’s uncommon today, but if you use it, it’s not wrong. And people will understand you, even if you do get a sideways glance from some people. You can use “else” without “or”, if you like. The article was fascinating, especially the historical examples from different…

> The article was fascinating, especially the historical examples from different programming languages, and I buy the plausibility of a German speaker using “else” this way... I work with German speakers and they do it all the time. From the small amount of German I know, it feels like there might be some parallel with “als”. I‘m a native German. It was certainly not „als“ as this translates to either „than“ as in „m…

I shouldn't speculate I guess. :) Als sounds like a cognate to else, but maybe it's not related.

Looking up etymology for "else", I see it comes from old High German's "elles". https://en.wiktionary.org/wiki/else#Etymology

> „falls“ for „if“

This one is interesting in the same way that it might lead me to the wrong conclusion. Is 'falls' related to 'falsch' at all? The English 'falls' is used quite differently, though you can start to see the relationship. For example something like "this falls somewhere between the two".

Language is fascinating! I love learning about how the colloquial meanings of certain cognates between languages sometimes have rather different meanings, especially between German and English since English is a Germanic language. It illuminates the interesting path some of my everyday words evolved from, and it's often rather different than one might guess.

Re: If-then-else had to be invented

#200
One of my first jobs was using the IBM mainframe RPG III language in 1985.

About half a year in, and new language version introduced IF/ELSE statements. I was glad to finally get a semblance of modern programming, but the old RPG veterans advised against using it, since the new fancy features often didn't work so well, and anyway you can write anything you want without it.

After 14 months, my contract wasn't extended. Maybe the complaint that I could be seen sleeping at my desk sometimes were a factor.

You young kids don't know how good you have it...

Post reply on HN