Live data from Hacker News

Why Operators Are Useful

neopythonic.blogspot.com

91–100 of 173 posts

Re: Why Operators Are Useful

#91

Seems like it's more an argument and prefix notation vs infix. z = Add(x,y) is just a form of prefix notation in my opinion. I would say that z = x + y feels better because that's how we are taught in school. But in English at least, it's reasonable to say the following: Z is X plus Y. To get Z, Add X and Y. --- It's also an argument about inconsistent syntax. For example there is not a big gap in lisp for (+ a b) an…

It'd come down to context for me. If it's 2 or maybe 3 items then I'd prefer x + y, but if it's any more than that I'd definitely use Add().

Re: Why Operators Are Useful

#92

Earlier quoted context omitted.

If this is so obviously preferable, why have mathematicians so obdurately not adopted this style? Mathematical notation is not an archaic practice that is followed out of a respect for tradition, or a doctrine that has been developed from first principles, it is something that has evolved (and continues to do so) because it has been useful.

Well mathematics notation largely follows speech. People say “one plus two” — largely because speech doesn’t have closing parentheses, so we need to speak in a way that makes it clear when we’re done talking — so that’s how we write it. But for a computer, prefix notation is great because it’s unambiguous and clear even without knowledge of PEMDAS. Similar to how Americans write MM/DD/YYYY because that’s how we say d…

I wonder how much is the reverse: we now tend to say mathematical expressions as they are written, but before this was standardised, you would just explain the steps.

Probably not "one plus two" -- I think + is essentially a variant of & which is a ligature for "et", and I guess most languages put "and" between the things being combined. But I'd be surprised if (x/y)^2 was said "x over y all squared" by many people before this notation. But the notation is clearly more designed for thinking on paper than for explaining down a phone line.

Re: Why Operators Are Useful

#93
post #2

This is much less confusing than (2), and leads to the observation that the parentheses are redundant, so now we can write "x + y + z" This is a non-problem if you're using Lisp. (+ x y z) accepts an arbitary number of arguments and the operator precedence problem does not exist since there is no operator precedence.

Lisp is pretty ugly :) (eql (* x (+ y z)) (+ (* x y) (* x z))) I wonder if its famed sense of enlightenment is partly just overcoming the mental hurdle of it's syntax. Edit: typo fix, had x/z mixed up

using rm-hull/infix in clojure

        x * (y + z) = x * z + y * z reduces to
    ($= x * (y + z) = x * z + y * z)
Specifically its more complex only in that the entire expression is wrapped in ($= )

In order to give x y and z values to run it simply wrap it in a let and give them values.

    (let [x 1 y 2 z 1]
      ($= x * (y + z) = x * z + y * z))
alternatively wrap it in a function

    (defn testme [x y z]
      ($= x * (y + z) = x * z + y * z))

Re: Why Operators Are Useful

#94

Earlier quoted context omitted.

What? Have you never had two dicts and wanted vals from one dict override the other?

If a+b != b+a that breaks the commutativity property of addition.

That property is not universal, and it is currently being defined for Python dictionaries. You can't break a property that isn't defined yet. ;-)

Re: Why Operators Are Useful

#95

Earlier quoted context omitted.

Vales of keys in the left operand are overwritten by values of keys in the right operand.

Thats not obvious and breaks a commutative property. This observation about operators seemed poorly crafted to support a decision he already made. The existing example was unnecessarily complicated...most languages just do a singular function with a return val. Why be obtuse in the example? Preconceived agenda. The operator isnt compelling for dicts/hashmaps in any language.

Lots of operators are non-commutative. You can't "break" a commutative property that doesn't exist because the operator is not yet defined.

Re: Why Operators Are Useful

#96
post #2

This is much less confusing than (2), and leads to the observation that the parentheses are redundant, so now we can write "x + y + z" This is a non-problem if you're using Lisp. (+ x y z) accepts an arbitary number of arguments and the operator precedence problem does not exist since there is no operator precedence.

If this is so obviously preferable, why have mathematicians so obdurately not adopted this style? Mathematical notation is not an archaic practice that is followed out of a respect for tradition, or a doctrine that has been developed from first principles, it is something that has evolved (and continues to do so) because it has been useful.

1. Mathematicians have different priorities than programmers, and they use different tools. Working with an equation on a whiteboard, it's easier to write "a+b+c" and then cancel terms as needed. When writing a formula on my computer, cancelling terms is something I almost never do, so it would be silly to use a notation that's been optimized for that.

When I am doing algebra on my computer, I hope I have a tool like Graphing Calculator (not "Grapher"!) that lets me simply drag a term from here to there, and automatically figures out what needs to happen to keep the equation balanced.

2. They have, except they use Σ for the prefix version. When it's more than a couple terms, and there's a pattern to it, Σ (prefix notation) is far more convenient than + (infix notation).

If programming languages look like they do because they're taking the useful notations from mathematics, why doesn't your favorite programming language have a Σ function? Who's being stubborn here?

Re: Why Operators Are Useful

#97
post #69

Earlier quoted context omitted.

Ramblings through technology, politics, culture and philosophy by the creator of the Python programming language. This was literally the first thing I read when I hit the link. Don't mean to sound rude but how did you miss that ? Does it render differently on web? I saw this on the mobile version of the site on my Android.

For me that was covered up by some popover I didn't read. Besides the tagline of a blog is the sort of thing I for one gloss over. I've had decades of training how to skip straight to the content.

Yeah, that's me exactly.

Re: Why Operators Are Useful

#98
post #64
post #2

This is much less confusing than (2), and leads to the observation that the parentheses are redundant, so now we can write "x + y + z" This is a non-problem if you're using Lisp. (+ x y z) accepts an arbitary number of arguments and the operator precedence problem does not exist since there is no operator precedence.

Try writing out typical mathematical formula derivations using only s-expressions. I tried for a period and abandoned the persuit. It’s just not comparable to established mathematical notation.

The Lisp community has literally tried exactly this, on and off, for the past half century -- and they always come back to s-expressions. Every new Lisp programmers says "I know, I'll make a macro to let me write infix math!", and then abandons it 2 months later. It's not like Lisp programmers aren't aware of how schoolchildren write (+ 2 2).

I've written tons of code in both language families. In infix/prefix (i.e., Algol-family) languages, I frequently wish for a nice consistent prefix syntax. In prefix-only (i.e., Lisp-family) languages, I can't say I've ever wished for infix notation.

I don't understand what the perceived issue is with infix notation, except for unfamiliarity -- and that passes soon enough.

Re: Why Operators Are Useful

#100
post #85
post #2

This is much less confusing than (2), and leads to the observation that the parentheses are redundant, so now we can write "x + y + z" This is a non-problem if you're using Lisp. (+ x y z) accepts an arbitary number of arguments and the operator precedence problem does not exist since there is no operator precedence.

Your comment is begging the question. The reason that Lisp “+” can accept a list of arbitrary length, rather than a pair, is that the underlying addition operator is associative.

Not true. Division isn't associative and you can do e.g. (/ 12 6 3)
Post reply on HN