1. 12
  1.  

  2. 7

    Worth noting that s-expressions avoid a lot of legibility problems discussed in the article. If we look at the first example under the “providing immediate feedback” section where traditional notation looks like:

    50.04 + 34.57 + 43.22 / 3
    

    this would be expressed as:

    (+ 50.04 34.57 (/ 43.22 3))
    

    which would be hard to confuse with:

    (/ (+ 50.04 34.57 43.22) 3)
    

    A lot of people seem to have the impression that s-expressions are harder to read than traditional syntax, but I find the opposite to be the case. With s-expressions you have simple and predictable rules that remove a lot of mental overhead around figuring out what the code is doing.

    1. 2

      Similarly just having the same precedence and associativity for everything would give you an easy-to-predict and easy-to-read syntax. This way you gain terseness, but you have to get used to the associativity of whatever mechanism you’re using, whereas s-expressions (or *shudder* XML, etc) are more portable, but require you to explicitly state the tree with more characters.

      For example, right associative:

      50.04 + 34.57 + 43.22 / 3
      

      And for the sum of everything over three, it would be:

      (50.04 + 34.57 + 43.22) / 3
      

      This is the style that APL/J/K and various languages inspired by them tend to use (they also add different precedence for certain operations that take another operation as one of their inputs, such as fold). Many people use such languages as an enhanced calculator (there are plotting utilities made for them, etc). For example, in K, where division is % and assignment is ::

      force: (6.67e-11*mymass*collidingmass)%radius*radius
      yearlybill: 12*rent+electric+internet
      

      Or with functions, where / is fold:

      force:{[m1;m2;radius](6.67e-11*m1*m2)%radius*radius}
      yearlybill:{[monthlyutilities]12*+/monthlyutilities}
      
      1. 1

        Then you get the situation that 1 * 2 + 3 and 3 + 1 * 2 mean different things, which is horrible, because people will always assume that they don’t.

        I don’t know why people have such a problem with a + b + c / 3 meaning a + b + (c / 3). It’s just something you have to get used to, it’s not really that difficult and there are much bigger problems that need solving. But if it’s really such a big deal, just make it a function \frac{a + b + c}{3} in LaTeX is good enough for mathematicians, so frac(a + b + c, 3) should be good enough for programmers.

        1. 1

          Then you get the situation that 1 * 2 + 3 and 3 + 1 * 2 mean different things, which is horrible, because people will always assume that they don’t.

          I don’t know why people have such a problem with 1 * 2 + 3 and 3 + 1 * 2 meaning different things. It’s just something you have to get used to when using a different language, it’s not really that difficult and there are much bigger problems that need solving.

          1. 2

            The universal rules of mathematical expressions create a strong precedent. People expect them to hold. They get confused when they don’t. Even if they are arbitrary.

            I’m not aware of any language anywhere in all of programming or mathematics that uses different rules and has sustained any kind of popularity. Seems like a hard requirement to ever be successful in my experience.

            1. 1

              They aren’t “universal”. See my other comment. Sustained any kind of popularity is a vacuous statement Forth is used extensively in embedded applications. Your calculator uses a left to right operator precedence and yet you don’t struggle to translate from PEMDAS or whatever system you use.

              1. 2

                They are absolutely universal. All mathematicians agree on the order of operations here.

                1. 2

                  Funny because every mathematician I’ve talked to, and listened to about order ambiguity agrees with me and says you should put parentheses to disambiguate.

                  The reality is that because it is cultural means it does not matter if you have a solution to the problem if not everyone is using it. In my opinion abandoning order of operations is much simpler and the order is arbitrary, needlessly convoluted, and does not afford for the expansion of operators. You can make things abundantly clear by using polish notation.

                  - / 2x 3y 1

                  Before you throw your arms up in frustration yes there are proofs done in this format, and they’re great.

                  1. 0

                    because it is cultural

                    Yeah but it isn’t cultural. It’s universal. as I’ve explained

                    1. 1

                      I suppose since it is universal that there are severe pedagogical deficiencies, which doesn’t surprise me terribly. Still would have been completely avoided with a simpler and clearer precedence system. It took me a while to realize that you were talking about strictly mathematicians whereas I was talking about all people. Apologies for my poor communication.

            2. 1

              “Order of operations” have been an arbitrary curse on mathematics since their creation, different cultures don’t actually agree, in addition it restricts the creation of new operators. I’m not particularly invested in left to right or right to left, but either would be much simpler than the random format we have now.

              1. 2

                Cultures that don’t use ÷ and × often don’t write sentences left-to-right and pages top-to-bottom. They might not even use arabic numerals.

                I don’t see how it restricts the creation of new operators. Mathematicians seem to have no problem introducing new operators: ∧, ∨, →, ↔, dots, existing operators in circles and all sorts of silly new operators are used all over algebra without any real issue. If it’s not obvious from context, you put brackets in.

                1. 1

                  What order precedence does modulus have? Is it the same as division or should it be done first, or last? If we had a order precedence that can accomodate new operators this question wouldn’t need to be asked and I wouldn’t have to use parentheses which lets be honest is a hack.

                  1. 1

                    Modulus isn’t a standard mathematical operator. But if you defined it, you could just say what its precedence is.

            3. 1

              wait are you using PEMDAS or BODMAS?

              1. 1

                Same thing. Brackets = parenthesis, multiplication and division are done at the same time and so their order is whatever sounds better when reading out the abbreviation. What synonym of exponent does ‘O’ stand for?

                1. 1

                  Multiplication and division are not done at the same time. Orders I believe. http://www.math.harvard.edu/~knill/pedagogy/ambiguity/

                  1. 1

                    Multiplication and division are always done at the same time (with left-associativity - a÷b÷c = (a÷b)÷c in mathematics and this follows over into programming languages that use * and / to emulate × and ÷.

                    2x/3y-1 is not well-defined notation. It’s not mathematics, because mathematics doesn’t use a slash in the middle of some linear text for division (it uses a horizontal line or ÷ depending on the context, although really depending on the level, because I haven’t seen anyone use ÷ since primary school), and it’s not any programming language I’m aware of either. Randomly writing down some text then claiming it’s ambiguous is pretty silly.

                    2 × x ÷ 3 × y - 1 is completely unambiguous, on the other hand: (((2 × x) ÷ 3) × y) - 1. Try putting it into google, or asking someone what 2 × 9 ÷ 3 × 2 - 1 is. Their answer is 11.

                    Mathematicians almost never use ÷ anyway, we write (2 x) / (3 y) where the line is horizontal (not possible on this platform as far as I can tell). But the same rule applies to addition and subtraction: 2 + x - 3 + y - 1 is universally agreed to be (((2 + x) - 3) + y) - 1.

                    Programming languages usually approximate ÷ and × with / and * for the sake of ASCII, so the same rules apply as with those operators. I’m not sure I know of any programming language where you can multiply variables by juxtaposition.

                    I once saw a proposal that it should be based on whitespace: 1+x * 3+y would be (1 + x) * (3 + y), while 1 + x*3 + y would be 1 + x * 3 + y. I thought it was quite a cute proposal, if perhaps prone to error.

                    1. 2

                      Americans use a slash in the middle of linear text to mean division. You clearly didn’t even read the article. Just because you can do multiplication and division from left to right doesn’t mean that’s what people do.

                      1. 1

                        Americans use a slash in the middle of linear text to mean division.

                        Don’t think so.

                        You clearly didn’t even read the article.

                        The article has a bunch of monospace ASCII.

                        Just because you can do multiplication and division from left to right doesn’t mean that’s what people do.

                        It’s what literally everybody in the entire world does.

        2. 3

          I’m reminded of various applications such as Calca, Soulver, numi, NaSC, Qialculate, etc. that offer a similar functionality. However, most of them tend to use “standard” mathematical notation, precedence, and associativity, and ascii text. Other software, such as Mathematica, has the ability to let you write and edit visual equations, and then perform computations with them.

          1. 2

            This is a really long rant about how 1-dimensional ascii text makes poor representation for elementary school math. I’m not going in to any higher math. But ultimately, math is really about abstraction. It’s about make a name for a blob of things, and forget the things inside the blob. Now you have more mental ability to think about other blobs and name them and collect all the new names and put them all together and repeat the process. All the way goes higher and higher.

            Just like software engineering.

            For people working on a specific level of abstraction, it is enough if they only hold that level of abstraction. So anybody on Rails wouldn’t care if malloc is a new grape variety. Unfortunately the usual elementary school math is so informationally denser than a common piece of code, that every encounter of one line formula could make the code reviewer’s mind implode, simply because every one of those + - * / actually means one operation, and usually that single line involves more than a handful of variables.

            If it could make your reviewer happy, name all the formula and put each in a separate functions. Instead of

                s = (1/2)*a*t^2
            

            write

                s = calculate_distance(a,t)
            

            and throw that function toward the end of the file. OUT of SIGHT.