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…
Why Operators Are Useful
91–100 of 173 posts
Re: Why Operators Are Useful
#92Earlier 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…
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
#93This 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
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
#94Earlier 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.
Re: Why Operators Are Useful
#95Earlier 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.
Re: Why Operators Are Useful
#96This 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.
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
#97Earlier 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.
Re: Why Operators Are Useful
#98This 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.
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
#99Re: Why Operators Are Useful
#100This 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.