News for hackers. Stuff that matters.
Re:Why does `True == False is False` evaluate to False in Py... by stinos on Saturday May 02, 2020 @02:24AM (#23049771)
One of the comments lays out why I probably never use things like this: And this is exactly why I tend to wrap compound logical comparisons in parens, I simply can't remember the syntax across all the languages I use, and it's not worth the risk of leaving them off and having unexpected behavior

Apart from unexpected behavior it is also about readability: with parentheses in place you can just read left-to-right and the parsing overhead is minimal. Without them though, you have to read almost everything first, parse what is there, figure out what comes first (and hope you remembred it correctly), then read again to get a mental image of what is actually going on.

Re:Why does `True == False is False` evaluate to False in Py... by ghaff on Saturday May 02, 2020 @07:53AM (#23051202)
Whether it's computer languages or human ones, as soon as you get into a discussion about the correct parsing of a statement, you've lost and need to rewrite in a way that's unambiguous. Too many people pride themselves on knowing more or less obscure rules and, honestly, no one else cares.
Re:Why does `True == False is False` evaluate to False in Py... by collyw on Saturday May 02, 2020 @08:59AM (#23051498)
This. I got asked an interview question that involved writing two list comprehensions in python in an interview. The guy then asked if I could do the same without the intermediate variable - basically nesting them. I had a mental block for a bit before I realised how simple the task was. It just that I would never think to nest list comprehensions because I find it horribly unreadble.
Re:Why does `True == False is False` evaluate to False in Py... by kwhitefoot on Saturday May 02, 2020 @12:29PM (#23052773)
> if I could do the same without the intermediate variable

I'm glad I never had to go through such ridiculous hoops to get a job.

If I had I might have been inclined to say "Yes I could but I wouldn't do it because it would be unmaintainable."

Real application programming isn't about being concise it's about being cost effective. Sometimes conciseness achieves that end often it does not. Having a well named intermediate variable can help document what is happening so that the poor sod who has to fix a bug in or extend your code two years later doesn't have to spend an hour deciphering your code to apply a two minute fix. That poor sod might be the very same person who wrote it.

Re:Why does `True == False is False` evaluate to False in Py... by rohan1024 on Saturday May 02, 2020 @10:10AM (#23051874)
I was a Java developer for more than 4 years at the beginning of my career. I was more of application developer than language expert so I did not know about nooks and crannies of the language. But that is exactly what was being asked in interviews and was never able to crack those interviews.

I liked Go and used to work on it in my personal time. Go's way of doing things is usually one way so there are not many things you have to remember about language. I applied for a job of Go and I landed that one. Of course, at that time very few Go developers were there in market so that could be a good reason for me landing that job as well.

Re:Why does `True == False is False` evaluate to False in Py... by rhizome on Saturday May 02, 2020 @02:23PM (#23053778)
It's about elegance, you see.

num%3 == 0 ? num%5 == 0 ? "fizzbuzz" : "fizz" : num%5 == 0 ? "buzz" : num

Re:Why does `True == False is False` evaluate to False in Py... by lonelappde on Saturday May 02, 2020 @09:14AM (#23051589)
This starts in elementary school when the the cargo cult that is math pedagogy teaches the terrible "order of operations", instead of teaching students to use clear unambiguous syntax.
Re:Why does `True == False is False` evaluate to False in Py... by horsawlarway on Saturday May 02, 2020 @09:48AM (#23051765)
Math in general is incredibly sloppy with this. I believe it's similar to why churches only read the bible in latin - There's a sort of perverse incentive in keeping arcane symbols around that make the life of the practitioner easier at the expense of the lay-person.

Most formulas students need to learn are actually quite intuitive when you replace the symbol with a one or two word description. But they'd rather force you to memorize the symbol.

It's like forcing you to read obfuscated code. I find it draining with zero benefit to most learners.

Re:Why does `True == False is False` evaluate to False in Py... by cgriswald on Saturday May 02, 2020 @10:50AM (#23052092)
Math is first and foremost a language, whose symbols are generally well-defined, although they differ between contexts in some cases. In many of those differing contexts, the symbols are re-used to give an intuitive sense. For example, re-using "x" for cross product.

Reducing math to words means English math is different from Chinese math. If I, a native English speaker, were to look at such math, I would have to more or less take it on faith that the translation I'm reading is accurate. And god forbid I'm trying to read a translation of a work done jointly by (say) a Romanian and a Chinese.

The symbols generally remove ambiguity. Consider the English word "bi-weekly." It's so muddied that it is almost useless. It means either twice a week or once every two weeks. It means, literally, both multiplication and division; and context is rarely helpful for this particular word.

You can certainly use the symbols poorly and ambiguously, as many viral "Solve this math problem!" memes exemplify. But used properly they're generally clear, concise, and well-defined.

I do, however, have one nitpick about symbols, and that's with the use of the ellipsis in math. You'll often see things like {1, 2, ..., n} which is generally intended to mean (say) the natural numbers up and including to n. But does it? Couldn't it also represent powers of 2? Or the set of fibonacci numbers? And since it is a set, order doesn't matter. Almost anything at all could be in that set. We can only be sure it's not something like "all the odd numbers" because 2 is in the set. Frustratingly, it's not even necessary in most cases, since we have set-builder notation and other tools.

Re:Why does `True == False is False` evaluate to False in Py... by horsawlarway on Saturday May 02, 2020 @11:34AM (#23052315)
Sure, but this is also exactly why latin was used for as long as it was - It was a language that the educated elites from many different and diverse countries used as a command ground.

I'm not saying that math shouldn't be using symbols, I'm saying it's near intentionally hostile to those first picking up the subject. If the goal of math education is to provide the groundwork of understanding to the general populace... Cater to the general populace. The vast majority of those folks are not going to be discussing complex math across several languages.

They're going to be using it for accounting, taxes, construction, cooking, etc. They don't need to memorize an entire language to do that effectively, and we shouldn't be wasting their time in school trying to make them.

Those that choose to specialize are welcome to. In my opinion that doesn't justify the use of specialized language in basic education settings.

Re:Why does `True == False is False` evaluate to False in Py... by cgriswald on Saturday May 02, 2020 @11:58AM (#23052488)
Can you give an example of which symbols you object to and what you anticipate as a replacement? The most difficult things I can think of that someone doing accounting or cooking might have to do is compound interest or converting units; so we're talking about ()+-x÷ and exponents. I'm guessing you have something else in mind or I'm not getting it.

I do have criticism with symbols insofar as math is taught which roughly fall in line with "A Mathematician's Lament" by Paul Lockhart[0]. Loosely, that much math is taught as symbol manipulation rather than... actual math. But that's not a problem with the symbols themselves so much as with their use to obfuscate what's actually being done mathematically.

You might be interested in the book Burn Math Class by Jason Wilkes [1]. I don't really recall what his arguments against symbols were. He ends up inventing his own notation as he goes along (which is what ultimately turned me off the book about halfway through -- it just became an exercise in translating notation for me).

[0] - https://www.maa.org/external_archive/devlin/LockhartsLament....

[1] - https://www.amazon.com/Burn-Math-Class-Reinvent-Mathematics-...

Edit: Fixed list of links.

Re:Why does `True == False is False` evaluate to False in Py... by horsawlarway on Saturday May 02, 2020 @12:30PM (#23052782)
I think you're vastly over estimating the capability of many students (particularly young students without previous exposure).

It's easy to fall into a trap where you forget what it's like to be completely new to a subject. It's particularly hard when you tend to surround yourself in educated communities where this "in-knowledge" becomes assumed and standard (eg hacker news).

Take just less than ( < ) and greater than ( > ). Think about how many stupid rhymes or memorization techniques you see in classrooms to help learners memorize which is which.

Here are three separate sites, with an entire page dedicated to helping students remember which is which:

https://math.wonderhowto.com/how-to/remember-greater-than-le...

https://numberock.com/lessons/comparing-numbers-to-100/

https://myhomeworkdone.com/blog/greater-than-less-than-sign/

One of them includes a whole damned song for the purpose. All to avoid writing out smaller/bigger.

Like any language, once you learn it's hard to remember all the places you struggled.

Why make "change" Δ

Why make "square root of -1" i

In how many classes do we see rote memorization of the quadratic formula, with no context around why you should even bother to learn it? (I've seen quite a few).

Now, not all of those are really the fault of the language (math), but using the language for each of those problems facilitates lazy teaching, and it changes the goal from "understand how math relates to the world" to "memorize this language construct". One is much more helpful than the other.

Re:Why does `True == False is False` evaluate to False in Py... by pinusc on Saturday May 02, 2020 @02:38PM (#23053894)
Because once you learn it, notation gets out of the way rather than in the way. I can't imagine doing physics and having to write out words rather than symbols to express rates of change.

It makes sense that specific knowledge uses specific language to be more easily used and manipulated. Imagine writing (or even proving) Euler's equation without using i or pi or e. Imagine what mess math would be if we never used Greek symbols.

Sure, it would be easier for middle schoolers. But if you're arguing that we should make it easier for them since they're not gonna need ease of manipulation for math that they're not gonna use... Then just do the teach it to them. Maybe middle schoolers don't need < as a concept any more than they need it as a symbol.

But if you're going to solve equations and inequalities, then yeah, you need = and <. Everything else would be needlessly verbose and get in the way of actually manipulating concepts you know.

Re:Why does `True == False is False` evaluate to False in Py... by cgriswald on Sunday May 03, 2020 @10:57AM (#23059371)
I've tutored many college students (of various ages) in basic algebra, almost all of whom were convinced they couldn't ever possibly learn it, and only one of whom didn't end up getting an A in their course. I'm pretty aware of the struggles some students can have with it and none of them really had trouble memorizing the handful of symbols that are actually used at that level. Some struggled with the concept of a variable, but many just struggled with understanding the relationship between the actual concepts and the manipulation of symbols. Off the top of my head, equations being balanced can be a difficult one, but certainly not the only one.

As for younger students, I have much less experience, but some; and it's interesting you mentioned less than and greater than; since I actually remember learning those symbols. We learned that the "alligator" always eats the "bigger" number. It's not surprising there are countless ways of learning it, including song. That's true of almost any abstract concept. The idea is to link a metaphor the person understands to the abstract concept. Not every metaphor will work for every person; and this is true of all abstract concepts, not just math symbols.

Of course, it's not actually true that the alligator is eating the "bigger" number, and it actually demonstrates why we need the symbols. ">" and "<" actually refer to "greater than" or "less than" which we much later learned is a way of saying "which number is further right on the number line"; which, of course, requires the abstract concept of the number line and accepting the more-or-less arbitrary decision of a left-to-right number line. "Bigger" means "has a greater distance from zero on the number line in either direction" which we'd represent as a comparison of absolute values. I don't recall when I learned about absolute values, but it was definitely years after learning about < and >. Using the proper symbols lets us be explicit, concise, and precise and avoid issues like using English synonyms (bigger, greater) or whatever pitfalls exist in other languages.

The choice of symbols < and > are, of course, largely arbitrary other than the symmetry between them. (We could have, for instance, always put the greater number underneath the smaller number so the structure is more stable in an imaginary gravity; but that, too, would be arbitrary.) But so is the letter S, or the number 9. They're all arbitrary symbols that have particular meanings in particular languages. "9" is interesting, because it's a number, versus the Roman numeral system. The Roman numeral system could arguably be called non-arbitrary. "I" clearly represents a single thing, "II", two things, etc. That works until you get up to "IV". What? "IV"? So if a lesser value is in front of a greater value, you subtract it? And how does "V" represent five anyway? It's arbitrary! But the Romans found it much more useful to be able to write VII + VI = XIII rather than IIIIIII + IIIIII = IIIIIIIIIIIII, which can pretty quickly get unruly. Turns out, memorizing digits 0-9 makes it (and more complex math) even easier: 7 + 6 = 13; which is why the entire world uses numbers instead of numerals.

(We could also have a side-discussion on why base 10 and not something like base 12, binary, a mixed radix system that uses the prime numbers or the sexagesimal system used by the Sumerians. The answer is basically that its mostly arbitrary, simpler than some systems, and we have ten fingers/thumbs.)

> Why make "change" Δ

> Why make "square root of -1" i

Largely historical reasons, expediency, and lack of better alternatives. Why represent the sound "ssss" with the symbol "s"?

You could swap i for √-1 and people would understand you, but you'd very quickly wish there was a shorthand that you could use to represent this rather special value.

> In how many classes do we see rote memorization of the quadratic formula, with no context around why you should even bother to learn it? (I've seen quite a few).

You won't see me objecting to this; but this is not an issue with mathematics. It is an issue with teaching mathematics and is part of the "lament" I linked to above. This is quite a different issue than the issue of symbols. The symbols, while arbitrary and arcane, actually make the mathematics more manageable and precise. Saying that "facilitates laziness" is like saying a clothes washer facilitate laziness since it removes the need to manually provide friction and agitation. It's true, in a sense, but I'll keep my washer.

Mathematics is taught very poorly in many places; but making it hopelessly complex and less precise by removing the symbols of the language is not going to help. I learned algebra, officially, my freshman year of high school. Yet there are many high school graduates who come out of high school not even having a rudimentary understanding of algebra (and, actually, even basic mathematics - tutored a few of those as well). Many of them learn it in college, so they're obviously capable of learning it. Those high schools failed those students. Many university professors equally fail their students.

But blaming this on the symbols of the language is too far of a stretch for me. Blame the teachers.

Edit: Fixed display of symbols.

Re:Why does `True == False is False` evaluate to False in Py... by viraptor on Saturday May 02, 2020 @09:51PM (#23056270)
> Couldn't it also represent powers of 2?

You'd use a different notation then. `{1, 2, 4, ..., n^2}` or `{2^0, 2^1, ..., n}` or something similar which indicates what you mean. There's nothing wrong with elipsis, if you spend a second thinking about what you're writing.

If someone wanted to be obnoxious and confusing then they could say: Haha, `n` is not a symbol either; I'm using base-50 and it's digit 23(10). So you can't really stop bad / intentionally misleading communication.

Re:Why does `True == False is False` evaluate to False in Py... by cgriswald on Sunday May 03, 2020 @11:24AM (#23059531)
Like I said, it’s a nitpick. I can know what a person means most of the time, but it’s imprecise and technically the ellipsis can be almost anything depending on the explicit values/symbols. In the cases where the pattern is clear it’s clear. Where it’s not, using proper set builder notation in the first place would have made it clear. I’ve also seen it used in contexts other than sets, including for summations. In those cases often just having the summations in proper form can make consequences and manipulations plainer and easier.
Re:Why does `True == False is False` evaluate to False in Py... by ghaff on Saturday May 02, 2020 @10:06AM (#23051858)
In general, at least through high school, probably way too much teaching involves basically memorization of trivia.

Yes, some foundations of facts are needed. For example, there's some very basic operator precedence that students should internalize. And history inevitably does involve names and dates. But too much attention is probably devoted to remembering whether a battle was fought in 1746 or 1750.

It's somewhat understandable because testing for those things is easy and unambiguous. But it's unfortunate anyway.

Re:Why does `True == False is False` evaluate to False in Py... by jmaa on Saturday May 02, 2020 @10:31AM (#23051992)
Pedantic point: The whole "reading the bible in Latin" is a very Catholic thing (and maybe Orthodox?). The Protestant churches I've been in has read from the bible in the native tongue, and it was indeed one of Luther's criticisms of the Catholic church.
Re:Why does `True == False is False` evaluate to False in Py... by mordechai9000 on Saturday May 02, 2020 @12:01PM (#23052514)
I'm not Catholic, but I think they stopped requiring the reading of scripture in Latin around 1960 and The Second Council of Vatican, AKA Vatican II.

I think Latin is still used as part of the traditional service, but it's mostly ritualistic. What I remember from attending Catholic services years ago is a lot of standing up and sitting down while chanting in Latin, followed by a sermon delivered in English.

Re:Why does `True == False is False` evaluate to False in Py... by viraptor on Saturday May 02, 2020 @09:42PM (#23056238)
It's not universal either. I've grown up in a catholic-obsessed country and not a single mass I've been to had Latin elements or chanting. All in native language in mid 80s.
Re:Why does `True == False is False` evaluate to False in Py... by CrazyStat on Saturday May 02, 2020 @10:06AM (#23051856)
> Most formulas students need to learn are actually quite intuitive when you replace the symbol with a one or two word description. But they'd rather force you to memorize the symbol.

Can you give some examples of this?

Re:Why does `True == False is False` evaluate to False in Py... by tomp on Saturday May 02, 2020 @10:42AM (#23052052)
Literally the only thing you need to know is that * binds tighter than + and - and that * can be omitted. Everything else is obvious - I never used / but fractions instead, exponentiation is also visually indicated, the only counterexample I guess is some made up operations when doing group/ring theory but it’s all clearly explained anyways. Using “clear unambiguous syntax” as in () would actually make all formulas much longer and much less clear.
Re:Why does `True == False is False` evaluate to False in Py... by jameshart on Saturday May 02, 2020 @10:10AM (#23051875)
I genuinely think PEDMAS/BODMAS nonsense creates permanent barriers to understanding in math in some people because it inculcates an understanding of the symbols like + and - as being sequential operations, and they struggle to ever make the leap from math as ‘calculation’ to math as ‘reasoning’ as a result.
Re:Why does `True == False is False` evaluate to False in Py... by mojomark on Saturday May 02, 2020 @10:27AM (#23051970)
Concur. A long time ago I spent a full day as a professional engineer trying to figure out why a microsoft Excel formula wasn't working. Turns out that the default MS Excel order of operations was not PEMDAS, it's PE(M or D)(A or S), where 'X or X' is selected based on which operator comes next from left to right.(1) So frustrating. Always use parens.

1. https://edu.gcfglobal.org/en/excel2013/complex-formulas/1/

Re:Why does `True == False is False` evaluate to False in Py... by apricot on Saturday May 02, 2020 @11:06AM (#23052163)
Isn't that the normal way to do things? Every teacher, every textbook has always told me that multiplication and division have the same priority, as do addition and subtraction.
Re:Why does `True == False is False` evaluate to False in Py... by Dylan16807 on Saturday May 02, 2020 @10:23PM (#23056400)
Wait, so what do you think 1+2-4+8 is supposed to be? It's not negative.
Re:Why does `True == False is False` evaluate to False in Py... by dec0dedab0de on Saturday May 02, 2020 @07:16AM (#23051063)
When I have very complex logic I like to give each step its own variable. It makes it read like English.

To be honest I only actually only do this when Im working on old code and find myself trying to remember how something works.

Re:Why does `True == False is False` evaluate to False in Py... by paulryanrogers on Saturday May 02, 2020 @10:13AM (#23051886)
IME the improvement to readability is worth the cost of a few extra assignments.
Re:Why does `True == False is False` evaluate to False in Py... by Avamander on Saturday May 02, 2020 @10:36AM (#23052022)
In the cases where they aren't worth it, you're hopefully also using a language that gets compiled and they're just optimized out.
Re:Why does `True == False is False` evaluate to False in Py... by userbinator on Saturday May 02, 2020 @02:36AM (#23049829)
On the other hand, Python is the only language I've used which has this special-case parsing. In all others, a < b < c would be parsed as ((a < b) < c) which may or may not be a type error, but it's consistent with the other binary operators.
Re:Why does `True == False is False` evaluate to False in Py... by stinos on Saturday May 02, 2020 @03:04AM (#23049945)
That actually proves my point. I'm not really good in learning certain facts by heart so if I see a < b < c it is going to take multiple seconds, likely followed by an internet search so add a couple of minutes to that, before I can be 100% sure what it does. I mean, I know what precedence is and I'd probably assume it would be (a < b) < c but that's not going to cut it.
Re:Why does `True == False is False` evaluate to False in Py... by aktuel on Saturday May 02, 2020 @03:33AM (#23050089)
Just program in assembler then.

Honestly, Python's way is the only sane way to parse this. This is how a human who never programmed before with some knowledge of math would understand it.

Everyone's else mind is just corrupted by broken legacy languages.

Re:Why does `True == False is False` evaluate to False in Py... by apricot on Saturday May 02, 2020 @11:02AM (#23052141)
I sometimes teach programming to beginners who have some knowledge of math. A common mistake they make is to write compound conditionals like this:

    if a == 2 or 3:
        do stuff
because that's how they would write it in math. Does that mean Python is broken and should support that construct as well?
Re:Why does `True == False is False` evaluate to False in Py... by edflsafoiewq on Saturday May 02, 2020 @05:14PM (#23054970)
I believe COBOL supports this.
Re:Why does `True == False is False` evaluate to False in Py... by maest on Saturday May 02, 2020 @06:29AM (#23050835)
Even if Python's way was the only sane way of doing it (view which, btw, denotes having narrow experience with programming languages), that's irrelevant. GP's point was that different languages use different rules so, unless you use brackets, you won't easily know which precedence rules get applied.
Re:Why does `True == False is False` evaluate to False in Py... by Retric on Saturday May 02, 2020 @08:10AM (#23051269)
Python’s edge cases are just as odd as every other language

  >>> a=16
  >>> a*a is a*a
  True
  >>> a=17
  >>> a*a is a*a
  False
“is”, “==“, and “=“ are all very different and none of them match their mathematical equivalents very well.
Re:Why does `True == False is False` evaluate to False in Py... by dhosek on Saturday May 02, 2020 @08:48AM (#23051443)
Not really familiar with Python. Do you know why the second statement evaluates as false?
Re:Why does `True == False is False` evaluate to False in Py... by mkl on Saturday May 02, 2020 @09:06AM (#23051543)
Small integer caching: https://wsvincent.com/python-wat-integer-cache/

The objects for small integers are built-in and static, but 17^2 is too big, and so new integer objects are created when the expressions are evaluated. "is" checks if two expressions represent the same object in memory. "==" checks for equality of values.

Re:Why does `True == False is False` evaluate to False in Py... by xen0 on Saturday May 02, 2020 @09:08AM (#23051552)
CPython keeps an array for "small value" integers (I think in the range [-5, 256]). So when Python wants 256, it'll give you a reference to the existing object. Larger numbers require a brand new object.
Re:Why does `True == False is False` evaluate to False in Py... by h8hawk on Saturday May 02, 2020 @09:09AM (#23051557)
`is` is identity comparison and in python everything is "object". It check if two variable refer to same object (location in memory) or not. So you should not expect that `a is b` for `a=1.2 , b=1.2` be true. In this case actually first expression returned True is weird. because 0-256 objects are cached and every instance of them refer to same object.
Re:Why does `True == False is False` evaluate to False in Py... by xyproto on Saturday May 02, 2020 @05:24AM (#23050523)
Math notation is just one of many possible notations, though. And math notation is not static throughout history.
Re:Why does `True == False is False` evaluate to False in Py... by aktuel on Saturday May 02, 2020 @05:42AM (#23050598)
True. But the syntax of almost all other languages are derived from the same basic math syntax we use commonly for at least since programming languages are a thing.
Re:Why does `True == False is False` evaluate to False in Py... by shkkmo on Saturday May 02, 2020 @10:53AM (#23052107)
When you use a tricky language feature to improve readability, you can just add a comment to the link some piece of documentation for that behavior. It is still a trade-off, but it saves a bit of time and whenever I come across a place where past me did this, I am always appreciative.
Re:Why does `True == False is False` evaluate to False in Py... by stinos on Saturday May 02, 2020 @11:27AM (#23052271)
Depends. For obscure behavior features, ok, for 'language features' I'm probably still going to pass. Because in this example case that would come down do

  # See stackoverflow/highlyupvoted/wtf/does/python/do/here
  # This is the same as (a < b) < c.
  x = a < b < c
whih is not clearer, not easier to parse and not faster to read and harder to maintain (leads to rot easily when variable names change) than the non-ambiguous other choice.
Re:Why does `True == False is False` evaluate to False in Py... by shkkmo on Saturday May 02, 2020 @11:40PM (#23056699)
I would have skipped that second line and just left the line with the documentation link. If you are going to provide the equivalent code in a comment, you might as well just use the equivalent code.
Re:Why does `True == False is False` evaluate to False in Py... by sushimako on Saturday May 02, 2020 @08:23AM (#23051331)
In Clojure, and I assume other lisps as well, you can use the < operator in the same fashion. By merit of prefix notation it's also unambiguous regarding precedence.

  user=> (< 1 2 3)
  true
Re:Why does `True == False is False` evaluate to False in Py... by tfigment on Saturday May 02, 2020 @09:03AM (#23051524)
I'll be honest that I'm not a Clojure user, even with context I have no idea read that. Like every other language you have to be trained to read it correctly and is not intuitively obvious to everyone.
Re:Why does `True == False is False` evaluate to False in Py... by jplayer01 on Saturday May 02, 2020 @01:05PM (#23053138)
The rules are extremely simple and easy to grasp. And once you've grasped it, you'll never have to think twice about it.

Parentheses take precedence.

The first symbol is the operator (add, subtract, sum, multiply, etc.).

Everything else is operated on from left to right.

(+ 2 5 7)

2+5+7

It's also not a Clojure thing. It applies to all Lisps or related like Scheme.

Re:Why does `True == False is False` evaluate to False in Py... by bjoli on Saturday May 02, 2020 @10:18AM (#23051920)
All maths functions where it makes sense take arbitrarily many arguments. (+ 1 2 3) = 6. (< 1 2 3) = true. Everything in function position (directly after an opening paren) is either a function you want to apply or a macro you want to expand, except in a select few forms, such as binding forms and conditionals. The syntax of scheme is remarkably simple once you know the basics.

I have programmed python for about 20 years, and I still do stupid mistakes. I grooked all the r6rs scheme syntax in 20 minutes, except for (do ...) which somehow never sticks. It is also rarely used.

I have tried to evangelize scheme enough to know some people just don't like it, but for me it instantly clicked.

Re:Why does `True == False is False` evaluate to False in Py... by edflsafoiewq on Saturday May 02, 2020 @05:35PM (#23055120)
+ and = are pretty obvious but it can still be confusing. Take not=. Does (not= x y z) mean adjacent numbers are disequal (x≠y≠z, by analogy to + and =)? Or that no two numbers are equal? Or that at least two numbers are disequal? Different lisps pick different meanings.
Re:Why does `True == False is False` evaluate to False in Py... by bjoli on Sunday May 03, 2020 @09:53AM (#23058997)
Which lisps? I think I have only ever seen that in clojure (thinking it was a bad idea), and clojure seems scared of parentheses. (not (equal? x y z)) is clearer, but suffers from the same drawback as your question.

The problem I think is that not= returns true as long as any elements are non-equal, which means it is not analogous to +. I can't speak for clojure, but this is in line with all equality predicates in scheme, negated or not. A predicate that checked if any neighbours are not equal would in true scheme spirit probably be called not-any-neighbour-equal? :)

Re:Why does `True == False is False` evaluate to False in Py... by geocar on Saturday May 02, 2020 @03:07AM (#23049953)
> In all others, a < b < c would be parsed as ((a < b) < c) which may or may not be a type error, but it's consistent with the other binary operators.

In APLish languages, it's (a<(b<c)).

Re:Why does `True == False is False` evaluate to False in Py... by h8hawk on Saturday May 02, 2020 @09:01AM (#23051515)
Julia also do this:

    julia> 2<3<4
    true
Re:Why does `True == False is False` evaluate to False in Py... by tomp on Saturday May 02, 2020 @10:45AM (#23052067)
Python follows math. Other languages made up something weird.
Re:Why does `True == False is False` evaluate to False in Py... by mFixman on Saturday May 02, 2020 @04:54AM (#23050416)
The only correct way to parse `a < b < c` for numbers is throwing a type error.

Python comes second for source code niceness, allowing you to compare numbers to booleans is common and shouldn't be.

Re:Why does `True == False is False` evaluate to False in Py... by Scarblac on Saturday May 02, 2020 @05:38AM (#23050581)
But it doesn't compare a number to a boolean. It tests whether b is between a and c, in Python.
Re:Why does `True == False is False` evaluate to False in Py... by mFixman on Saturday May 02, 2020 @08:38AM (#23051402)
What I wrote wasn't very understandable.

In most languages, like C++, a < b < c ends up comparing a boolean to an integer. This should be a type error, but isn't.

Re:Why does `True == False is False` evaluate to False in Py... by ulucs on Saturday May 02, 2020 @08:57AM (#23051489)
Something I really like in k/q is that operators have no precedence and everything is executed right to left. To take a "fast" 8th power you can just do

    c*c:s*s:x*x
with no ambiguity of parsing whatsoever.
Re:Why does `True == False is False` evaluate to False in Py... by arcticbull on Saturday May 02, 2020 @03:17AM (#23050002)
Sounds like “is” is lower precedence than ==. Nothing to see here folks, move along?
Re:Why does `True == False is False` evaluate to False in Py... by tromp on Saturday May 02, 2020 @03:25AM (#23050049)
No; it's not about precedence at all. It's about semantics of chained comparisons, which is not what you'd expect in Python.
Re:Why does `True == False is False` evaluate to False in Py... by aktuel on Saturday May 02, 2020 @03:32AM (#23050086)
The syntax works exactly like it's supposed to. "is" is an alias for "==". This kind of chained comparison makes code much more readable. This contrived example which I never encountered as a practical issue not withstanding.
Re:Why does `True == False is False` evaluate to False in Py... by scaredginger on Saturday May 02, 2020 @03:37AM (#23050111)
I think you need to brush up on Python...

>>> x = 25 * 37

>>> y = 25 * 37

>>> x is y

False

>>> x == y

True

From my understanding, '==' checks for equality and 'is' checks that the variables reference the same address.

Re:Why does `True == False is False` evaluate to False in Py... by aktuel on Saturday May 02, 2020 @06:12AM (#23050741)
OK this is truly weird:

  >>> a=16
  >>> a*a is a*a
  True
  >>> a=17
  >>> a*a is a*a
  False
WTF
Re:Why does `True == False is False` evaluate to False in Py... by chrismorgan on Saturday May 02, 2020 @06:18AM (#23050769)
CPython interns the integers between -5 and 256.

See https://stackoverflow.com/questions/306313/is-operator-behav... for some discussion and further related links.

Re:Why does `True == False is False` evaluate to False in Py... by amelius on Saturday May 02, 2020 @06:38AM (#23050885)
I guess it's ok if you are aware of it but this can be a source of bugs: let's say you're not aware of this "feature" and you are in the middle of writing some code and want to know whether A is A always evaluates to true for integers. So you fire up Python and type "10 is 10" which gives True. ...
Re:Why does `True == False is False` evaluate to False in Py... by Alphaeus on Sunday May 03, 2020 @06:54PM (#23062565)
Using 'is' on integers raises a SyntaxWarning in 3.8+
Re:Why does `True == False is False` evaluate to False in Py... by lonelappde on Saturday May 02, 2020 @09:25AM (#23051641)
That's why you should read the spec and not guess a function's definition from one example.

Otherwise you'll end up thinking that almost everything is simply an alias for constant True or 0 or Error, by popping in 0 to any operator you check.

Re:Why does `True == False is False` evaluate to False in Py... by amelius on Saturday May 02, 2020 @09:45AM (#23051739)
No. Imho, a good language designer will make it possible to learn the language incrementally without surprises. For example, a tutorial on a language should not start with "please read the spec first or you may encounter some awkward and counter-intuitive behavior in areas you thought you had already mastered".
Re:Why does `True == False is False` evaluate to False in Py... by dragonwriter on Sunday May 03, 2020 @07:01PM (#23062601)
At the Python (rather than CPython implementation) level, the explanation is “is is object identity not value equality, and there is no guarantee that equal integers share object identity.”

At the CPython level, you can explain it in terms of the particular range of small integers that are interned and thus are guaranteed within particular CPython versions to share object identity when they have value equality.

But just knowing that is identity and == is equality is mostly enough to use them correctly.

Re:Why does `True == False is False` evaluate to False in Py... by lonelappde on Saturday May 02, 2020 @09:23AM (#23051628)
Maybe also delete or reply to your previous commented in which you made strong assertions of wrong facts.
Re:Why does `True == False is False` evaluate to False in Py... by Igelau on Saturday May 02, 2020 @08:18AM (#23051300)
Maybe you should stick to assembly?
Re:Why does `True == False is False` evaluate to False in Py... by wrboyce on Saturday May 02, 2020 @03:35AM (#23050105)
“==“ is not an alias of “is”, they behave quite differently.
Re:Why does `True == False is False` evaluate to False in Py... by 101404 on Saturday May 02, 2020 @05:32AM (#23050553)
`x is y` is an alias for `id(x) == id(y)`.
Re:Why does `True == False is False` evaluate to False in Py... by sbergjohansen on Saturday May 02, 2020 @04:41AM (#23050360)
To see that this is not about precedence, evaluate the following:

  >>> True == False is False
  False
  >>> False == True is False
  False
Re:Why does `True == False is False` evaluate to False in Py... by cjhopman on Saturday May 02, 2020 @07:26AM (#23051092)
Or think about it for a moment and realize that it would be True with either precedence if interpreted as expected.

Or read the very first part of the linked page that shows:

  >>> (True == False) is False
  True
  >>> True == (False is False)
  True
Re:Why does `True == False is False` evaluate to False in Py... by collyw on Saturday May 02, 2020 @09:06AM (#23051542)
Would I be correct in avoiding "is" for any simple data types, and only using it for objects?
Re:Why does `True == False is False` evaluate to False in Py... by lonelappde on Saturday May 02, 2020 @09:27AM (#23051654)
Integers are not simple data types in python. https://docs.python.org/2/c-api/int.html#PyInt_FromLong

You'd be correct to use 'is' to mean 'is', and '==' to mean '==', following their definitions.

Re:Why does `True == False is False` evaluate to False in Py... by Scarblac on Saturday May 02, 2020 @10:28AM (#23051976)
It's idiomatic to use it for comparisons with the value `None`, which is a singleton so it's always that one.

Other than that, just don't use `is`.

Re:Why does `True == False is False` evaluate to False in Py... by sbergjohansen on Saturday May 02, 2020 @09:43AM (#23051733)
See the comment by lonelappde, but note that the example under discussion here is actually not about `is` vs. `==` either.
Re:Why does `True == False is False` evaluate to False in Py... by sbergjohansen on Saturday May 02, 2020 @08:23AM (#23051329)
Yes. By the time I realised my second example is redundant, it was already too late to edit the comment. Thanks for clarifying.